var aSpot = 0;
var nSpot =0;
$(function() {
		
	// Homepage
    $('#slider').nivoSlider({
        effect:'random', // Specify sets like: 'fold,fade,sliceDown'h
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:3000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:false, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: hideSpot, // Triggers before a slide transition
        afterChange: changeSpot, // Triggers after a slide transition
        slideshowEnd: function () {}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
	
	var h = $('#primary').height();
	var h2 = $('#main').height() + 100;
	if (h < h2) {
		$('#primary').height( $('#main').height() + 100);
	}
	
	nSpot = $('.linkSpot').size();
	$('.linkSpot').hide();
	$('.linkSpot').eq(0).show();
	
	// Calcolo delle date
	t = setInterval(coutndown , 1000);
        
        // rating        
        $(".star").each(function (i) {
            
           var $me = $(this);
           $me.bind("click" , function () {
               var voto = $(this).index();
               voto == 0 ? voto = 1: "";               
               $("#rating").val((voto-1));
               
               for (var t=0;t<5;t++) {
                   if (t<(voto-1))
                       $(".star:eq("+t+")").css("background","transparent url(/wp-content/themes/parkhotelgrilli/images/stars24.png)  0px -24px no-repeat");  
                   else
                       $(".star:eq("+t+")").css("background","transparent url(/wp-content/themes/parkhotelgrilli/images/stars24.png)  0px 0px no-repeat");  

               }
               
               
           })
        
        })
           

	
});

function coutndown() {
	
	$(".scadenza").each(function (i) {
		
		var d=new Date();
		var t=d.getTime();
		var ss= $(this).attr("data-scadenza").split(",");
		var s = new Date(ss[0],ss[1]-1,ss[2],ss[3],ss[4],ss[5]);
		var st = s.getTime();
		var differenza = s - t;
		
		var stext =""
		if (differenza < 0) {
			
			if (!$(this).hasClass("privato")) {
				$(this).text(l["scaduta"]);
				$(this).parent().hide();
				$(this).addClass("privato"); 
				$.post("/cgstatus.php", { id: $(this).attr("id")})
				.success(function (data) { alert(data) });			
			}
			
		} else {
			x = differenza / 1000;
			seconds = Math.floor(x % 60);
			x /= 60;
			minutes = Math.floor(x % 60);
			x /= 60;
			hours = Math.floor(x % 24);
			x /= 24;
			days = Math.floor(x);
			
			var stext = days + " " + l["giorni"]+ ", " + hours + " " + l["ore"]+ ", " + minutes + " " + l["minuti"]+ ", " + seconds + " "+ l["secondi"];
			$(this).children("span.val-scadenza").text(stext);
		}
		
		
		
	});
}

function hideSpot() {
	$('.linkSpot').eq(aSpot).hide('slow')
}
function changeSpot() {
	aSpot++;
	if (aSpot == nSpot) {
		aSpot = 0;
	}
	$('.linkSpot').eq(aSpot).show('slow');
}


