//Début du temps de chargement
entree = new Date;
entree = entree.getTime();

//animate the opening of the branch (span.grower jQueryElement)
function openBranch(jQueryElement, noAnimation) {
		jQueryElement.addClass('OPEN').removeClass('CLOSE');
		if(noAnimation)
			jQueryElement.parent().find('ul:first').show();
		else
			jQueryElement.parent().find('ul:first').slideDown();
}
//animate the closing of the branch (span.grower jQueryElement)
function closeBranch(jQueryElement, noAnimation) {
	jQueryElement.addClass('CLOSE').removeClass('OPEN');
	if(noAnimation)
		jQueryElement.parent().find('ul:first').hide();
	else
		jQueryElement.parent().find('ul:first').slideUp();
}

//animate the closing or opening of the branch (ul jQueryElement)
function toggleBranch(jQueryElement, noAnimation) {
	if(jQueryElement.hasClass('OPEN'))
		closeBranch(jQueryElement, noAnimation);
	else
		openBranch(jQueryElement, noAnimation);
}

//when the page is loaded...
$(document).ready(function () {
	//to do not execute this script as much as it's called...
	if(!$('ul.tree.dhtml').hasClass('dynamized'))
	{
		//add growers to each ul.tree elements
		$('ul.tree.dhtml ul').prev().after("<span class='grower OPEN' style='display:none;'> </span>");
		
		//dynamically add the '.last' class on each last item of a branch
		$('ul.tree.dhtml ul li:last-child, ul.tree.dhtml li:last-child').addClass('last');
		
		//collapse every expanded branch
		$('ul.tree.dhtml span.grower.OPEN').addClass('CLOSE').removeClass('OPEN').parent().find('ul:first').hide();
		$('ul.tree.dhtml').show();
		
		//open the tree for the selected branch
			$('ul.tree.dhtml .selected').parents().each( function() {
				if ($(this).is('ul'))
					toggleBranch($(this).prev().prev(), true);
				});
			toggleBranch( $('ul.tree.dhtml .selected').prev(), true);
		
		//add a fonction on clicks on growers
		$('ul.tree.dhtml span.grower').click(function(){
			toggleBranch($(this));
		});
		//mark this 'ul.tree' elements as already 'dynamized'
		$('ul.tree.dhtml').addClass('dynamized');
		$('ul.tree.dhtml').removeClass('dhtml');
	}
});

function displayGrower(growerElem)
{
	
	//parent.growerElem.setAttribute("id","parentgrowerElem_hover");
}

$(function(){ 
    $("ul.tree li .grower").mouseover(function(){
		$(this).each(function(){
			$(this).show(); 
			$(this).prev().css("background-color","#333333"); 
			$(this).prev().css("border-left","solid 2px #FFFFFF"); 
			
			if($(this).hasClass("OPEN"))
			{
				$(this).css("background-image","url('/themes/prestashop/img/icon/less_hover.png')"); 
			}
			else
			{
				$(this).css("background-image","url('/themes/prestashop/img/icon/more_hover.png')"); 
			}
		 }); 
	 }); 
	
    $("ul.tree li .grower").click(function(){
		$(this).each(function(){
			if($(this).hasClass("OPEN"))
			{
				$(this).css("background-image","url('/themes/prestashop/img/icon/less_hover.png')"); 
			}
			else
			{
				$(this).css("background-image","url('/themes/prestashop/img/icon/more_hover.png')"); 
			}
		 }); 
	 }); 
	
    $("ul.tree li .grower").mouseout(function(){
		$(this).each(function(){
			if($(this).hasClass("OPEN"))
			{
				$(this).show(); 
				$(this).css("background-image","url('/themes/prestashop/img/icon/less.png')"); 
			}
			else
			{
				$(this).hide();
				$(this).prev().css("background","none");
				$(this).css("background-image","url('/themes/prestashop/img/icon/more.png')"); 
			}
			if($(this).prev().hasClass("selected"))
			{
				$(this).prev().css("border-left","solid 2px #D3993F"); 
			}
			else
			{
				$(this).prev().css("border-left","solid 2px #333333"); 
			}
		 }); 
	 }); 
	
    $("ul.tree li .aGrower").mouseover(function(){
		$(this).each(function(){
			$(this).next().show(); 
		 }); 
	 }); 
    $("ul.tree li .aGrower").mouseout(function(){
		$(this).each(function(){
			if($(this).next().hasClass("OPEN"))
			{
				$(this).next().show(); 
			}
			else
			{
				$(this).next().hide(); 
			}
		 }); 
	 }); 
}); 

/**
 * @author Alexander Farkas
 * v. 1.02
 */
/*(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
For Jquery 1.2.x*/
(function(jQuery) { 
    jQuery.extend(jQuery.fx.step, { 
        backgroundPosition: function(fx) { 
            function toArray(strg) { 
                strg = strg.replace(/left|top/g, '0px'); 
                strg = strg.replace(/right|bottom/g, '100%'); 
                strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2"); 
                var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/); 
                return [parseFloat(res[1], 10), res[2], parseFloat(res[3], 10), res[4]]; 
            } 
            if (parseInt(fx.state) === 0 && typeof fx.end === 'string') { 
                var start = jQuery.curCSS(fx.elem, 'backgroundPosition'); 
                if (!start) { 
                    start = jQuery.curCSS(fx.elem, 'backgroundPositionX') + ' ' + jQuery.curCSS(fx.elem, 'backgroundPositionY'); 
                } 
                start = toArray(start); 
                fx.start = [start[0], start[2]]; 
                var end = toArray(fx.end); 
                fx.end = [end[0], end[2]]; 
                fx.unit = [end[1], end[3]]; 
            } 
            var nowPosX = []; 
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0]; 
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1]; 
            fx.elem.style.backgroundPosition = nowPosX[0] + ' ' + nowPosX[1]; 
        } 
    }); 
})(jQuery); 


/* Victor */

function get_pageload(){
	//alert("ok");
	fin = new Date;
	fin = fin.getTime();
	secondes = (fin-entree)/1000;
	return secondes;
	}
	
function display_pageload(){
	document.getElementById('txt_pageload').innerHTML='page servie en ' + get_pageload() + ' secs.';
	//alert("Page en cours de modification...");
	}


$(function(){ 
$('ul#product_list li')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:200})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
		})
$('ul.pagination li a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -17px)"}, {duration:200})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
		})

	 
	 /* Style des listes des recettes */
	 $("#listing_recette li").each(function (i) {
		  $(this).wrapInner("<p></p>");
	  });


	/* Onclick sur les input, select et textarea */
	$('input, select, textarea')
	.mousedown(function(){
		$(this).css("background-color","#CFCFCF");
	})
	.blur(function(){
		$(this).css("background-color","#EBEBEB");
	});
//Calcul de la date de Pâques, selon l'année
function jour_paques(annee) {
	var retour = new Array();
	b=annee-1900;
	c=annee%19;
	d=Math.floor((7*c+1)/19);
	e=(11*c+4-d)%29;
	f=Math.floor(b/4);
	g=(b+f+31-e)%7;
	date=25-e-g;
	if (date>0) mois=3;
	else {
		date=31+date;
		mois=4;
	}
	retour[0] = date;
	retour[1] = mois;
	return retour;
}
/* Affichage des déclianisons de l'oie + neige */
	var date_courante = new Date();
	var mm = parseInt(date_courante.getMonth());
	var dd = parseInt(date_courante.getDate());
	var paques = jour_paques(parseInt(date_courante.getFullYear()));
	if ((paques[0]-15)<0) {
		debut_paques_m = paques[1]-1;
		debut_paques_j = (paques[0]-15)+31;
	}
	else {
		debut_paques_m = paques[1];
		debut_paques_j = paques[0]-15;
	}
	//Fetes des meres
	if ((mm == 4 && (dd > 8))) { 
		declinaison = 'fete_meres';
	}
	/*else if ((mm == 5 && (dd > 20) || (mm == 8 && (dd < 23)))) {
		declinaison = 'ete';
	}*/
	else if ((mm == 1 && (dd > 0)) && (mm == 1 && (dd < 15))) {
		declinaison = 'st_valentin';
	}
	else if ((mm == 11) || (mm == 0) || (mm == 1) || (mm == 2 && (dd < 20))) {
		declinaison = 'hiver';
		if ((mm == 11 && (dd > 14)) && (mm == 11 && (dd < 26))) {
			declinaison = 'noel';
		}
		if ((mm == 11 && (dd > 25)) || (mm == 0 && (dd < 2))) {
			declinaison = 'st_sylvestre';
			$('div#header_user img#th_oie').addClass("st_sylvestre");
		}
		if ((mm == 0 && (dd > 1)) && (mm == 0 && (dd < 10))) {
			declinaison = 'epiphanie';
		}
	}
	else if ((mm == debut_paques_m && (dd > debut_paques_j)) || (mm == paques[1] && (dd < (paques[0]+1)))) {
		declinaison = 'paques';
		$('div#header_user img#th_oie').addClass("paques");
		$('div#header_user img#picto_bulle').addClass("picto_bulle_paques");
	}
	else declinaison = false;
	if (declinaison != false) {
		//Image Oie
		$('div#header_user img#th_oie').attr("src","/themes/prestashop/img/oie_"+declinaison+".png");
		//Fond du site
		if (declinaison == 'noel' || declinaison == 'fete_meres' || declinaison == 'st_valentin' || declinaison == 'paques' || declinaison == 'st_sylvestre' )
		{
			if($('div#page div#bordures_site_fr'))
			{
				$('div#page div#bordures_site_fr').css("background-image","url('/themes/prestashop/img/fond_"+declinaison+"_fr.png')");
			}
			if($('div#page div#bordures_site_en'))
			{
				$('div#page div#bordures_site_en').css("background-image","url('/themes/prestashop/img/fond_"+declinaison+"_en.png')");
			}
		}
	}
	//Snowstorm.js
	snow = false;
	if ((mm == 11 && (dd > 04))) snow = true;
	if (snow) {
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = '/themes/prestashop/js/snowstorm.js';
		document.getElementsByTagName('head').item(0).appendChild(script);
	}

//Fait disparaitre la div qui cache le site
$('div#cache').hide();

//Affiche le temps de chargement de la page
display_pageload();
}); 

/* FIN Victor */
