$(document).ready(function () {
	
	$("a").bind("focus",function(){
			if(this.blur)this.blur();
	});
	
	if ($.cookie('activeSection') != null) {
		var activeSection = $.cookie('activeSection');
		var sel = $("#"+activeSection).attr("class");
			sel = $.trim(sel);
			//alert(activeSection+" "+sel);
		if(sel !="first selected"){
				$("#"+activeSection).addClass("first selected");				
			}
		
		}
	
	$("a").not($("#mainmenu a, .menuSection a")).click(function () {
        $.cookie('activeSection', null, {path: '/'});
    });
	
	$("#mainmenu a").click(function() {
		var idSezione = $(this).parent().parent().attr("id");
		idSezione = $.trim(idSezione);
		//alert(idSezione);
		if ($.cookie('activeSection') != idSezione){
			//$.cookie('activeSection', null);
			$.cookie('activeSection', idSezione, {path: '/'});
			//alert("in "+idSezione);
			var selected = $("#"+idSezione).attr("class");
			selected = $.trim(selected);
			if(selected !="first selected"){
				$("#"+idSezione).addClass("first selected");
				$("#"+idSezione).parent().find("li").not($("#"+idSezione)).removeClass("first selected");				
			}
		}
    });
	
	/*menu accordion*/
	$.ui.accordion.animations.peoples = function(options) {
	this.slide(options, {
		duration: options.down ? 1000 : 500
	});
 };


$('#menuPoker').accordion({ 
    active: false, 
    header: 'h3.mnuTitle',
	alwaysOpen: false,
    navigation: true,
	/*clearStyle: true,*/
	/*animated:'jswing',*/
	animated: "peoples",
   	autoHeight: false
 
});	
	
    $("a").each(function () {
        if (this.href.indexOf(".pdf") > -1)
            $(this).attr("rel", "popup");
    });
    
    $("a[rel=popup]").click(function() {
        var sUrl = this.href;
        
        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else {
            setTimeout(sUrl.replace("javascript:", ""), 0);
        }
            
        return false;
    });
    
    $("a[rel=popup]").bind("onkeydown", function() {
        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else
            setTimeout(sUrl, 0);
        
        return false;
    });
    
    if ($.browser.ie != true) {
        $("img[hspace]").each(function () {
            $(this).css("margin-left", $(this).attr("hspace") + "px");
            $(this).css("margin-right", $(this).attr("hspace") + "px");
            $(this).css("margin-top", $(this).attr("vspace") + "px");
            $(this).css("margin-bottom", $(this).attr("vspace") + "px");
        });
    }
    
    var l = 990;
    var i = $("div#mainmenu ul li").length;
    $("div#mainmenu ul li").css("width", parseInt(l / i) - 1 + "px");
    
    // Bug IE 6 : boh??
    $("div div.right").css("width", $("div div.right").css("width"));
});

//###########################
// Funzione menù a tendina #
//#########################

/*function showhide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		if (obj.style.display == "none"){
			obj.style.display = "";
		} else {
			obj.style.display = "none";
		}
	}
}
function show(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		obj.style.display = "";
	}
}
function hide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		obj.style.display = "none";
	}
}
function menu_poker_gruppo1() {
	show('items_gruppo1');
	hide('items_gruppo2');
	hide('items_gruppo3');
}
function menu_poker_gruppo2() {
	hide('items_gruppo1');
	show('items_gruppo2');
	hide('items_gruppo3');
}
function menu_poker_gruppo3() {
	hide('items_gruppo1');
	hide('items_gruppo2');
	show('items_gruppo3');
}*/


//################################
// Fine Funzione menù a tendina #
//##############################

