/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : ConsulGaz
// Date   : 31 aout 2009
//----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Inclusion dynamique des fichiers externes javascripts
/*----------------------------------------------------------------------------*/
function importJavascript(src)
{
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function importCss(href, media)
{
	document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------*/
// Declarations jQuery
/*----------------------------------------------------------------------------*/
$(document).ready(function(){
						   
	// Equalize colonnes principales
	equalHeight($("#BarreLaterale, #Corps"), false);
	
	//Accueil Caroussel
	if($("#Caroussel").length > 0) {
		initCaroussel($("#Caroussel"));
	}
	
});

/* - Fonction : Photo Caroussel
   ------------------------------------*/
var totalSlide, timerSlide, currentSlide, containerSlide;
var slideTime = 3000;
function initCaroussel(obj) {
	containerSlide = obj
	totalSlide = $("img.CarousselSlide", containerSlide).length;
	if(totalSlide > 1) {
		$("img.CarousselSlide", containerSlide).each(function(i){
			$(this).attr("id", "slide-"+(i+1));
		});
		currentSlide = totalSlide;
		timerSlide = setTimeout(loopCaroussel, slideTime);	
	}
}
function loopCaroussel() {
	$("#slide-"+currentSlide).fadeOut(2000, function(){
		$(containerSlide).prepend($("#slide-"+currentSlide));
		$("#slide-"+currentSlide).show();
		currentSlide = (currentSlide == 1?totalSlide:(currentSlide-1));
		timerSlide = setTimeout(loopCaroussel, slideTime);
	});
}

/* - Fonction : Equalcols height
   ------------------------------------*/
function equalHeight(group, important) {
    tallest = 0;
    important = (important == false ? "" : " !important");
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.attr("style", "height:" + tallest + "px" + important + ";");
}
function clearEqualHeight(group) {
	group.each(function() {
        $(this).css("height","");
    });
}
