sas_tmstp=Math.round(Math.random()*10000000000);sas_masterflag=1;

function SmartAdServer(sas_pageid,sas_formatid,sas_target) {
if (sas_masterflag==1) {sas_masterflag=0;sas_master='M';} else {sas_master='S';};
document.write('<scr'+'ipt SRC="http://www.smartadserver.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></scr'+'ipt>');
}

//open window
function Sesame(page,target,larg,haut,scraul,agrandir,foc){
	var posXpop = (screen.availWidth-larg)/2;
	var posYpop = (screen.availHeight-haut)/2;
	param = "width="+larg+",height="+haut+",left="+posXpop+",top="+posYpop+",scrollbars="+scraul+",resizable="+agrandir;
	popup = window.open(page,target,param);
	if(foc) popup.focus();
}
// fin open window




/* charg� un bloc */
/* si time = 0 : Le chargement est appelé une seule fois */

function loadBloc(bloc,source,time,callback, anim){
	//alert("Load bloc : " + bloc + ' // ' + source);
	$(bloc).load(source, function() {
	  if(callback != null){
		callback();
		if (anim != null && anim == true ) $(bloc).show('drop');
	  }
	 cufonReplace();
	});
	if(time != 0){
		var timeMs = (time * 60)*1000;
		//var timeMs = time*1000;
		window.setInterval(function() {
			if (anim != null && anim == true ) $(bloc).hide('fade');
			$(bloc).load(source, function() {
			   if(callback != null){
				callback();
				if (anim != null && anim == true ) $(bloc).show('drop');
			  }
			cufonReplace();

			});
		}, timeMs);
	}
}





/** Code Commun  à toutes les pages **/


/** Fonction Ready **/
$(document).ready(function() {



    // Gestion de l'affichage du bouton retour en fonction du mode d'arrivée
    var url = document.referrer;
    var match = url.indexOf("www.dakar.com");
    if (match != -1) {
        $("#titrePageLive a").attr('href', "javascript:history.back()");
        $("#titrePage a").attr('href', "javascript:history.back()");
    } else {
        $("#titrePageLive a").attr('style', "display:none");
        $("#titrePage a").attr('style', "display:none");
    }



    //gestion de la fermeture de l'alerte orange
    $('.closeAlert').toggle(function() {
            $('#alertSecu').hide();
    },function() {
            $('#alertSecu').show();
    });



    //Ouverture / Fermeture de la nav Etapes
    var cpt = 0;
    $('.prevNext, .titreEtapeClickable').click(function(){
            cpt++;
            $('#stageListe').show();

            if(cpt == 1) {
                $(".NavEtapeCarroussel ul").simplyScroll({
                    speed: 25
                });

                //on insere le bouton close dynamiquement
                $('<span id="close" class="simply-scroll-btn"><img src="/dakar/img/commun/close-stage.gif" alt="close" /></span>').insertAfter($('.NavEtapeCarroussel .simply-scroll-btn-right'));
            }

            var currentWidth = $('.NavEtapeCarroussel li.current').width();
            var pos = $('.NavEtapeCarroussel li.current').index();
            //on retire 2 pour bien caler
            pos = pos-2;
            $('.simply-scroll-clip').scrollLeft(currentWidth*pos);





    });

    $('#stageListe').click(function(){
            $('#stageListe').hide();
    });

    // par défaut, la liste des stage est cachée 

    //on positionne l'étape courante en 1er

    //$('#stageListe').hide();
   // $('#stageListe').css("display", "none");




    // GESTION DES LANGUES
    //
    // Ouverture / Fermeture des langues 
    $('#langs').mouseover(function() {
            $('#langs').removeClass('closed');
    }).mouseout(function() {
            $('#langs').addClass('closed');
    });

    // Ouverture / Fermeture des langues hors course
    $('#langs_horscourse').mouseover(function() {
            $('#langs_horscourse').removeClass('closed');
    }).mouseout(function() {
            $('#langs_horscourse').addClass('closed');
    });


    $('#lives').mouseover(function() {
            $('#lives').removeClass('closed');
    }).mouseout(function(){
            $('#lives #listLives').css("top","0px");
            $('#lives').addClass('closed');
    });



    // Sponsors
    jQuery('#mycarouselSponsor').jcarousel({
            auto: 2,
            wrap: 'circular',
            initCallback: hoverStop
    });


    // sous menus
    hideMenu = false;
    $("ul#menu li a").mouseover(function() {
            if (hideMenu)
            {
                    $("ul#menu ul.subnav").hide();
                    hideMenu = false;
            }
            $(this).parent().find("ul.subnav").slideDown('fast').show();
            $(this).parent().hover(function() {

            }, function(){
                    if (!$(this).parent().hasClass('subnav'))	hideMenu = true;
                    $(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
            });
    });


    // Chain.js
    var numero = Math.round( ( 8 ) * Math.random() )+1;
    charge_chaine(numero);
    jQuery('#lives.closed').hover(
            function(){ jQuery('#lives li.chaine').addClass("current"); jQuery('#lives li.chaine a').show();
            }
    );





      // CHANGEMENT DE LANGUE


        $('.langFlag').click(function() {
            var lang = $(this).attr("class").split(" ")[0];
            var url = $("#Url_"+lang).val();
            window.location.href = url;
        });

        // FIN CHANGEMENT LANGUE


        //changement de type DAKAR MAG
        $("#blockDakarMag ul.tabs li").click(function() {
            $("#blockDakarMag ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $("#blockDakarMag .tab_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active content


            return false;
        });


        //fin changement de type DAKAR MAG


        //carrousel liste engagés : affichage aléatoire
        $('ul#mycarouselPhotoPilotes').shuffle();


}); // Fin ready



    
// Chain.js
function charge_chaine(numero) {
    jQuery('#lives.closed li.chaine').removeClass("current");
    jQuery('#lives.closed li.chaine a').hide();
    jQuery('#tv_'+numero).addClass("current");
    jQuery('#tv_'+numero+' a').show();
    var numero = Math.round( ( 8 ) * Math.random() )+1;
    setTimeout(' charge_chaine('+numero+')',5000);
}




// FIN FONCTION GENERALE DE CHARGEMENT DES CAROUSELS




// FONCTION SHUFFLE : affiche aléatoirement les composants d'une liste
(function($){

	$.fn.shuffle = function() {
		return this.each(function(){
			var items = $(this).children().clone(true);
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}

	$.shuffle = function(arr) {
		for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	}

})(jQuery);
