jQuery.noConflict();
jQuery(document).ready(function() {
	
	function get_substr (str, full_class) {var arr_class = new Array();if (full_class){if (full_class.indexOf(str)!==-1){arr_class = full_class.split(' ');if ( arr_class ){for ( var arr_i in arr_class ){if (arr_class[arr_i].indexOf(str)!==-1){cat_class = arr_class[arr_i];return cat_class.slice(str.length);}}}}}}
	
	jQuery('ul#menu-principale li.current-cat a').removeAttr('title');
	
	if (jQuery('body.single-post ul li.current-cat-32').length && jQuery('body.single-post ul li.current-cat-11').length) jQuery('body.single-post ul li.current-cat-32').removeClass('current-cat-32');
	//if (jQuery('body.single-post ul li.current-cat-33').length && jQuery('body.single-post ul li.current-cat-11').length) jQuery('body.single-post ul li.current-cat-20').removeClass('current-cat-33');
	// Link aggiornato al post sull'immagine della macchinetta
	jQuery('div.macchinetta h3 a').each(function(i,o){
		tmpid = get_substr('post-', jQuery(o).attr('id'));
		tmp = jQuery('img#immagine-'+tmpid).parent();
		tmpCopy = tmp.html();
		jQuery(tmp).append('<a href="'+jQuery(o).attr('href')+'" class="immagine-'+get_substr('post-', jQuery(o).attr('id'))+'">--</a>');
		jQuery('img', tmp).remove();
		jQuery('a.immagine-'+tmpid).html(tmpCopy);
		tmp = jQuery('div#scheda-'+tmpid);
		tmpCopy = '<table>'+tmp.find('table').html()+'</table>';
		jQuery(tmp).empty();
		jQuery(tmp).append(tmpCopy);
		tmpid = tmp = tmpCopy = null;
	});
	/*jQuery('div#sidebar, div#content, div#footer').fadeOut(0).fadeIn(600);*/
	jQuery('.scheda').hide();
	jQuery('.scheda').removeClass('nascosto_jq');
	curr_cat = get_substr('cat-item-', jQuery('li.current-cat').attr('class'));
	if (curr_cat == 32) {
		jQuery('div#scheda-400').show();
		jQuery('div.macchinetta h3 a#400').attr('class','acceso');
		jQuery('div.macchinetta h3 a').attr('title','Clicca qu&igrave; per visualizzare la scheda tecnica');
		jQuery('img#immagine-414').css({ opacity: 0.5 });
		jQuery('img#immagine-412').css({ opacity: 0.5 });
		jQuery('img#immagine-404').css({ opacity: 0.5 });
	}
	else {
		jQuery('div#scheda-594').show();
		jQuery('div.macchinetta h3 a#594').attr('class','acceso');
		jQuery('div.macchinetta h3 a').attr('title','Click here to view technical characteristics');
		jQuery('img#immagine-597').css({ opacity: 0.5 });
		jQuery('img#immagine-601').css({ opacity: 0.5 });
		jQuery('img#immagine-607').css({ opacity: 0.5 });
	}
	jQuery('div.macchinetta h3 a').hover(function() {
		idscheda = get_substr('post-', jQuery(this).attr('id'));
		if (idscheda != get_substr('scheda-', jQuery('div.scheda:visible').attr('id')))
		{
			jQuery('div.macchinetta img').css({ opacity: 0.5 });
			jQuery('img#immagine-'+idscheda).css({ opacity: 1 });
			jQuery('div.macchinetta h3 a').css('color','#a5a5a5');
			jQuery('div.macchinetta h3 a').attr('class','spento');
			jQuery('div.macchinetta h3 a#'+idscheda).attr('class','acceso');
			jQuery(this).css('color','#414141');
			
			//alert(idscheda+' != '+get_substr('scheda-', jQuery('div.scheda:visible').attr('id')));
			jQuery('div.scheda').stop(true, true).slideUp(300, 'swing');
			jQuery('div#scheda-'+idscheda).stop(true, true).slideDown(300, 'swing');
		}
		//var w = window.screen.width;
		//var h = window.screen.height;
		//window.scrollTo(w * h, w * h);
	});
	//jQuery(this).animate({marginLeft: "0px" }, { queue:false, duration:300 }, 'swing');
	jQuery('div.macchinetta div.entry img').hover(function() {
		idscheda = get_substr('immagine-', jQuery(this).attr('id'));
		if (idscheda != get_substr('scheda-', jQuery('div.scheda:visible').attr('id')))
		{
			jQuery('div.macchinetta img').css({ opacity: 0.5 });
			jQuery('img#immagine-'+idscheda).css({ opacity: 1 });
			jQuery('div.macchinetta h3 a').css('color','#a5a5a5');
			jQuery('div.macchinetta h3 a').attr('class','spento');
			jQuery('div.macchinetta h3 a#post-'+idscheda).attr('class','acceso').css('color','#414141');
			
			//alert(idscheda+' != '+get_substr('scheda-', jQuery('div.scheda:visible').attr('id')));
			jQuery('div.scheda').stop(true, true).slideUp(300, 'swing');
			jQuery('div#scheda-'+idscheda).stop(true, true).slideDown(300, 'swing');
		}
		//var w = window.screen.width;
		//var h = window.screen.height;
		//window.scrollTo(w * h, w * h);
	});
	/*
	jQuery('div.macchinetta h3 a').click(function(e) {
		e.preventDefault();
		idscheda = jQuery(this).attr('id');
		jQuery('div.scheda').hide();
		jQuery('div.macchinetta h3 a').css('color','#a5a5a5');
		jQuery('div.macchinetta h3 a').attr('class','spento');
		jQuery('div.macchinetta h3 a#'+idscheda).attr('class','acceso');
		jQuery('div.macchinetta img').css({ opacity: 0.5 });
		jQuery(this).css('color','#414141');
		jQuery('img#immagine-'+idscheda).css({ opacity: 1 });
		jQuery('div#scheda-'+idscheda).show();
		var w = window.screen.width;
		var h = window.screen.height;
		window.scrollTo(w * h, w * h);
	});
	*/
	if (jQuery('div.banner_affiliazione').length) jQuery('div#content table').attr('style', 'width: 650px;');	// tabella macchinetta/e
	jQuery('div.menu_sidebar li#post-508').remove();
	jQuery('div#footer p').append('<div id="tooltip-credits" style="display: none;" class="info-credits"></div>');
	jQuery('div#footer p a.credits').tooltip({tip:'#tooltip-credits',position:'top center',offset:[0,0],lazy:true,delay:0});
	
	jQuery('body.category-prodotti div#content div.post, body.category-products-en div#content div.post').each(function(i, o){
		jQuery(o).find('img').parent().html('<a href="'+jQuery(o).find('h3 a').attr('href')+'">'+jQuery(o).find('img').parent().html()+'</a>');
	});
	//jQuery('body.category-prodotti div.single_category, body.category-products-en div.single_category').each(function(i, o){
		//jQuery(o).find('img').attr('style', 'width:120px;');
	//});
	
	if (!self.getRequestParameter)
	{
		function getRequestParameter(param) {
			var q = document.location.search || document.location.hash;
			if(q) {
				var pairs = q.substring(1).split("&");
				for (var i=0; i < pairs.length; i++) {
					if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
						return pairs[i].substring((pairs[i].indexOf("=")+1));
					}
				}
			}
			return "";
		}
	}
	
	if (jQuery('div.foto_prodotto').length) {
		var spostare = jQuery('div.scheda_prod span.yak_price').html();
		jQuery('div.scheda_prod span.yak_price').remove();
		if (jQuery('li.cat-item-16').length) { 
			jQuery('input[name=buynow_quantity]').before('<span class="yak_price">'+spostare+'</span><span class="etic_q">Quantity</span>');
		}
		else jQuery('input[name=buynow_quantity]').before('<span class="yak_price">'+spostare+'</span><span class="etic_q">Quantit&agrave;</span>');
		
		if (jQuery('table.yak-multi td.yak-multi').length)
		{
			jQuery('table.yak-multi td.yak-multi').last().html(jQuery('table.yak-multi td.yak-multi').last().html().replace('Misto', 'Misto <span class="infotab" title="600 cialde di caffè naturale + 150 cialde di caffè decaffeinato"></span>'));
			jQuery('table.yak-multi td.yak-multi').last().html(jQuery('table.yak-multi td.yak-multi').last().html().replace('Mixed', 'Mixed <span class="infotab" title="600 pods of natural coffee + 150 pods of decaffeinated coffee"></span>'));
		}

		jQuery('input[name=buynow_quantity]').val(1);
		if (((jQuery('div.scheda_prod table').size()) - (jQuery('div.scheda_prod form[name=buynow] table').size())) > 1) {
			jQuery('div.scheda_prod table').last().addClass('seconda_tab');
			jQuery('div.scheda_prod table').last().prev().addClass('prima_tab');
			var titolo_pt = jQuery('div.scheda_prod table th.th-table').last().html();
			jQuery('div.scheda_prod table th.th-table').html('<a class="grafico pros_tab">Tabella successiva</a><a class="grafico prec_tab_off">Tabella precedente</a>'+titolo_pt);
			jQuery('div.scheda_prod table th.th-table').last().html('<a class="grafico pros_tab_off">Tabella successiva</a><a class="grafico prec_tab">Tabella precedente</a>'+titolo_pt);
		}
	}
	
	jQuery('table.seconda_tab').hide(0);
	jQuery('a.pros_tab').live('click', function(e){
		 jQuery('table.prima_tab').hide(0);
		 jQuery('table.seconda_tab').show(0);
    });
	jQuery('a.prec_tab').live('click', function(e){
		 jQuery('table.seconda_tab').hide(0);
		 jQuery('table.prima_tab').show(0);
	});
	
	
	
	testo_cerca = ((window.location.toString().indexOf('/en/')!==-1||getRequestParameter('lang')=='en')?'Site search':'Cerca nel sito');
	jQuery('form#searchform input#s').ready(function(){
		var tthis = 'form#searchform input#s';
		if (!jQuery(tthis).val()) jQuery(tthis).val(testo_cerca);
	});
	jQuery('form#searchform input#s').focusout(function(){
		if (!jQuery(this).val()) jQuery(this).val(testo_cerca);
	});
	jQuery('form#searchform input#s').focusin(function(){
		if (jQuery(this).val() == testo_cerca) jQuery(this).val('');
	});
	/*jQuery('div.menu ul#menu-principale li').each(function(i, o){
		if (get_substr('current-cat-', jQuery(this).attr('class')) && !jQuery('.cat-item-11.current-cat', this).length)	//':not(.current-cat-11)', 
			jQuery('div.menu ul#menu-principale li:eq('+i+'):not(.cat-item-11.current-cat) a').attr('style','cursor:default;border: 1px solid red;').click(function(e){e.preventDefault();});
		/*
		if (get_substr('current-cat-', jQuery(this).attr('class')))	//':not(.current-cat-11)', 
			jQuery('div.menu ul#menu-principale li:eq('+i+'):not(.current-cat-11) a').attr('style','cursor:default;border: 1px solid red;').click(function(e){e.preventDefault();});
			*/
		//jQuery('div.menu ul#menu-principale li:not(.cat-item-11.current-cat)').css('border', '1px solid red');
		//jQuery(':not(.cat-item-11.current-cat)', this).css('border', '1px solid red');
		//jQuery('div.menu ul#menu-principale li:eq('+i+'):not(.cat-item-11.current-cat) a').css('border', '1px solid red');
	//});
	jQuery('div.menu ul#menu-principale li').each(function(i, o){
		mypcat = get_substr('current-cat-', jQuery(this).attr('class'));
		if (mypcat&&!jQuery('div.menu_sidebar ul.elenco_post').length&&(mypcat=='4'||mypcat=='6'||mypcat=='16'||mypcat=='10'||mypcat=='15'||mypcat=='54'||mypcat=='55'))	//||mypcat=='carrello'
		{
			jQuery('div.menu ul#menu-principale li.current-cat-'+mypcat+' a').attr('style','cursor:default;').click(function(e){e.preventDefault();});
		}
	});
	jQuery('div.menu ul#menu-principale li.current-cat a').attr('style','cursor:default;').click(function(e){e.preventDefault();});
	/*
	jQuery('div.menu ul#menu-principale li').each(function(i, o){
		tthis = jQuery('div.menu ul#menu-principale li:eq('+i+')');
		if (tthis.children().attr('style')) jQuery(tthis).click(function(e){e.preventDefault();});
		else jQuery(tthis).attr('style', 'cursor:pointer;cursor:hand;').click(function(e){jQuery(e.target).children().click(function(e){return true;}).click();});	// Non clicca
		//.attr('style', 'border: 1px solid red;')
	});
	*/
	jQuery('form#searchform input#searchsubmit').click(function(e){
		var tthis = 'form#searchform input#s';
		if (jQuery(tthis).val() == testo_cerca) {/*jQuery(tthis).val('');*/ e.preventDefault(); alert(((getRequestParameter('lang')=='en')?'Insert key for start your search.':'Inserire una o piu\' parole per eseguire la ricerca.'));}
	});
	jQuery('div.lingua div#lang_sel_list ul li a.lang_sel_sel').attr('style', 'cursor:default;opacity:.5;filter:alpha(opacity=50);').bind('click', function(e){e.preventDefault();});
	/*
	jQuery.event.add(window, 'load', resizeFrame);
	jQuery.event.add(window, 'resize', resizeFrame);
	function resizeFrame()
	{
		var h = jQuery(window).height();
		var w = jQuery(window).width();
		jQuery("html, body").css('height',jQuery(window).height());
		jQuery("#footer").css('background-color', '#FFFFFF');
		jQuery("#page").css('height', (jQuery(window).height()-jQuery('#header').height()-parseInt(jQuery('#header').css('margin-bottom'))-jQuery('#footer').height()-parseInt(jQuery('#footer').css('margin-top')))+'px');
		jQuery("#page").css('min-height', 'inherit');
	}
	*/
	//jQuery('body.single div.single_prodotti span.yak_price').html(jQuery('body.single div.single_prodotti span.yak_price').html()+ '<span class="ii" title="IVA 20% inclusa">i.i.</span>');
	jQuery('body.single div.single_prodotti span.yak_price').after('<span class="ii">IVA 20% inclusa</span>');
	iqty = jQuery('body.single div.single_prodotti input[name=buynow_quantity]');
	if (iqty.length)
	{
		iqty.after('<div class="buy_cmd"><div class="up"></div><div class="down"></div></div>');
		iqty.parent().find('div.up').click(function(e){
			ival = jQuery(e.target).parent().parent().find('input[name=buynow_quantity]');
			cval = parseInt(ival.val());
			if (cval<100) ival.val(cval+1);
		});
		iqty.parent().find('div.down').click(function(e){
			ival = jQuery(e.target).parent().parent().find('input[name=buynow_quantity]');
			cval = parseInt(ival.val());
			if (cval>1) ival.val(cval-1);
		});
		jQuery('input[name=buynow_quantity]').blur(function(e){	// blur
			ival = jQuery(e.target);
			cval = parseInt(ival.val());
			if (isNaN(cval) || cval<=0 || cval>100) ival.val(1);
			else ival.val(cval);
		});
	}
	if (jQuery('form#cart td.yak_quantity').length)
	{
		jQuery('form#cart td.yak_quantity input').each(function(i,o){
			//tmpid = get_substr('post-', jQuery(o).attr('id'));
			jQuery(o).after('<div class="buy_cmd"><div class="up"></div><div class="down"></div></div>');
		});
		jQuery('form#cart td.yak_quantity div.up').click(function(e){
			ival = jQuery(e.target).parent().parent().find('input');
			if (ival.val()<100) ival.val(parseInt(ival.val())+1);
		});
		jQuery('form#cart td.yak_quantity div.down').click(function(e){
			ival = jQuery(e.target).parent().parent().find('input');
			if (ival.val()>0) ival.val(parseInt(ival.val())-1);
		});
	}
	//foto_grande = jQuery('body.single div.foto_prodotto a.foto_prodotto_grande');
	//if (foto_grande.length)
	//{
		/*
		foto_grande.parent().append('<img class="foto_prodotto_grande" src="'+foto_grande.attr('href')+'" style="display:none;" />');
		setTimeout("jQuery('img.foto_prodotto_grande').fadeIn(0);jQuery('img.foto_prodotto_grande').fadeOut(0);", 500);
		jQuery(foto_grande).hover(function(e){jQuery('img.foto_prodotto_grande').fadeIn(300)});
		jQuery('img.foto_prodotto_grande').hover(function(){},function(e){jQuery('img.foto_prodotto_grande').fadeOut(300)});
		//jQuery('body.single a.foto_prodotto_grande').hover(function(e){jQuery(e.target});
		*/
	//	foto_grande.fancybox();
	//}
	jQuery('body.single div.foto_prodotto a.foto_prodotto_grande').fancybox();
	jQuery('body.single div#post-16 a.foto_grande').fancybox();
	jQuery('body.single div#post-39 a.foto_grande').fancybox();
	jQuery('div#footer,div.sei_in').each(function(){jQuery(this).html(jQuery(this).html().replace(' @en', ''))});
	
	//jQuery('body.page-id-744 button#buybutton').parent().prev().text('Bonifico Bancario');
	//jQuery('body.page-id-797 button#buybutton').parent().prev().text('Bank transfer');
});
