﻿$(document).ready(function(){  
	$('#footer a:not(.info), .accetto a').colorbox({width:"600px", height:"500px", iframe:true });
	$('a.sfoglia').colorbox({width:"990px", height:"600px", iframe:true });
	$('.info').colorbox({width:"500px", height:"350px", iframe:true });	
	$('a.lb, .galContent a').colorbox();
	$("a.blank").click( function() { $(this).attr("target", "_blank") });
	
	
	
	/* newsletter */
	$("#newsletter>p>a").click( function() {
		$("#newsletter").toggleClass("open");
		return false;
	});
	$("#newsletterForm .invia a").click( function() { 
		$("#newsletterForm").find("input[type=submit]").click();
		return false;
	});
	$("#newsletterForm").validate({
		rules: {
			nomenl: { required: true },
			cognomenl: { required: true },
			mailnl: { email: true, required: true },	
			accettonl: { required: true }
		},
		messages: {
		    nomenl: "",
		    cognomenl: "",
		    mailnl: "",
		    accettonl: ""
		},
		submitHandler: function (form) {
			PostNewsletterRequest();
		}
	});
	/* !newsletter */
	
	
	
	
	/* slideshow */
	if( $("#slideshow li").length > 1 ) {
		intervalId = setInterval( "slideSwitch()", 5000 );
		$("#slideshow li").each( function() {
			$("#slidePaging").append("<a href='#'>&nbsp;</a>")
		});
		$("#slidePaging a:eq("+ $("#slideshow li.active").index("#slideshow li") +")").addClass("sel");
		$("#slidePaging a").live( "click", function() {
			$("#slidePaging .sel").removeClass();
			$(this).addClass("sel");
			var x = $(this).index("#slidePaging a");
			slideSwitchTo(x);
			window.clearInterval(intervalId);
			intervalId = setInterval("slideSwitch()", 5000);
			return false;
		});
		
		
		if ($(".miniGallery").length != 0) {
			$(".miniGallery a").click(function() { return false })
			$(".miniGallery img:not(.sel)").live("mouseover", function() {
				$(".miniGallery img.sel").removeClass("sel");
				$(this).addClass("sel");
				var x = $(this).index(".miniGallery img");
				slideSwitchTo(x+1);
				window.clearInterval(intervalId);
				return false;
			});
			$(".miniGallery img.sel").live("mouseover", function() {
				window.clearInterval(intervalId);
			})
			$(".miniGallery img").live("mouseout", function() {
				window.clearInterval(intervalId);
				intervalId = setInterval("slideSwitch()", 5000);
			});
		}
	}
	/* !slideshow */
	
	/* altmenu */
	$("#altMenu>li").hover( function() {
		$(this).addClass("over");
		if( $("#perizzi.home").length != 0 )
			$(this).find(".submenu").stop().animate({height:'65px'},{queue:false, duration:500})		
		else 
			$(this).find(".submenu").stop().animate({height:'35px'},{queue:false, duration:500})
	}, function() {
		$(this).removeClass("over");
		$(this).find(".submenu").stop().animate({height:'0px'},{queue:false, duration:500})
	});
	
	$("#altMenu>li.e1>a, #altMenu>li.e4>a").click( function() { return false; });
	
	/* !altmenu */
	
	/* boxlinked */
	$("#page .box, #page .boxC.linked, #news .wrap>div ").click( function() {
		var url = $(this).find("a").attr("href");
		window.location=url;
	});
	$("#page .box, #page .boxC.linked, #news .wrap>div").hover(function() { $(this).addClass("over") }, function() { $(this).removeClass("over") });
	/* !boxlinked */
	
	/* storia img */
	if ($(".storia").length != 0) {
		var z = 10;
		$(".storia span").hover( function() {
			$(this).find(".big").remove();
			var img = new Image();
			var url = $(this).find("a").attr("href");
			$(img).attr('src', url).addClass("big");
			$(this).css("z-index",z);
			$(this).append(img)
			$(this).find(".big").css("opacity", 0).animate(
				{ opacity: 1 }, // what we are animating
				{
					duration: 3000,
					easing: 'easeOutBack',
					complete: function() { }
				});
		}, function() {
			$(this).find(".big").stop().fadeOut("slow", function() { $(this).remove() });
			z = z +1;
		});
		$(".storia span a").click(function() { return false; });
	};
	/* !storia img */
	
	/* grandi navi img */
	if ($(".mdgn").length != 0) {
		var z = 10;
		$(".mdgn .foto").hover( function() {
			$(this).find(".big").remove();
			var img = new Image();
			var url = $(this).find("a").attr("href");
			$(img).attr('src', url).addClass("big");
			$(this).css("z-index",z);
			$(this).append(img)
			$(this).find(".big").css("opacity", 0).animate(
				{ opacity: 1 }, // what we are animating
				{
					duration: 3000,
					easing: 'easeOutBack',
					complete: function() { }
				});
		}, function() {
			$(this).find(".big").stop().fadeOut("slow", function() { $(this).remove() });
			z = z +1;
		});
		$(".mdgn .foto a").click(function() { return false; });
	};
	/* !grandi navi img */
	
	/* home img */
	if ($(".homeDiv").length != 0) {
		var z = 10;
		$(".homeDiv .foto").hover( function() {
			$(this).find(".big").remove();
			var img = new Image();
			var url = $(this).find("a").attr("href");
			$(img).attr('src', url).addClass("big");
			$(this).css("z-index",z);
			$(this).append(img)
			$(this).find(".big").css("opacity", 0).animate(
				{ opacity: 1 }, // what we are animating
				{
					duration: 3000,
					easing: 'easeOutBack',
					complete: function() { }
				});
		}, function() {
			$(this).find(".big").stop().fadeOut("slow", function() { $(this).remove() });
			z = z +1;
		});
		$(".homeDiv .foto a").click(function() { return false; });
	};
	/* !home img */
	
	/* spaziocucina h1*/
	if( $(".topCucina").length != 0 ) {
		$(".topCucina h1").hover( function() {
			$(this).addClass("over").find(".tool").stop().animate({"height":"21px"});
		}, function() {
			$(this).removeClass("over").find(".tool").stop().animate({"height":"0px"});	
		});
	}
	
	/* !spaziocucina h1*/
	
	/* gal menu */
	if( $(".galleryTop").length !=0 ) {
		$(".galleryTop li a").hover( function() {
			$(this).closest("li").addClass("over");									  
		}, function() {
			$(this).closest("li").removeClass("over");					
		});
	}
	/* !gal menu */
	
	
});


function slideSwitch() {
    var $active = $('#slideshow li.active');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow li:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
			$("#slidePaging a.sel").removeClass();
			$("#slidePaging a:eq("+$("#slideshow li.active").index("#slideshow li")+")").addClass("sel");
        });
}

function slideSwitchTo(x) {
    var $active = $('#slideshow li.active');
    var $next =  $('#slideshow li:eq('+x+')');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
			$("#slidePaging a.sel").removeClass();
			$("#slidePaging a:eq("+$("#slideshow li.active").index("#slideshow li")+")").addClass("sel");
		});
		
	
}


