$(document).ready(function() {

	// Moteur de recherche
	//dch@8/8/08 - tmatic 6: régler le bug de saisi dans le champs d'inscription (activié cette option que pour les input de la recherche et le formulaire d'identification
	//$("input:text").focus(function() {
	$("#searchtext").focus(function() {
		this.value = "";
	});
	
	$("#id1").focus(function() {
		this.value = "";
	});
	
	$("#id2").focus(function() {
		this.value = "";
	});

	// Boutons
	$(".btn button").mouseover(function() {
		$(this).addClass("btn_hover");
	});
	$(".btn button").mouseout(function() {
		$(this).removeClass("btn_hover");
	});


	// Catalogue Liste
	$("#catalogueliste").clone().prependTo("body");
	$("#header #catalogueliste").remove();

		// Ouverture
		$("#cataloguemenu a").click(function() {
			if($("#catalogueliste").css("display") == "none") {
				//$("select").css("visibility", "hidden");
				$(".hidecalendar").hide();
				$("#catalogueliste").css("display", "block");
				$("#cataloguemenu").toggleClass("cataloguemenu-on")
			}
			this.blur();
			return false;
		});

		// Fermeture
		$(".catalogueliste-close a").click(function() {
			//$("select").css("visibility", "visible");
			$(".hidecalendar").show();
			$("#catalogueliste").css("display", "none");
			$("#cataloguemenu").removeClass("cataloguemenu-on")
			return false;
		});

	// Ajout panier
	$("#res-submit").click(function() {
		if($(".panier-ajout").css("display") == "none") {
			$("#res-form select").css("visibility", "hidden");
			$(".panier-ajout").css("display", "block");
			$(".panier-ajout").fadeTo("slow", 1);
			//$("#panier-ajout").animate({opacity: 'show'}, "slow");
			//$("#res-form").submit();
		}
		return false;
	});

	//Fermer panier
	$(".panier-ajout .btn_noir").click(function() {
		if($(".panier-ajout").css("display") == "block") {
			$(this).parent().css("display", "none");
			$("#res-form select").css("visibility", "visible");
		}
	});

	$(".panier-ajout-fermer a").click(function() {
		$(this).parent().parent().hide("slow");
		return false;
	});

	// Box Info
	if(document.getElementById("boxinfo-content")) {
		Hgt = $("#boxinfo-content h2 img").height();
		Hgt = Hgt + 10;
		$("#boxinfo-entete").height(Hgt+"px");
		$("#boxinfo-content p#tagcloud").css("top", Hgt+"px");
		$("#boxinfo-content p#saviezvous").css("top", Hgt+"px");
	}





	// TEST
	//$("#catalogueliste").css("display", "block");
	//$("#panier-ajout").css("display", "block");
	//$("#panier-ajout").css("opacity", 100);



	// onglets de la fiche produit

	$(".ong").not(":first").hide();
	$(".onglet li:first").addClass("on");

	$(".onglet a").click( function(){


		$(".onglet li").removeClass("on");
		$(this).parents("li").addClass("on");

		$(".ong").hide();

		$(this.hash).show();

		this.blur();
		return(false);
	});


	// rollover partiel pour les produits (CAT1)
	$("#categories .visuel, #categories .titre2").mouseover( function() {
		$(this).parents("li").addClass("on");
	} );

	$("#categories .visuel, #categories .titre2").mouseout( function() {
		$(this).parents("li").removeClass("on");
	} );


	// rollover total pour les produits (CAT2, FP, MOP)
	$("#produits .border, #classeur .border, #comparaison .border").mouseover( function() {
		$(this).removeClass("border");
		$(this).addClass("border_jaune");
	} );

	$("#produits .border, #classeur .border, #comparaison .border").mouseout( function() {
		$(this).removeClass("border_jaune");
		$(this).addClass("border");
	} );


	// rollover partiel pour les produits (RES)
	$("#resultats .titre2, #resultats .visuel").mouseover( function() {
		$(this).parent().removeClass("border");
		$(this).parent().addClass("border_jaune");
	} );

	$("#resultats .titre2, #resultats .visuel").mouseout( function() {
		$(this).parent().removeClass("border_jaune");
		$(this).parent().addClass("border");
	} );


	// rollover partiel pour les produits (PAN)
	$("#proposition .titre3, #proposition .visuel").mouseover( function() {
		$(this).parent().removeClass("border");
		$(this).parent().addClass("border_jaune");
	} );

	$("#proposition .titre3, #proposition .visuel").mouseout( function() {
		$(this).parent().removeClass("border_jaune");
		$(this).parent().addClass("border");
	} );


	// plier/dï¿½plier pour la FAQ
	$("#questions .titre2 a").click( function() {
		$(this).parents("li").toggleClass("close");
	} );

// hack IE calendar
if($.browser.msie)
{
   $(".calendrier_show").focus(function(){
       $(".hidecalendar").hide();
   });
   $(".calendrier_show").blur(function(){
       $(".hidecalendar").show();
   });
}

	// Calendrier
	if($(".calendrier_show")[0]) {

		dT = new Date();
		dT = new Date(dT.getFullYear(), dT.getMonth(), (dT.getDate() + 2));
		$("input.calendrier_show").calendar({
			clearText: '',
			closeText: '<img src="/extension/KiloutouDesign/design/kiloutou/images/template/picto_croix.gif" alt="Fermer" title="Fermer" />',
			prevText: '<img src="/extension/KiloutouDesign/design/kiloutou/images/template/calendrier_prev.gif" alt="PrÃ©cÃ©dent" title="PrÃ©cÃ©dent" />&nbsp;&nbsp;',
			nextText: '&nbsp;&nbsp;<img src="/extension/KiloutouDesign/design/kiloutou/images/template/calendrier_next.gif" alt="Suivant" title="Suivant" />',
			currentText: "Aujourd'hui",
			buttonImage: '/extension/KiloutouDesign/design/kiloutou/images/template/picto_calendrier.gif',
			buttonImageOnly: true,
			autoPopUp: "both",

			firstDay: 1,
			dayNames: new Array('Dim','Lun','Mar','Mer','Jeu','Ven','Sam'),
			monthNames: new Array('Janvier','FÃ©vrier','Mars','Avril','Mai','Juin','Juillet','AoÃ¹t','Septembre','Octobre','Novembre','DÃ©cembre'),
			yearRange: dT.getFullYear() + ':' + (dT.getFullYear() + 1),
			minDate:dT,
			customDate: function joursFermeture(date) {
				rtn = new Boolean(true);
				jourFerie = [
								[1, 1],		// Jour de l'An
								[5, 1],		// 1er Mai
								[12, 25],	// Noï¿½l
								[10, 15]
							];
				// Jours Fï¿½riï¿½s
				for(i=0; i<jourFerie.length; i++) {
					if (date.getMonth() == jourFerie[i][0] - 1 && date.getDate() == jourFerie[i][1]) {
						rtn = false;
					}
				}
				// Week-end
				if(date.getDay() < 1) {
					rtn = false;
				}
				if(rtn == false) 	{return [false, ''];}
				else				{return [true, ''];}
			}
		});
	}


	//switch description produit/vidï¿½o

	if($("#fiche")[0])
	{
		$("#fiche a#video").click( function() {
			$(this).parent().parent().parent().parent().parent().css("display", "none");
			$("#fiche div.video").css("display", "block");

			return (false);

		} );

		$("#fiche a#description").click( function() {
			$(this).parent().parent().css("display", "none");
			$("#fiche div.description").css("display", "block");
		} );
	}


	//incrï¿½menter/dï¿½crï¿½menter les quantitï¿½s du panier
	$("a.plus").click( function() {
		$(this).parents("td").children("input").val(parseInt($(this).parents("td").children("input").val()) + 1);
	} );

	$("a.moins").click( function() {
		if ($(this).parents("td").children("input").val()!=0) {
			$(this).parents("td").children("input").val(parseInt($(this).parents("td").children("input").val()) - 1);
		}
	} );


// png transparents pour IE
	if (navigator.appName.substring(0, 3) == "Mic"){
		if (navigator.appVersion.indexOf("6.0")>0){
			for (i = 0; i < document.images.length; i++){
				if (document.images[i].src.substring(document.images[i].src.length-3, document.images[i].src.length) == "png") {
				  document.images[i].style.height = document.images[i].height + "px";
				  document.images[i].style.width = document.images[i].width + "px";
				  document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + document.images[i].src + ",sizingMethod='scale')";
				  document.images[i].src = "/extension/KiloutouDesign/design/kiloutou/images/template/blank.gif";
				}
			}
		}
	}

// flashs

	$("#noflash").flash({
		src:"/extension/KiloutouDesign/design/kiloutou/flash/animation_home.swf",
		width:350,
		wmode:"transparent",
		height:160
		},{
			version:8
		}
	);

	// Remplacement des Select
	var h = "";
	$("#res-form select").each(function() {
		$(this).attr("class", "none");
		$(this).hide();
		h += '<div>';
		h += '<input type="text" value=" '+$(this).children("option:first").text()+'" id="'+$(this).attr("name")+'-input"/>';
		h += '<img src="/extension/KiloutouDesign/design/kiloutou/images/template/select.gif" alt="" />';
		h += "</div>";
		h += '<ul id="'+$(this).attr("id")+'">';
		$(this).children("option").each(function(i) {
		    if( $(this).val() != 'select_lib' ) {
    			h += '<li>';
    			h += '<a href="#" rel="'+$(this).val()+'" onclick="xajax_searchfamilyproducts('+$(this).val()+');">'+$(this).text()+'</a>';
    			h += '</li>';
		    }
		});
		h += "</ul>";
	});
	$("#res-form").prepend(h);
	$("#res-form input").focus(function() {
		$(this).blur();
		$("#res-form ul").hide();
		$(this).parent("div").next("ul").show();
	});
	$("#res-form div img").click(function() {
		$("#res-form ul").hide();
		$(this).parent("div").next("ul").show();
	});
	$("#res-form ul li a").click(function() {
		$("#res-form ul").hide();
		a = $(this).attr("rel");
		$(this).parents("p").children("select").children("option").each(function() {
			if($(this).val() == a) {
				$(this).attr("selected", "selected");
			}
		});
		$(this).parents("ul").prev("div").children("input").attr("value", " "+$(this).text());
		return false;
	});
	$(document.body).mousedown(function(event) {
		var target = $(event.target);
		if(target.parents("#res-form").length == 0) {
			$("#res-form ul").css("display", "none");
		}
	});

});



