function setLang(lang)
{
	var url = baseurl+"setlang/"+lang;
	$.post(url, { content: content }, function(data) {document.location = data});
}

// Manage submenus on main menu
function openSubMenu(menuId)
{
	if ($("#"+menuId).length > 0)
	{
		$("#"+menuId).show();
		$("#"+menuId).mouseout(function() {if($(this).hasClass('alwaysopen')!=1) {$(this).hide();}});
	}
}

// Manage submenus on navigator menu (left)
function subnav(id)
{
	if ($("#"+id).is(":visible")) 	$("#"+id).hide();
	else
	{
		classname = $("#"+id).attr("class");
		$("."+classname).hide();
		// Hide all subnav opened
		$("#"+id).show();
	}
}

// Mark as selected all parents of a child
function selectParentNav(id)
{
	el = $("#navigation .selected");
	subnav("sub"+$(el).attr("id"));
	while ($(el).parent().parent("LI").length > 0)
	{
		$(el).parent().parent("LI").addClass("selected");
		el = $(el).parent().parent("LI");
		subnav("sub"+$(el).attr("id"));
	}
}

// Slide open and close navigator
function toggleNav()
{/*
	if ($("#navigation .main").is(":visible"))
	{
		$("#navigation .main").hide("slow");
		$("DIV#navigator").addClass("to-close").removeClass("to-open");
	}
	else
	{
		$("#navigation .main").show("slow");
		$("DIV#navigator").removeClass("to-close").addClass("to-open");
	}*/
}

// Recall myAxolute flash function
function sendMyAxolute(params, link)
{
	str="";
	
	/* DEBUG
	for (var paramname in params) 
	{  
		str += paramname + ' : ' + params[paramname] + '\n';
	}
	alert(str);
	*/
	
	var len = 250;
	var trunc = params["desc"];
	if (trunc.length > len)
	{
		trunc = trunc.substring(0, len);
		trunc = trunc.replace(/\w+$/, '');
		trunc += '...';
		params["desc"] = trunc;
	}
	params["desc"] = params["desc"].replace(/^\s+|\s+$/g,"");
	var flashMovie=getFlashMovieObject("myAxolute");
	flashMovie.savingParameters(params["line"], params["category"], params["title"], params["desc"], params["preview"], params["img"], params["url"]);
	$(link).parent().html("<span>"+label_myaxolutesaved+"</span>");
}

//Recall myAxolute flash function
function sendMyAxoluteFlash(link)
{
	activateMyAxolute(false);
	$(link).parent().siblings(".myAxoluteSaved").show().delay(2000).fadeOut('slow'); ;
	var flashMovie=getFlashMovieObject("visore0");
	flashMovie.saveItem();
}

//Recall myAxolute flash function
function sendMyAxoluteFlashVivi(link)
{
	activateMyAxolute(false);
	var flashMovie=getFlashMovieObject("visore0");
	flashMovie.saveItem();
}

// Show/Hide add to my axolute button (called by flash)
function activateMyAxolute(show)
{
	if(show) {$(".myAxoluteSaved").hide(); $(".myAxolute").show();$("#myAxoluteInfo").hide();}
	else	 $(".myAxolute").hide();
}

//Show/Hide add to my axolute button (called by flash)
function activateMyAxoluteVivi(show)
{
	if (show) {$(".myAxoluteSaved").hide(); $(".myAxolute").show();$("#myAxoluteInfo").hide();}
	else	  $(".myAxolute").hide();
}

// Return item link (called by flash)
function schedaMyAxolute(show)
{
	return "";
}

function getFlashMovieObject(movieName)
{
    if (window.document[movieName])
    	return window.document[movieName];
    if (navigator.appName.indexOf("Microsoft Internet")==-1) 
    	if (document.embeds && document.embeds[movieName])
        	return document.embeds[movieName];
    else
    	return document.getElementById(movieName);
}

function createMenuSelector()
{
	$("#menu").append('<div id="selected" class="fixpng"></div>');
	// Check position of the selected element
	if($("#menu .selected").length>0) $("#menu #selected").css("left", ($("#menu .selected").position().left + ($("#menu .selected").outerWidth()/2) - 75) + "px");
	$("#menu LI").hover( function() {$("#menu #selected").animate({left: (($(this).position().left + $(this).outerWidth()/2) - 75) }, 50);} );
}

function sendMail() {
	error_mail = false;
	
	var nome = $('#nome').attr('value'); 
	var cognome = $('#cognome').attr('value'); 
	var email = $('#email').attr('value'); 
	var oggetto = $('#oggetto').attr('value'); 
	var msg = $('#msg').attr('value'); 
	
	$('.error').html('');
	
	if(nome=="") appendError(requiredLabel, 'error-nome');
	if(cognome=="") appendError(requiredLabel, 'error-cognome');
	if(email=="") appendError(requiredLabel, 'error-email');
	if(oggetto=="") appendError(requiredLabel, 'error-oggetto');
	if(msg=="") appendError(requiredLabel, 'error-msg');

	var isemail = /^[_a-z0-9-]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$/.test(email);
	if(email!="" && !isemail) appendError(errorLabel, 'error-email');
	
	if(!error_mail) {
		$.post(url, { 
			nome: nome, 
			cognome: cognome, 
			email: email, 
			oggetto: oggetto,
			msg: msg,
			ajax: 1
		},
		function(data){
			if(data.indexOf('OK')>-1) showConfirmMsg();
			else appendError("Invio messaggio fallito!", 1);
			return false;
			});
	}

	return false;
}

function appendError(err, field)
{
	if (field != 1) {$('#'+field).html('&rarr; '+err);}
	error_mail = true;
}

function showConfirmMsg()
{
	$('#ok_msg').show();
	$('#intro_msg').hide();
	$('#body_msg').hide();
	$('#first-cnt').hide();
	$('#second-cnt').hide();
	$('#error-box').hide();
}

function popup(page)
{
	if ($("#popup").length == 0)
	{
		$("body").append("<div id=\"popup\"></div>");
		$("#popup").dialog({ autoOpen:false, height:388, width:418, position:['center',280], modal: true, overlay: { backgroundColor: "#FFF", opacity: 0.7 } });
	}
	$("#popup").load(page, function() {
		$("#popup").append("<div class=\"close\">chiudi</div>");
		$("#popup .close").click(function() {$("#popup").dialog("close");});
		$("#popup").dialog("open");
	});
}

Cufon.replace('#menu LI');
Cufon.replace('#navigator .din');

$(document).ready(function() {
	if ($.browser.msie)
		$(".myAxolute A").mouseover(function() {$("#myAxoluteInfo").show();}).mouseout(function() {$("#myAxoluteInfo").hide();});
	else
	{
		$(".myAxolute A").mouseover(function() {$("#myAxoluteInfo").fadeIn("slow");}).mouseout(function() {$("#myAxoluteInfo").fadeOut("slow");});
		$("#pagination .disabled").css({ opacity: 0.5 });
	}
});


