// JavaScript Document
$(document).ready(function() {
	
	switch (getUrlVarsFrom(window.location.href, true)['tabid']) {
		case undefined:
			initSlideshow();
			break;
		case '1':
			initSlideshow();
			break;
		case '18':
			initSlideshow();
			break;
		
		}
})

function getUrlVarsFrom(url, preventUnwantedVars) {
    var vars = [],
        hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
		if (preventUnwantedVars) {
			if (hash[0] != 'lg' && hash[0] != 'objectid' && hash[0] != 'tabindex' && hash[0] != 'page' && hash[0] != 'keyword'  && hash[0] != 'mediaid') {
        		vars.push(hash[0]);
        		vars[hash[0]] = hash[1];
			}
		} else {
			vars.push(hash[0]);
        	vars[hash[0]] = hash[1];
		}
    }
    return vars;
}
		
function slideSwitch() {
	
    var $active = $('div#slideshow div.slides div.active');

    if ( $active.length == 0 ) $active = $('div#slideshow div.slides div:last');

		// use this to pull the images in the order they appear in the markup
		var $next =  $active.next().length ? $active.next()
			: $('div#slideshow div.slides div:first');
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})//changer cette valeur en 0.0 pour activer le slideshow
			.addClass('active')
			//.animate({opacity: 1.0}, 1500, function() {
			.animate({opacity: 1.0}, 3500, function() {
				$active.removeClass('active last-active');
				if (t) clearTimeout(t);
				t=setTimeout( "slideSwitch()", 6500 );
     });
}




function initSlideshow() {
	
	$('div#slideshow div.slides div:first').addClass('active');
	t=setTimeout( "slideSwitch()", 4500 );
}



