jQuery(document).ready( function() {
	// pulse
	jQuery('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300);

	// Reveal
	jQuery('.wp-no-js-hidden').removeClass( 'wp-no-js-hidden' );

	jQuery('#footer li:last a').css('border','none');
	jQuery('#news-list li:last a').css('border-bottom','1px solid #f60');
	jQuery('#qtrans_language_chooser li:last a').css('border','none');
	
	// immagine del centimetro nel footer
	jQuery('#prefooter').append('<div id="footer-image"></div>');	
	jQuery('.articles:first').css('border-width','2px');
	
	jQuery(".MainCategory").click(function() {
		jQuery(this).next("div.SubCategories").slideDown(500).siblings("div.SubCategories").slideUp("slow");
		jQuery(this).siblings();
	});
	
	jQuery('#contB2 .SubCategories').each(function(n) {
		jQuery(this).find('li a:last').css('border-bottom','none');	
	});	

	
	if(jQuery('body').attr('id') == 'home') {
		jQuery('#nav li:first').addClass('current_page_item'); // stato attivo su home
	}
	jQuery('#nav li:last').addClass('cercanelsito'); // classe diversa per menu cerca nel sito	
	jQuery('#news-list li a:last').css('border-bottom','none');
	
	jQuery('#logo,#logo.logo-en,#logo.logo-it,#footer-image,#cart .welcome,#cart .world,#cart .carrello,#footer a.rss').ifixpng();


	var opzioni = {
		resizeLgImages:     true,
		displayNav:         true,
		loadingImage:		myurlsite+'/shadowbox/images/loading.gif',
		overlayBgImage:		myurlsite+'/shadowbox/images/overlay-85.png',
		handleUnsupported:  'remove',
		keysClose:          ['c','x', 27], // c or esc
		keysNext:			['n','s',39] // n s o freccia
	};
	Shadowbox.init(opzioni);





/*gestione baloon 	
da attivare bubble in includes/brands.php
var zmax = 0;
jQuery(function(){
	jQuery("#brand").mouseover(function () {
		jQuery(this).find(".bubble").animate({opacity: "show", top: "-75"}, "slow");		
		 // i.e. z-index hack fix
		 jQuery(this).find(".bubble").each(function() {
				 var cur =  jQuery( this ).css( 'zIndex');
				  zmax = cur > zmax ? cur : zmax;   // use 'cur' here instead of jQuery( this ).css( 'zIndex')
		 });
		 jQuery( this ).css( 'zIndex', zmax+1 );
	});
	
	jQuery("#brand").mouseout(function() {
		jQuery(this).find(".bubble").animate({opacity: "hide", top: "-85"}, "fast");
	});
});
*/

 
});

(function(JQ) {
	JQ.fn.tTips = function() {

		JQ('body').append('<div id="tTips"><p id="tTips_inside"></p></div>');
		var TT = JQ('#tTips');

		this.each(function() {
			var el = JQ(this), txt;
			
			if ( txt = el.attr('title') ) el.attr('tip', txt).removeAttr('title');
			else return;
			el.find('img').removeAttr('alt');

			el.mouseover(function(e) {
				txt = el.attr('tip'), o = el.offset();;

				clearTimeout(TT.sD);
				TT.find('p').html(txt);

				TT.css({'top': o.top + 16, 'left': o.left - 5});
				TT.sD = setTimeout(function(){TT.fadeIn(150);}, 100);
			});

			el.mouseout(function() {
				clearTimeout(TT.sD);
				TT.css({display : 'none'});
			})
		});
	}
}(jQuery));

jQuery(function(){jQuery('#cart a').tTips();});
jQuery(function(){jQuery('.firstcol a').tTips();});


function copia() {
	jQuery('.wpsc_checkout_table input:eq(7)').val(jQuery('.wpsc_checkout_table input:eq(0)').val()).addClass('copiato');
	jQuery('.wpsc_checkout_table input:eq(8)').val(jQuery('.wpsc_checkout_table input:eq(1)').val()).addClass('copiato');
	jQuery('.wpsc_checkout_table input:eq(9)').val(jQuery('.wpsc_checkout_table input:eq(2)').val()).addClass('copiato');
	jQuery('.wpsc_checkout_table input:eq(10)').val(jQuery('.wpsc_checkout_table input:eq(3)').val()).addClass('copiato');
	jQuery('.wpsc_checkout_table input:eq(11)').val(jQuery('.wpsc_checkout_table input:eq(4)').val()).addClass('copiato');	
	jQuery('.wpsc_checkout_table input:eq(13)').val(jQuery('.wpsc_checkout_table input:eq(5)').val()).addClass('copiato');
	jQuery('.wpsc_checkout_table textarea:eq(1)').val(jQuery('.wpsc_checkout_table textarea:eq(0)').val()).addClass('copiato');
}

function test(par) {
	alert(par);
}

function ricercasito(){
	valore = jQuery("#cercanelsito input[@name='type']:checked").val();

	if(jQuery("#cercanelsito #cercanelsito-input").val() == '') {
		alert('Inserire almeno una parola per la ricerca');
		return false;
	} else {
		if(valore == "sito") {
			//alert('valore sito');
			jQuery("#cercanelsito #cercanelsito-input").attr("name","s");
			jQuery("#cercanelsito").attr("action", myabsurl);
			jQuery("#cercanelsito").submit();
		} else if (valore == "shop") {
			jQuery("#cercanelsito #cercanelsito-input").attr("name","product_search");
			jQuery("#cercanelsito").attr("action", myabsurl+"shop/");
			jQuery("#cercanelsito").submit();
		}
	}
}


jQuery(document).ready( function() {
	jQuery("#cercanelsito a").click(function() {
		ricercasito();
	});

//jQuery('#cercanelsito input').bind('keypress', function(e) {
jQuery('#cercanelsito input').keydown(function(e) {
	if(e.keyCode==13) {
		if(jQuery("#cercanelsito #cercanelsito-input").attr('value') == '') {
			alert('Inserire almeno una parola per la ricerca');
			return false;
			} else {
				ricercasito();
			}
	}
});




jQuery("#cerca a").toggle(function() {
	jQuery("#boxcerca").animate({
		height: 'show',
		opacity: 'show'
	}, 'fast');
}, function() {
	jQuery("#boxcerca").animate({
		height: 'hide',
		opacity: 'hide'
	}, 'fast');
});
	
	
});





// metodo di pagamento
jQuery(document).ready( function() {
	
	jQuery("#copiadatispedizione").html("Stessi dati per la Spedizione? Clicca qui per copiarli");
		
	jQuery("input[@name='payment_method']").change(
	function() {
		if (jQuery("input[@id='payment_method_2']:checked").val())
		// qui fai fare qualcosa se scelgono bonifico bancario o contrassegno
		var gino;
		else 	
		// qui fai fare qualcosa se paypal carta credito
		jQuery(this).blur();
		});
});



function badBrowser(){
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6){ return true;}
	
	return false;
}

function getBadBrowser(c_name)
{
	if (document.cookie.length>0)
	{
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}	

function setBadBrowser(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

if(badBrowser() && getBadBrowser('browserWarning') != 'seen' ){
	jQuery(function(){
		jQuery("<div id='browserWarning'><strong>Siamo spiacenti: si sta utilizzando un browser non supportato. Si prega di effettuare l'aggiornamento a <a href='http://getfirefox.com'><em>FireFox</em></a> o <a href='http://www.apple.com/safari/'><em>Safari</em></a>.&nbsp;&nbsp;&nbsp;[<a href='#' id='warningClose'>ignora</a>] </strong><br ><br > Sorry: you are currently using an unsupported browser. Please upgrade to <a href='http://getfirefox.com'><em>FireFox</em></a> or <a href='http://www.apple.com/safari/'><em>Safari</em></a>.&nbsp;&nbsp;&nbsp;[<a href='#' id='warningClose'>ignore</a>]</div> ")
			.css({
				backgroundColor: '#fcfdde',
				'width': '100%',
				'border-top': 'solid 1px #000',
				'border-bottom': 'solid 1px #000',
				'text-align': 'center',
				padding:'10px 0px 15px 0px'
			})
			.prependTo("body");
		
		jQuery('#warningClose').click(function(){
			setBadBrowser('browserWarning','seen');
			jQuery('#browserWarning').slideUp('slow');
			return false;
		});
	});	
}




