var curr_pos = 0;



function go_first() {

	$("#spot_content").animate({"left":"0px"},400,"swing");

	$(".nav").removeClass("active");

	$("#nav_1").addClass("active");

	$(".top_title, .top_cat").hide();

	$("#pos_1, #pos_cat_1").show();

	curr_pos = 0;	

}



function go_second() {

	$("#spot_content").animate({"left":"-976px"},400,"swing");

	$(".nav").removeClass("active");

	$("#nav_2").addClass("active");

	$(".top_title, .top_cat").hide();

	$("#pos_2, #pos_cat_2").show();

	curr_pos = -976;

}



function go_third() {

	$("#spot_content").animate({"left":"-1952px"},400,"swing");

	$(".nav").removeClass("active");

	$("#nav_3").addClass("active");

	$(".top_title, .top_cat").hide();

	$("#pos_3, #pos_cat_3").show();

	curr_pos = -1952;

}



function go_next() {

	if (curr_pos==0) { go_second(); return false; }

	if (curr_pos==-976) { go_third(); return false; }

	if (curr_pos==-1952) { go_first(); return false; }

}



function go_prev() {

	if (curr_pos==0) { go_third(); return false; }

	if (curr_pos==-976) { go_first(); return false; }

	if (curr_pos==-1952) { go_second(); return false; }

}



$(document).ready(function(){

						   

	var tempo = setInterval(function () { go_next() }, 11000);

	var isiPad = navigator.userAgent.match(/iPad/i) != null;

	var isiPod = navigator.userAgent.match(/iPod/i) != null;

	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

	

	if (isiPad||isiPod||isiPhone) {

	$("#spot_container").touchwipe({

     wipeLeft: function() { 

		 	go_next();

			clearInterval(tempo);

			tempo = setInterval(function () { go_next() }, 11000);

			},

     wipeRight: function() {

			 go_prev();

			 clearInterval(tempo);

			 tempo = setInterval(function () { go_next() }, 11000);

		 },

     min_move_x: 20,

     preventDefaultEvents: true

	});

	}



	$("#nav_1").click(function(event){

		event.preventDefault();

		go_first();

		clearInterval(tempo);

		tempo = setInterval(function () { go_next() }, 11000);

	});



	$("#nav_2").click(function(event){

		event.preventDefault();

		go_second();

		clearInterval(tempo);

		tempo = setInterval(function () { go_next() }, 11000);

	});



	$("#nav_3").click(function(event){

		event.preventDefault();

		go_third();

		clearInterval(tempo);

		tempo = setInterval(function () { go_next() }, 11000);

	});



	$(".cell a img").mouseover(function(event){

		$(this).parent().parent().css({"background-color":"#000"});

		$(this).parent().parent().find("a.reg_title").css({"color":"#ddd"});

	});

	

	$(".cell a img").mouseout(function(event){

		$(this).parent().parent().css({"background-color":"#fff"});

		$(this).parent().parent().find("a.reg_title").css({"color":"#333"});

	});

	

	$(".nav_categories_open").live('click', function(event) {

		event.preventDefault();

		$(this).removeClass("nav_categories_open").addClass("nav_categories_closed");

		$("#nav_categories").animate({"left":"299px"},260,"swing");

		$("#nav_contact").animate({"left":"409px"},260,"swing");

		$("#open_contact").addClass("nav_contact_closed").removeClass("nav_contact_open");

	});

	

	$(".nav_categories_closed").live('click', function(event) {

		event.preventDefault();

		$(this).removeClass("nav_categories_closed").addClass("nav_categories_open");

		$("#nav_categories").animate({"left":"29px"},260,"swing");

		$("#nav_contact").animate({"left":"409px"},260,"swing");

		$("#open_contact").addClass("nav_contact_closed").removeClass("nav_contact_open");

	});

	

	$(".nav_contact_open").live('click', function(event) {

		event.preventDefault();

		$(this).removeClass("nav_contact_open").addClass("nav_contact_closed");

		$("#nav_contact").animate({"left":"409px"},260,"swing");

		$("#nav_categories").animate({"left":"299px"},260,"swing");

		$("#open_categories").addClass("nav_categories_closed").removeClass("nav_categories_open");

	});

	

	$(".nav_contact_closed").live('click', function(event) {

		event.preventDefault();

		$(this).removeClass("nav_contact_closed").addClass("nav_contact_open");

		$("#nav_contact").animate({"left":"139px"},260,"swing");

		$("#nav_categories").animate({"left":"29px"},260,"swing");

		$("#open_categories").addClass("nav_categories_closed").removeClass("nav_categories_open");

	});



	$("#big_pic_container").mouseover(function(event){

		$("#striscia,#fitimg").show();

	});



	$("#big_pic_container").mouseleave(function(event){

		$("#striscia,#fitimg").hide();

	});



	$("#pix1").mouseover(function(event){

		$("#prev_pic").stop().show().animate({"left":"30px"});

	});



	$("#pix1").mouseout(function(event){

		$("#prev_pic").stop().hide().css({"left":"65px"});

	});



	$("#pix2").mouseover(function(event){

		$("#next_pic").stop().show().animate({"left":"886px"});

	});



	$("#pix2").mouseout(function(event){

		$("#next_pic").stop().hide().css({"left":"851px"});

	});

	

	$("#pix3").mouseover(function(event){

		$("#fit").stop().show();

		$("#fitimg").css({'opacity':'1'});

	});



	$("#pix3").mouseout(function(event){

		$("#fit").stop().hide();

		$("#fitimg").css({'opacity':'0.3'});

	});

	

	$("#facebook").mouseover(function(event){

		$("#facebook").css({"background-position":"left -20px"});

	});

	

	$("#facebook").mouseout(function(event){

		$("#facebook").css({"background-position":"left 0"});

	});

	

});
