function animAnchor(target) {
		//disattiva l'azione di default
		$(target).click(function(event) {
		event.preventDefault();
		var full_url = this.href;

		//recupera l'ancora
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 1500);
	});
}





// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}




var config_menu = { over: menuOpen, timeout: 300, out: menuClose};
var config_loghi = { over: logoHover, timeout: 150, out: menuOut};
function menuOpen() {
	$(this).children('ul').slideDown();
};
function menuClose() {
	$(this).children('ul').slideUp();
};

function logoHover() {
	$(this).fadeTo(250,0.7);
};
function menuOut() {
	$(this).fadeTo(150,1);
};



$(document).ready(function() {
	
var carrelloSpedizione = $('.crSpedizione');
if(carrelloSpedizione[0] != undefined)	{
	$('#prodSpese').remove();
}
	
$('.subCollane #column').wrapInner('<div id="mobileColumn">');



// ridimensiono il link in base alla dimensione dell'immagine in freschi di stampa
$('.inner_fr_st_container .immagine').each(function(index) {
    var larghezza = $(this).children('img').attr('width');
    $(this).css('width', larghezza);
});


	// creo un box in cui inserire il menu con le ancore
$('.subCollane #containerProduct').prepend('<div id="subNav"><h2>In questa collana</h2><ul></ul><hr class="clearL"/></div><hr class="clearL"/>');
$('.subCollane .subCollana > h2').each(function(index){
	// applico ad ogni titolo id univoci incrementali
	$(this).attr('id','sub' + index);

	var titolo = $(this).text();
	var ancora = 'sub' + index;
	
	// a parte il primo titolo appendo ad ogni titolo un link che torna su
	if (index >=1)
		$(this).append('<a class="goTop scroll" href="#container" title="Torna all\'inizio">Top</a>');

	// creo il menu
	$('#subNav ul').append('<li><a class="scroll" href="#' + ancora + '">' + titolo + '</a></li>')
});
	
	animAnchor('.scroll');
	
	//$("#home .fr_stampa_one:first").css('padding-left','0');
	//ridimensiono badge social
	$('.socialBadge img').css({'width' : '25','height' : '25'});

	$(".tabellario tr:odd").css("background-color", "#eee");	
	$(".box:odd").addClass('secondo');	
			
	// metto la classe first al primo elemento del menu
	$('#mainMenu > li:first').addClass('first');
	//attivo menu a tendina
	$('#mainMenu li').hoverIntent(config_menu);

	/*gestione altezza colonna laterale
	var hContent = $('#content').innerHeight();
	var hColumn  = $('#column').innerHeight();
	
	
	if (hContent > hColumn)
		$('#column').height(hContent);
	*/



$('.sconto_15').append('<img class="sconto" src="images/promotion/sconto_15.png" alt="sconto del 15%" title="sconto del 15%"/>');
$('.sconto_10').append('<img class="sconto" src="images/promotion/sconto_10.png" alt="sconto del 10%" title="sconto del 10%"/>');
$('.sconto_5').append('<img class="sconto" src="images/promotion/sconto_5.png" alt="sconto del 5%" title="sconto del 5%"/>');

$('.sconto_15min').append('<img class="scontomin" src="images/promotion/sconto_15.png" alt="sconto del 15%" title="sconto del 15%"/>');
$('.sconto_10min').append('<img class="scontomin" src="images/promotion/sconto_10.png" alt="sconto del 10%" title="sconto del 10%"/>');
$('.sconto_5min').append('<img class="scontomin" src="images/promotion/sconto_5.png" alt="sconto del 5%" title="sconto del 5%"/>');

$('#listaRicerca .item').hide();
$('#regione').change(function() {
  var corrente = $("select option:selected").attr('value');
  $('#listaRicerca .item').hide();
  if (corrente == 'tutti')
  	$('#listaRicerca .item').show();
	else
  $('.' + corrente).show();
});

$('#lCategorie').change(function() {
  var URL = $("select option:selected").attr('value');
  window.location = URL;
});



// aggiungo iun margine al secondo titolo in home
	$('#home #ev_titolo:eq(1)').css({'margin-top' : 25});

//poi nella pagina 

var last = getUrlVars()["categoria"];
if(last)
	$('.here,#titlePage').text(decodeURI(last));
	
});




	

