// jQuery conflict mode
$.noConflict();

// Cufon Font Replacment
Cufon.replace('.Aller', { fontFamily: 'Aller700', hover: true })


// jQuery Starts here

// Startpage Background Slideshow Variables

// Speed of the automatic slideshow
var slideshowSpeed = 20000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [{
    "title": "Taipei",
    "image": "promo01.jpg",
    "url": "/nl/Ontdek.aspx",
    "firstline": "Ontdek Azi&euml;",
    "secondline": "Welkom in Taiwan"
}, {
    "title": "Traditie en moderne cultuur",
    "image": "promo02.jpg",
    "url": "/nl/Ontdek/OverTaiwan.aspx",
    "firstline": "Een combinatie van",
    "secondline": "traditie en moderne cultuur"
}, {
    "title": "Natuur",
    "image": "promo03.jpg",
    "url": "/nl/Bestemming/CentraalTaiwan.aspx",
    "firstline": "Ontspan in",
    "secondline": "ongerepte natuur"
}, {
    "title": "Natuur",
    "image": "promo04.jpg",
    "url": "/nl/Bestemming/OostTaiwan.aspx",
    "firstline": "Geniet van het",
    "secondline": "adembenemende uitzicht"
}, {
    "title": "Droomeilanden",
    "image": "promo05.jpg",
    "url": "/nl/Bestemming/Zien_Doen/Bezienswaardigheden.aspx",
    "firstline": "Paradijselijke",
    "secondline": "droomeilanden"
}
];


// jQuery document ready
jQuery(document).ready(function() {

// Tabs
jQuery('#tabs div.tabcontent').hide(); // Hide all divs
jQuery('#tabs div.tabcontent:first').show(); // Show the first div
jQuery('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
jQuery('#tabs ul li a').click(function() { //When any link is clicked
    jQuery('#tabs ul li').removeClass('active'); // Remove active class from all links
    jQuery(this).parent().addClass('active'); //Set clicked link class to active
    var currentTab = jQuery(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
    jQuery('#tabs div.tabcontent').hide(); // Hide all divs
    jQuery(currentTab).show(); // Show div with id equal to variable currentTab
    return false;
});

// Background Slideshow

// Backwards navigation
jQuery("#back").click(function() {
    stopAnimation();
    navigate("back");
});

// Forward navigation
jQuery("#next").click(function() {
    stopAnimation();
    navigate("next");
});

var interval;
jQuery("#control").toggle(function() {
    stopAnimation();
}, function() {
    // Change the background image to "pause"
    jQuery(this).css({ "background-image": "url(/portals/0/promo-start-fotos/btn_pause.png)" });

    // Show the next image
    navigate("next");

    // Start playing the animation
    interval = setInterval(function() {
        navigate("next");
    }, slideshowSpeed);
});


var activeContainer = 1;
var currentImg = 0;
var animating = false;
var navigate = function(direction) {
    // Check if no animation is running. If it is, prevent the action
    if (animating) {
        return;
    }

    // Check which current image we need to show
    if (direction == "next") {
        currentImg++;
        if (currentImg == photos.length + 1) {
            currentImg = 1;
        }
    } else {
        currentImg--;
        if (currentImg == 0) {
            currentImg = photos.length;
        }
    }

    // Check which container we need to use
    var currentContainer = activeContainer;
    if (activeContainer == 1) {
        activeContainer = 2;
    } else {
        activeContainer = 1;
    }

    showImage(photos[currentImg - 1], currentContainer, activeContainer);

};

var currentZindex = -1;
var showImage = function(photoObject, currentContainer, activeContainer) {
    animating = true;

    // Make sure the new container is always on the background
    currentZindex--;

    // Set the background image of the new active container
    jQuery("#headerimg" + activeContainer).css({
        "background-image": "url(/portals/0/promo-start-fotos/" + photoObject.image + ")",
        "display": "block",
        "z-index": currentZindex
    });

    // Hide the header text
    jQuery("#headertxt").css({ "display": "none" });

    // Set the new header text
    jQuery("#firstline").html(photoObject.firstline);
    jQuery("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
    jQuery("#pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);


    // Fade out the current container
    // and display the header text when animation is complete
    jQuery("#headerimg" + currentContainer).fadeOut(function() {
        setTimeout(function() {
            jQuery("#headertxt").css({ "display": "block" });
            animating = false;
        }, 500);
    });
};

var stopAnimation = function() {
    // Change the background image to "play"
    jQuery("#control").css({ "background-image": "url(/portals/0/promo-start-fotos/btn_play.png)" });

    // Clear the interval
    clearInterval(interval);
};

// We should statically set the first image
navigate("next");

// Start playing the animation
interval = setInterval(function() {
    navigate("next");
}, slideshowSpeed);


// Flackern IE6 abstellen
if (jQuery.browser.msie) {
    try {
      document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}
};

//Navigatin Vertical Margin
jQuery(".nav-vertical ul.level2:last-child")
.css({ margin: "0 0 20px 0" })

// PNG Fix
jQuery('#logo').pngFix();

// Twitterfeed
jQuery('#twitterfeed').twitterfeed('nunaartaiwan', {
    limit: 3
});

// Document Icons
var iconPath = '/images/FileManager/Icons/';

var fileTypes = {
  doc: 'doc.gif',
  docx: 'doc.gif',
  xls: 'xls.gif',
  xlsx: 'xls.gif',
  ppt: 'ppt.gif',
  pptx: 'ppt.gif',
  pdf: 'pdf.gif',
  jpg: 'jpg.gif',
  tif: 'pdf.tif',
  tiff: 'tif.gif'
};

// All but not article images
jQuery('.article a').not('.article-image a').each(function() {
 
  var $a = jQuery(this);
  var href = $a.attr('href');
 
  if (
    (href.match(/^http/)) &&
    (! href.match(document.domain))
  ) {
 
    // use a special image for external links
    var image = 'link-external.gif';
 
  }
  
  // mailto link
  else if (href.match(/^mailto:/) || href.match(/^javascript:location.href='mailto:'/)) {
 
    // use a special image for external links
    var image = 'link-email.gif';
	
  }
  
  else {
    // get the extension from the href
    var hrefArray = href.split('.');
    var extension = hrefArray[hrefArray.length - 1];
 
    var image = fileTypes[extension];	
	
  }
 
  if (image) {
    $a.css({
      paddingLeft: '20px',
      background: 'transparent url("' +iconPath + image + '") no-repeat center left'
    }).attr("target", "_blank");
  }

});

// Weather
jQuery('#footer-box1').weatherfeed(['TWXX0021']);


});// Close Document.ready


// Function Preload Images
(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)

// Preload the following images
jQuery.preLoadImages("/portals/0/promo-start-fotos/promo01.jpg", "/portals/0/promo-start-fotos/promo02.jpg", "/portals/0/promo-start-fotos/promo03.jpg", "/portals/0/promo-start-fotos/promo04.jpg", "/portals/0/promo-start-fotos/promo05.jpg");
