arrSostituzioni=new Array(

	Array("Huiles Kousmi\'Life","<span class=\"nome-prodotto-2\">Huiles Kousmi\'Life</span>"),
Array("Kousmi\'Life","<span class=\"nome-prodotto-2\">Kousmi\'Life</span>"),
Array("Kousmi\' Life","<span class=\"nome-prodotto-2\">Kousmi\' Life</span>"),
Array("Livre d\'Art","<span class=\"nome-prodotto-2\">Livre d\'Art</span>"),
Array("Phytoquant","<span class=\"nome-prodotto-1\">Phyto</span><span class=\"nome-prodotto-2\">Quant</span>"),
Array("Quantabourrache","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">bourrache</span>"),
Array("Quantabourrache (100 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">bourrache</span> (100 Capsules)"),
Array("Quantabourrache (200 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">bourrache</span> (200 Capsules)"),
Array("Quantacal","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">cal</span>"),
Array("Quantacoeur","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">coeur</span>"),
Array("Quantadraine","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">draine</span>"),
Array("Quantadyn","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">dyn</span>"),
Array("Quantaflore","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">flore</span>"),
Array("QuantaHDL","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">HDL</span>"),
Array("Quantakel","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">kel</span>"),
Array("Quantamag","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">mag</span>"),
Array("Quantaomega3","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">omega3</span>"),
Array("Quantaomega3 (180 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">omega3</span> (180 Capsules)"),
Array("Quantaomega3 (90 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">omega3</span> (90 Capsules)"),
Array("Quantaonagre","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">onagre</span>"),
Array("Quantaonagre (100 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">onagre</span> (100 Capsules)"),
Array("Quantaonagre (200 Capsules)","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">onagre</span> (200 Capsules)"),
Array("QuantaOx","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">Ox</span>"),
Array("Quantaphylle","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">phylle</span>"),
Array("Quantaregul","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">regul</span>"),
Array("Quantarelax","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">relax</span>"),
Array("Quantaroyale","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">royale</span>"),
Array("Quantasmodium","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">smodium</span>"),
Array("Quantastimmun","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">stimmun</span>"),
Array("Quantaveine","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">veine</span>"),
Array("Quantaveino-GEL","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">veino-GEL</span>"),
Array("QuantaveinoGEL","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">veinoGEL</span>"),
Array("Quantavera","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">vera</span>"),
Array("Quantavie","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">vie</span>"),
Array("Quantavillosi","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">villosi</span>"),
Array("Quantaviris","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">viris</span>"),
Array("Quantavital","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">vital</span>"),
Array("Quantabuccal","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#00a3de;\">buccal</span>"),
Array("Quantabugast","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#e85790\">bugast</span>"),
Array("Quantadigest","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#41a62a;\">digest</span>"),
Array("Quantaderm","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#756fad;\">derm</span>"),
Array("Quantalostrum","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#8acdcb\">lostrum</span>"),
Array("Quantaroïde","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\" style=\"color:#ef8301;\">roïde</span>"),
Array("QuantaLAX","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">LAX</span>"),
Array("Quantacalm","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">calm</span>"),
Array("Quantapunch","<span class=\"nome-prodotto-1\">Quanta</span><span class=\"nome-prodotto-2\">punch</span>")
	

	);

$(document).ready(function() {

			$(".submenu").addClass("noshow");
			$("#main-menu span").hover(

					function() {

						$(this).addClass("main-menu-hover");


					},
					function() {
					
						$(this).removeClass("main-menu-hover");

					});


			$("#main-menu span").append("<img src=\"http://www.phytoquant.net/images/arrow-down-on-white.gif\" class=\"menu-arrow\" />");
			$("#main-menu span").click(function() { 
				arrImg=$(this).children("img");
				$(arrImg[0]).trigger("click");

			});
			$(".menu-arrow").click(mainMenuOnClickArrow);

			// sostituzione di phytoquant

			substituteNamePhytoquant(this);		
			substituteNamesAdvanced(this);
			substituteNameProdotti(this);
			substituteNamesInA(this);

			// menu ricerca

			//$("#form-ricerche-container").addClass("noshow");
			$("#ricerca-prodotto h4").append("<img src=\"http://www.phytoquant.net/images/arrow-up-on-green.gif\" id=\"arrow-ricerca\" />");
			$("#ricerca-prodotto h4").click(function() { 
				arrImg=$(this).children("img");
				$(arrImg[0]).trigger("click");

			});
			$("#arrow-ricerca").click(ricercaOnClickArrow);

			$("#ricerca-prodotto h4").hover(function() {

				$(this).addClass("hover");


				},
				function() {

				$(this).addClass("hover");

			});

			$(".ricerca-prodotto-submit").hover(function() {

				
					$(this).addClass("hover");


				},
				function() {

					$(this).addClass("hover");


				});

			$(".ricerca-prodotto-submit").click(function() {

				$(this).parent().parent().trigger("submit");


			});

			$("#ricerca-prodotto-nome").autocomplete({
	
				serviceUrl:'http://www.phytoquant.net/ajax/ajax_get_prodotti.php',
				minChars:1, 
				delimiter: /(,|;)\s*/, // regex or character
				maxHeight:100,
				width:220,
				zIndex: 9999,
				deferRequestBy: 0, //miliseconds
				params: { limit: 50, lang: 0, country: 'us' },
				// callback function:
				onSelect: onRicercaProdottoFound
			});

			$("#ricerca-prodotto-patologie").autocomplete({
	
				serviceUrl:'http://www.phytoquant.net/ajax/ajax_get_patologie.php',
				minChars:1, 
				delimiter: /(,|;)\s*/, // regex or character
				maxHeight:100,
				width:220,
				zIndex: 9999,
				deferRequestBy: 0, //miliseconds
				params: { limit: 50, lang: 0, country: 'us' },
				// callback function:
				onSelect: onRicercaPatologieFound
			});

			// bindiamo il submit dei form di ricerca
			$("#ricerca-nome").bind("submit",onSubmitRicercaNome);
			$("#ricerca-patologia").bind("submit",onSubmitRicercaPatologia);

			// prepariamo il menu sport se presente

				if ($("#menu-sport").length>0) { // cycle delle immagini
	
					$("#menu-sport-immagine").cycle({ timeout: 5000 });
	
				$(".menu_sport_switch").click(function(e) {
	
						if ($(this).hasClass("open")) {
							
							$(this).removeClass("open");
							$("#menu-sport-items").slideUp(500);
							e.preventDefault();
	
	
						} else {
	
							$(this).addClass("open");
							$("#menu-sport-items").slideDown(500);
							e.preventDefault();
						}
	
				});
	
				$("#menu-sport span").hover(
	
						function() {
	
							$(this).addClass("main-menu-hover");
	
	
						},
						function() {
						
							$(this).removeClass("main-menu-hover");
	
						});
	
	
				$("#menu-sport span").append("<img src=\"http://www.phytoquant.net/images/arrow-down-on-white.gif\" class=\"menu-arrow\" />");
				$("#menu-sport span").click(function(e) { 
					arrImg=$(this).children("img");
					$(arrImg[0]).trigger("click");
					e.preventDefault();
	
				});
				$(".menu-arrow").click(mainMenuOnClickArrow);

				// infine apriamo se necessario il menu sport

				arrSpanMenu=$("#sport_menu_selected").parent().prev("span");
				if (arrSpanMenu.length) { 

					$(arrSpanMenu[0]).addClass("submenu-selected");
					$(arrSpanMenu[0]).trigger("click");
					$("#menu-sport h4 a").trigger("click");
				}

			}

			// prepariamo il menu eventi se presente

				if ($("#menu-eventi").length>0) { 
	
				$(".menu_sport_switch").click(function(e) {
	
						if ($(this).hasClass("open")) {
							
							$(this).removeClass("open");
							$("#menu-sport-items").slideUp(500);
							e.preventDefault();
	
	
						} else {
	
							$(this).addClass("open");
							$("#menu-sport-items").slideDown(500);
							e.preventDefault();
						}
	
				});
	
				$("#menu-eventi span").hover(
	
						function() {
	
							$(this).addClass("main-menu-hover");
	
	
						},
						function() {
						
							$(this).removeClass("main-menu-hover");
	
						});
	
	
				$("#menu-eventi span").append("<img src=\"http://www.phytoquant.net/images/arrow-down-on-white.gif\" class=\"menu-arrow\" />");
				$("#menu-eventi span").click(function(e) { 
					arrImg=$(this).children("img");
					$(arrImg[0]).trigger("click");
					e.preventDefault();
	
				});
				$(".menu-arrow").click(mainMenuOnClickArrow);

				// infine apriamo se necessario il menu sport

				/*arrSpanMenu=$("#sport_menu_selected").parent().prev("span");
				if (arrSpanMenu.length) { 

					$(arrSpanMenu[0]).addClass("submenu-selected");
					$(arrSpanMenu[0]).trigger("click");
					$("#menu-sport h4 a").trigger("click");
				}*/

			}

			// infine apriamo se necessario il menu pricinpale

			arrSpanMenu=$("#menu_selected").parent().prev("span");
			if (arrSpanMenu.length) { 

				$(arrSpanMenu[0]).addClass("submenu-selected");
				$(arrSpanMenu[0]).trigger("click");
			}
			
			
});

function onSubmitRicercaNome()
{
	strNome=$("#ricerca-prodotto-nome").attr("value");
	$.post('http://www.phytoquant.net/ajax/ajax_getficheurlbyname.php',{ name: strNome, lang: 'fr', lang_num: 0 },onGetFicheUrlByName);
	return false;

}

function onGetFicheUrlByName(strUrl)
{
	if (strUrl) window.location=strUrl;
}

function onSubmitRicercaPatologia()
{
	strNome=$("#ricerca-prodotto-patologie").attr("value");
	$.post('http://www.phytoquant.net/ajax/ajax_getpatologieurlbyname.php',{ name: strNome, lang: 'fr', lang_num: 0 },onGetPatologieUrlByName);
	return false;

}

function onGetPatologieUrlByName(strUrl)
{
	if (strUrl) window.location=strUrl;
}
			

function onRicercaProdottoFound(strValue,data)
{
	// in data abbiamo l'id, in strValue il nome del prodotto
	$.post("http://www.phytoquant.net/ajax/ajax_getficheurl.php", { name: strValue, id: data, lang: 'fr'},onObtainedFicheUrl);
}

function onObtainedFicheUrl(strUrl)
{
	location=strUrl;
}

function onRicercaPatologieFound(strValue,data)
{
	$.post("http://www.phytoquant.net/ajax/ajax_getpatologieurl.php", {id: data, lang_num: 0, lang: 'fr' },onObtainedPatologieUrl);
}

function onObtainedPatologieUrl(strUrl)
{
	location=strUrl;
}

function mainMenuOnClickArrow(e)
{
	if ($(this).parent().next("div").hasClass("noshow")) {

		$(this).parent().addClass("open");
		$(this).parent().next("div").addClass("clicked"); // aggiunta

		$(this).parent().next("div").slideDown(500,mainMenuOnEndSlideDown);
		
	
	} else {

		$(this).parent().next("div").slideUp(500,mainMenuOnEndSlideUp);
		

	}

	e.stopPropagation();
		
}

function mainMenuOnEndSlideDown()
{
	arrImg=$(this).prev("span").children("img");
	$(arrImg[0]).attr("src","http://www.phytoquant.net/images/arrow-up-on-white.gif");
	$(this).removeClass("noshow");


	// aggiunta

	$("div.submenu").each(function() {

		if (!$(this).hasClass("clicked")) {

			$(this).slideUp(500);
			$(this).prev("span").removeClass("open");
			$(this).addClass("noshow");
			arrImg=$(this).prev("span").children("img");
			$(arrImg[0]).attr("src","http://www.phytoquant.net/images/arrow-down-on-white.gif");

			}
		

	
	});

	$("div.submenu").removeClass("clicked");

	// fine aggiunta
	
	
}

function mainMenuOnEndSlideUp()
{
	$(this).addClass("noshow");
	$(this).prev("span").removeClass("open");
	
	arrImg=$(this).prev("span").children("img");
	$(arrImg[0]).attr("src","http://www.phytoquant.net/images/arrow-down-on-white.gif");
}

function ricercaOnClickArrow(e)
{
	if ($(this).parent().next("div").hasClass("noshow")) {

		$(this).parent().addClass("open");
		
		$(this).parent().next("div").slideDown(500,ricercaOnEndSlideDown);
		
	
	} else {

		$(this).parent().next("div").slideUp(500,ricercaOnEndSlideUp);
		

	}

	e.stopPropagation();
		
}

function ricercaOnEndSlideDown()
{
	arrImg=$(this).prev("h4").children("img");
	$(arrImg[0]).attr("src","http://www.phytoquant.net/images/arrow-up-on-green.gif");
	$(this).removeClass("noshow");
	
}

function ricercaOnEndSlideUp()
{
	$(this).addClass("noshow");
	$(this).prev("h4").removeClass("open");
	
	arrImg=$(this).prev("h4").children("img");
	$(arrImg[0]).attr("src","http://www.phytoquant.net/images/arrow-down-on-green.gif");
}

function layoutActivateIconMenu()
{
	$("#icon-menu span").hover(

		function() {

			$(this).addClass("hover");


		},
		function() {
		
			$(this).removeClass("hover");

		});
}

function substituteNameProdotti(object)
{
	$(".substitute-nome-prodotto",object).each(function() {
	
	
		var strText=new String($(this).text());
		

		for (var i in arrSostituzioni) {

			var strSubstr=new String(arrSostituzioni[i][0]);

			if (strSubstr.toLowerCase()==strText.toLowerCase()) {

				$(this).html(arrSostituzioni[i][1]);
				//$(this).addClass("nome_prodotto");
			}

		}
		
	

		/*strText=$(this).text();

		strText1=strText.substr(0,6);

		if ((strText1=="Quanta")||(strText1=="quanta")) {

			strText2=strText.substr(6);

			strNome="<span class=\"nome-prodotto-1\">"+strText1+"</span><span class=\"nome-prodotto-2\">"+strText2+"</span>";

			$(this).html(strNome);

		}
		*/


	});
}

function substituteNamesAdvanced(object)
{
	$("u",object).each(function() {

		var strText=new String($(this).text());
		

		for (var i in arrSostituzioni) {

			var strSubstr=new String(arrSostituzioni[i][0]);

			if (strSubstr.toLowerCase()==strText.toLowerCase()) {

				$(this).html(arrSostituzioni[i][1]);
				$(this).addClass("nome_prodotto");
			}

		}

		
	});
}

function substituteNamesInA(object)
{
	$("a",object).each(function() {

		var strText=new String($(this).text().trim());

		for (var i in arrSostituzioni) {

			var strSubstr=new String(arrSostituzioni[i][0]);

			if (strSubstr.toLowerCase()==strText.toLowerCase()) {

				$(this).html(arrSostituzioni[i][1]);
				//$(this).addClass("nome_prodotto");
			}

		}

		
	});
}


function substituteNamePhytoquant(object)
{
	$("u",object).each(function() {

		strText=$(this).text();

		if (strText.toLowerCase()=="phytoquant") {

			 $(this).html("<span class=\"nome-phyto-1\">Phyto</span><span class=\"nome-phyto-2\">Quant</span>");
			$(this).addClass("nome-phyto");

		}
		

	});


}

function updateBasketItemCount()
{
	$("#menu-icone-basket-numero").load("http://www.phytoquant.net/ajax/ajax_get_total_items_count.php");
}

function startThrob()
{

	$("#throb").show();

}

function endThrob()
{

	$("#throb").hide();

}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


