$(document).ready(function() {
	// initialize scrollable together with the autoscroll plugin
	if($('#scroller div.items div.imgteaser img').length > 1) {
		$("#scroller").scrollable({circular: true, mousewheel: true}).navigator().autoscroll({
			interval: 3000
		});
	} else {
		$('a.prev').hide();
		$('a.next').hide();
	}


	$("#bg1").css('background-image', 'url(images/sfondo_03.jpg)');
	$("#bg2").css('background-image', 'url(images/sfondo_05.jpg)');

	if ($(window).width()<'1010'){
		$("#bg1").css('background-position','-300px 0');
		$("#bg2").css('background-position','-300px 0');
	}
	else if ($(window).width()<'1290'){
		$("#bg1").css('background-position','-172px 0');
		$("#bg2").css('background-position','-172px 0');
	}
	else {
		$("#bg1").css('background-position','top center');
		$("#bg2").css('background-position','top center');
	}

	//alert($("#mainContent").height());
	if ($("#mainContent").height()<=738) {
		$("#mainContent").height(738);
	}else {
		$("#bg1").css('background-image', 'url(images/sfondo_04.jpg)');
		if ($('#bghome').height()==null)
		{
			if ($(window).width()<'1010'){
					$("#bg1").css('background-position','-300px 0');
					$("#bg2").css('background-position','-300px 0');
				}
				else if ($(window).width()<'1290'){
					$("#bg1").css('background-position','-172px 0');
					$("#bg2").css('background-position','-172px 0');
				}
				else {
					$("#bg1").css('background-position','top center');
					$("#bg2").css('background-position','top center');
				}
			$("#mainContent").height(1258);
			$("#mainContent").css("overflow","hidden");	// oltre quest'altezza taglia perche' lo sfondo diventa bianco
		}
	}


	$("#invia").click(function (e) { e.preventDefault(); $(this).parents("form").submit(); });
	$("#invia").mouseover(function () {
		var src1= $("#invia").attr('src'); // initial src
		$("#invia").attr('src', 'images/invia_on.' + /[^.]+$/.exec(src1)); //last part is for extension
	});
	$("#invia").mouseout(function () {
		var src1= $("#invia").attr('src'); // initial src
		$("#invia").attr('src', 'images/invia.' + /[^.]+$/.exec(src1)); //last part is for extension
	});
	$("#search").mouseover(function () {
		var src1= $("#search").attr('src'); // initial src
		$("#search").attr('src', 'images/search_on.' + /[^.]+$/.exec(src1)); //last part is for extension
	});
	$("#search").mouseout(function () {
		var src1= $("#search").attr('src'); // initial src
		$("#search").attr('src', 'images/search.' + /[^.]+$/.exec(src1)); //last part is for extension
	});
	$('#search').parent().click( function (e) {
		e.preventDefault();
		document.location.href="filiali.php?filtro=" + ($("#filtro_10").attr("checked") ? "1" : "0" ) + ($("#filtro_01").attr("checked") ? "1" : "0" );
	});


	//Set default open/close settings
	$('.acc_container').hide(); //Hide/close all containers
	$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
			var id =$(this).attr("title");
			$("#img").load("common/ajax.caricaimg.php?id="+id, function() {
				if($('#scroller div.items div.imgteaser img').length > 1) {
					$("#scroller").scrollable({circular: true, mousewheel: true}).navigator().autoscroll({
						interval: 3000
					});
				} else {
					$('a.prev').hide();
					$('a.next').hide();
				}
			})

		}
		return false;
	});

	// per check dati di rete smallnet
	$('#smallnetcheck_button').click( function(e) {
		e.preventDefault();
		$('#smallnetcheck').hide();
		$('#risposta').show().html("carico...");
		$.ajax({'type' : 'POST','url' : "common/ajax.smallnet.php",
			'data' : {	'de_codcli' : $('#de_codcli').val(),
				'de_nome' : $('#de_nome').val(),
				'de_cognome' : $('#de_cognome').val() },
			'success' : function( $response ) { 
				if ($response) { 
					//...
					$('#risposta').html($response + "<a href='#' id='back'>&laquo; indietro</a>");
					setTimeout(function () {
						$('#back').click(function(e) {
							e.preventDefault();
							$('#risposta').hide();
							$('#smallnetcheck').show();
						});
					}, 500);
				 } },
			'error' : function () { alert("errore"); }
		});

	});


	$('#showcodcli').click(function(e) { e.preventDefault(); $('#normal').fadeOut("fast",function() { $('#special').show(); }); } ); 
	$('#hidecodcli').click(function(e) { e.preventDefault(); $('#special').fadeOut("fast",function() { $('#normal').show(); }); } ); 


});

function showSponsor(obj) {
	$('#sponsor .prodotti').load("common/ajax.sponsorizzazioni.php?anno="+$(obj).val());
}


