$(document).ready(function(){
	//ricavo tutti i banner della pagina
	listaBanner = $(".imgBanners");
	for(i=0;i<listaBanner.length;i++){
		urlPhp = "dir=banner&file=upBanner&id=" + listaBanner[i].id;
		$.ajax({
			type: "GET",
			url: "../../blocchi.php?",
			data: urlPhp,
			success: function(msg){
				//alert(msg);
			}
		});
	}
	
	$(".cbox").colorbox();
	$('.cboxmappa').colorbox({iframe:true, innerWidth:925, innerHeight:600, opacity:0.7});
	$('.cboxblocchi').colorbox({iframe:true, innerWidth:925, innerHeight:600});
	
	$('#slider').nivoSlider({
		effect:'fade',
		pauseTime:3000
	});	
	
	//label over input
	$('.inp_shopper, .txt_shopper, .inp_newsletter').focus(function(){
		var nome_label = $(this).attr("name");
		$(this).prev().addClass("hidden");
	});
	
	$('.inp_shopper, .txt_shopper, .inp_newsletter').blur(function(){
		if($(this).val() == '')
			$(this).prev().removeClass("hidden");
	});
	
	$('label').click(function(){
		$(this).addClass("hidden");
		$(this).next().focus();
	});
	
	$("label").each(function() {
		if($(this).next().val()!="")
			$(this).addClass("hidden");
	});
	
	$("#hide-show").click(function(){
		stato = $(this).attr("class")
		
		if(stato == "button-hide"){
			$(this).addClass("button-show");
			$(this).removeClass("button-hide");
			$("#corpo_pagina").slideUp('slow');
			$("#img-up-dw").attr("src", "img/up.png");
		}
		
		if(stato == "button-show"){
			$(this).addClass("button-hide");
			$(this).removeClass("button-show");
			$("#corpo_pagina").slideDown('slow');
			$("#img-up-dw").attr("src", "img/down.png");
		}
	});
	
	$(function(){
		//Get our elements for faster access and set overlay width
		var div = $('div.sc_menu'),
					 ul = $('ul.sc_menu'),
					 // unordered list's left margin
					 ulPadding = 15;
	
		//Get menu width
		var divWidth = div.width();
	
		//Remove scrollbars
		div.css({overflow: 'hidden'});
	
		//Find last image container
		var lastLi = ul.find('li:last-child');
	
		//When user move mouse over menu
		div.mousemove(function(e){
	
		  //As images are loaded ul width increases,
		  //so we recalculate it each time
		  var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	
		  var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		  div.scrollLeft(left);
		});
	});

});
//funzione che incrementa il click di un
function clickBanner(idBanner){
	urlPhp = "dir=banner&file=upBanner&cp=click&id=" + idBanner;
	$.ajax({
		type: "GET",
		url: "../../blocchi.php?",
		data: urlPhp,
		success: function(msg){
			//alert(msg);
		}
	});
}
//funzione che incrementa il click di un
function ordineInAttesa(idOrd){
	urlPhp = "dir=ecommerce&file=_upOrdine&id=" + idOrd;
	$.ajax({
		type: "GET",
		url: "../../blocchi.php?",
		data: urlPhp,
		success: function(msg){
			//alert(msg);
		}
	});
}

function redir(url){
	window.location=url;
}

function updatecaptcha() {
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = '../../lib/captcha/immagine.php?' + Math.random();
}
