$(function(){ 

	/* COOKIE */
	var cookieval = $.cookie("naba"); // LEGGO IL COOKIE	
	//alert(cookieval);
	
	if(cookieval && cookieval == "permanent" || permanent && permanent == "permanent" ) {
		$.cookie("naba","permanent"); 
	}
	else if(cookieval && cookieval == "smartphone") {		
		if(canale == 1){ window.location = "http://mobi.naba.it"; } // ITALIANO
		else{ window.location = "http://mobile.naba.it"; } // INGLESE
	}
	else if (cookieval != "web") {
		checkagent();
	}
	/* COOKIE */

	$("#menu li").bind({
		mouseover: function() {
			$(this).find(".menu-home-second").show();
		},
		mouseout: function() {
			$(this).find(".menu-home-second").hide();
		}
	})

	// PRELOAD IMMAGINI
	$.preloadCssImages();

	// GALLERIA
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({
		theme:'dark_rounded',
		autoplay_slideshow: false
	});
	
	// DATEPICKER	
	$('#datepicker').datepicker({
		regional: 'it',
		changeMonth: true,
		changeYear: true,
		yearRange: '1950:2010'
	});
	
	// CAMPO ALTRO NEI QUESTIONARI
	if( $('.select-altro option[value="19"]').is(':selected') ){
		$('.altro').show();
	};
	
	$('.select-altro').change(function(){
		if($('.select-altro option[value="19"]').is(':selected')){
			$('.altro').slideDown('normal');
			$('.input-altro').val('');
		}
		else {
			$('.altro').slideUp('normal');
			$('.input-altro').val('');
		}
	});		

});

/* COOKIE */
function checkagent() {
	var ua = navigator.userAgent;
	var checker = {
	  iphone: ua.match(/(iPhone|iPod|iPad)/),
	  blackberry: ua.match(/BlackBerry/),
	  android: ua.match(/Android/)
	};

	if ((checker.android) || (checker.blackberry) || (checker.iphone)) {
		if(canale == 1){ var question = confirm("Vuoi visualizzare la versione ottimizzata per Smartphone del nostro sito?"); }
		else{ var question = confirm("Would you like to view the Smartphone optimized version of our site?"); }
		
		if (question) {
			$.cookie("naba","smartphone"); // SETTO IL COOKIE A COOKIE DI SESSIONE NON SETTANDO LA DATA DI FINE ($.cookie("naba","smartphone", { expires: 100 });)
			if(canale == 1){ window.location = "http://mobi.naba.it"; } // ITALIANO
			else{ window.location = "http://mobile.naba.it"; } // INGLESE
		}
		else {
			$.cookie("naba", "web"); // SETTO IL COOKIE
		}
	}
}
/* COOKIE */

function menuHeader(menu) {
	var obj = "#"+menu;
	$(obj).bind({
	    mouseover: function() {
	        $(obj).attr("src","/contents/instance1/images/menu-header/"+menu+"-on.gif");
	    },
	    mouseout: function() {
	        $(obj).attr("src","/contents/instance1/images/menu-header/"+menu+"-off.gif");
	    }
	})
}

/* VIDEO PLAYER */
function video(contenitore,url,link_url,link_label,w,h,autoplay,videoimg) {

	var flashvars = {
		videoUrl: url,
		linkUrl: link_url,
		linkLabel: link_label,
		autoPlay: autoplay,
		videoImg: videoimg
	}
	
	var params = {
		allowfullscreen: "true",
		allowScriptAccess: "always",
		align: "middle",
		swliveconnect: "true",
		bgcolor: "#ffffff",
		wmode: "transparent"
	};
	
	var attributes = {
		id: contenitore,
		name: contenitore
	};
	
	swfobject.embedSWF(img_dir+'/video-player.swf', contenitore, w, h, '9.0.0', false, flashvars, params, attributes);
}

