// Un exemple de ce que ca doit faire, mais il faut rendre le block de la home generique
// car la j'ai fait tout ca en dur par manque de temps.
// Bon courage Tibault  :)

if((jQuery.browser.msie) && (jQuery.browser.version == '6.0')){
	
	var blockPos = Array(
		{width:"966px", top:"24px", left:"0px"},
		{width:"966px", top:"12px", left:"10px"},
		{width:"966px", top:"0px", left:"20px"}
	);
}else{
	var blockPos = Array(
		{width:"946px", top:"24px", left:"0px"},
		{width:"946px", top:"12px", left:"10px"},
		{width:"946px", top:"0px", left:"20px"}
	);
}

function rollBlocks() {
    jQuery('#dispatchBlockTopMenu li:eq(0)').click(function(){
        jQuery('#dispatchBlockTopMenu a.on').removeClass('on');
        jQuery('#dispatchBlockTop1').animate({top:"280px"}, "fast", function(){
               moveBlock('#dispatchBlockTop1', 1);
               moveBlock('#dispatchBlockTop2', 2);
               moveBlock('#dispatchBlockTop3', 3);
        });
        jQuery(this).find('a').addClass('on');
        return false;
    });

    jQuery('#dispatchBlockTopMenu li:eq(1)').click(function(){
        jQuery('#dispatchBlockTopMenu a.on').removeClass('on');
        jQuery('#dispatchBlockTop2').animate({top:"280px"}, "fast", function(){
               moveBlock('#dispatchBlockTop1', 3);
               moveBlock('#dispatchBlockTop2', 1);
               moveBlock('#dispatchBlockTop3', 2);
        });
        jQuery(this).find('a').addClass('on');
        return false;
    });

    jQuery('#dispatchBlockTopMenu li:eq(2)').click(function(){
        jQuery('#dispatchBlockTopMenu a.on').removeClass('on');
        jQuery('#dispatchBlockTop3').animate({top:"280px"}, "fast", function(){
               moveBlock('#dispatchBlockTop1', 2);
               moveBlock('#dispatchBlockTop2', 3);
               moveBlock('#dispatchBlockTop3', 1);
        });
        jQuery(this).find('a').addClass('on');
        return false;
    });
}

function moveBlock(blockName, position) {
    var zindex, posBlock;
    if(position=="1")      { zindex=3; posBlock=0; }
    else if(position=="2") { zindex=2; posBlock=1; }
    else                   { zindex=1; posBlock=2; }
    jQuery(blockName).css('z-index', zindex).animate(blockPos[posBlock], "fast");
}

jQuery(document).ready(function(){
    jQuery('#dispatchNews marquee').marquee().mouseover(function () {
      jQuery(this).trigger('stop');
    }).mouseout(function () {
      jQuery(this).trigger('start');
    });

    rollBlocks();
});

// ###### DEBUT DEFILEMENT IMAGES ######

// Déclaration des variables
var max = 3						// Nombre d'images
var imageEnCours = 0		// Image affichée
var timeout = 0				// Timer
var duree = 8000			// Duree de défliement

// Chargement d'une image
function chargeImage(numImage) {
	switch (numImage) {
		case 1:
			jQuery('#centralDispatchTopMenuLien3').removeClass('on');
		    jQuery('#dispatchBlockTop1').animate({top:"280px"}, "fast", function(){
		    	moveBlock('#dispatchBlockTop1', 1);
		        moveBlock('#dispatchBlockTop2', 2);
		        moveBlock('#dispatchBlockTop3', 3);
		    });
		    jQuery('#centralDispatchTopMenuLien1').addClass('on');
		    return false;
		    break;
		case 2:
			jQuery('#centralDispatchTopMenuLien1').removeClass('on');
			jQuery('#dispatchBlockTop2').animate({top:"280px"}, "fast", function(){
				moveBlock('#dispatchBlockTop1', 3);
				moveBlock('#dispatchBlockTop2', 1);
				moveBlock('#dispatchBlockTop3', 2);
			});
			jQuery('#centralDispatchTopMenuLien2').addClass('on');
			return false;
			break;
		case 3:
			jQuery('#centralDispatchTopMenuLien2').removeClass('on');
			jQuery('#dispatchBlockTop3').animate({top:"280px"}, "fast", function(){
				moveBlock('#dispatchBlockTop1', 2);
				moveBlock('#dispatchBlockTop2', 3);
				moveBlock('#dispatchBlockTop3', 1);
			});
			jQuery('#centralDispatchTopMenuLien3').addClass('on');
			return false;
			break;
		default: break;
	}
}
	
// Défilement continu des images
function imageContinu() {
	imageEnCours++
	if (imageEnCours > max ) { imageEnCours = 1 }
	chargeImage(imageEnCours);
	timeout = setTimeout("imageContinu()", duree)
}
	
// Arrête le défilement
function arret() { clearTimeout(timeout) }
	
// ###### FIN DEFILEMENT IMAGES ######
