function mycarousel_initCallback(carousel) {
	jQuery('#mycarousel-next_1').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#mycarousel-prev_1').bind('click', function() {
		carousel.prev();
		return false;
	});

};

function mycarousel1_initCallback(carousel) {
	jQuery('#mycarousel-next_2').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#mycarousel-prev_2').bind('click', function() {
		carousel.prev();
		return false;
	});
};

function mycarousel3_initCallback(carousel) {
	jQuery('#mycarousel-next_3').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#mycarousel-prev_3').bind('click', function() {
		carousel.prev();
		return false;
	});
};

jQuery(document).ready(function() {
	
	jQuery("#mycarousel1").jcarousel({
		scroll: 1,
		initCallback: mycarousel_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	jQuery("#mycarousel2").jcarousel({
		scroll: 1,
		initCallback: mycarousel1_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	jQuery("#mycarousel3").jcarousel({
		scroll: 1,
		initCallback: mycarousel3_initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
});

	function setHomePage (url) {
		if (document.all) {
			document.body.style.behavior = 'url(#default#homepage)';
			document.body.setHomePage(url);
		}
		else if (window.sidebar) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e) {
				var strTemp = '';
				strTemp += "Permission denied";
				alert(strTemp);
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', url);
		}
	}
	
$(document).ready(function(){
	$(function() {  
	  $("#newslettersubmitajax").submit(function() {  
		 $.ajax({
		   type: "POST",
		   url: "/gonewsletter.php",
			data: $('#newslettersubmitajax').serialize(),
			success: function(msg){
			var result = msg.charAt(0);
			if (result == '0') {
				msg = msg.substring(1);
				//var message = $("#successmessage").html();
				$('#hiddennewslettermessage').html(msg);
			}
			else {
				var randomnumber=Math.floor(Math.random()*10000)
				$(".captchaimage").attr("src", "/newsletter_captcha.php?rand=".concat(randomnumber)); 
				$('#error_message').html(msg);
			}
		   }
		 });
		 return false;		  
		});  
	});  			
		
	var browserCheck = (document.all) ? 1 : 0; 
	if (!browserCheck) {
		$('#btli').hide();
		$('#btli_smap').hide();
	}
	$('#bookmarkthis').click(function () {
		setHomePage ('http://www.divertimento.it');
		return false;
	});

	$('a.vote').click(function () {
		$("#rate").toggle();
		return false;
	});
	$("a.share, a.share_icon").click(function () {
		$("#share").toggle();
		return false;
	});

		
	$('#top10 div').hide(); // Hide all divs
	   $('#top10 div:first').show(); // Show the first div
	   $('#top10 ul li:first').addClass('active'); // Set the class for active state
	   $('#top10 ul li a').click(function(){ // When link is clicked
		   $('#top10 ul li').removeClass('active'); // Remove active class from links
		   $(this).parent().addClass('active'); //Set parent of clicked link class to active
		   var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
		   $('#top10 div').hide(); // Hide all divs
		   $(currentTab).show(); // Show div with id equal to variable currentTab
		   return false;
	   });

});
$(function() {
	$(".jCarousel_lite").jCarouselLite({
		btnNext: ".jfNext",
		btnPrev: ".jfPrev",
		visible: 1,
		btnGo:
		[".imageSliderExt .1", ".imageSliderExt .2",
		".imageSliderExt .3", ".imageSliderExt .4"],
		auto: 10000
	});
});

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("main-menu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace
	(" over", "");
   }
   }
  }
 }
}
window.onload=startList;
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}


function voteConcorso(user, user_id, type, extra1, extra2, site_id, redirect_url)
{   
    var query = '?user_id=' + user_id + '&type=' + type + '&extra1=' + extra1 + '&extra2=' + extra2 + '&action=check&site_id=' + site_id;
    
    $.ajax({
		type: "GET",
		url: "/check_user_voted.php" + query,
		contentType: "application/json; charset=utf-8",
  	  	dataType: "json",
		success: function(msg){

				if (msg.result == false)
                {
                    if (!confirm("Hai selezionato " + user + ": confermi il tuo voto?")) {
                         return false;
                    }
                    
                    var query = '?user_id=' + user_id + '&type=' + type + '&extra1=' + extra1 + '&extra2=' + extra2 + '&action=vote&site_id=' + site_id;
                    
                    $.ajax({
	                   	type: "GET",
	                   	url: "/check_user_voted.php" + query,
		                contentType: "application/json; charset=utf-8",
  	                 	dataType: "json",
		                  success: function(msg){
				                    if (msg.result) { location.href = redirect_url;  }
		                  }
	                   });
                }else
                {
                    alert('Hai già espresso la tua preferenza, puoi votare una volta sola, grazie!');
                }
		}
	});
}