$(document).ready(function(){
    if(self!=top)top.location=self.location;
    //$(".menusez p:not(.activelink)").hide();
    $("li.menusez h3:not(.sezcorr)").prepend("<span class=\"rettangolo\">&nbsp;</span>");
    $("li.menusez h3.sezcorr").prepend("<span class=\"rettangolo rettangoloattivo\">&nbsp;</span>");
    $("li.subvoce:not(.subezcorr) a").prepend("<span class=\"minirett\"></span>");
    $("li.subvoce.subezcorr a").prepend("<span class=\"minirett minirettattivo\"></span>");
    //$("li.menusez h3:not(.voceattiva) span.rettaperto").hide();
	$("li.menusez h3.voceattiva span.rettangolo").animate({width:'40px'}, 250);
    //$("li.menusez h3.voceattiva span.rettangolo").hide();
    $("li.menusez.multi h3:not(.voceattiva)").siblings("ul").hide();
    /*$("li.menusez.multi").click(function(){
	  $(this).children("ul.subsez").slideToggle(250).parent().siblings("li").children("ul.subsez:visible").slideUp(250);
	  $(this).children("h3").toggleClass("voceattiva");
	  $(this).children("ul").toggleClass("sezattiva");
	  $(this).siblings("li").children("h3").removeClass("voceattiva");
	  $(this).siblings("li").children("ul").removeClass("sezattiva");
	  $("li.menusez h3.voceattiva span.rettangolo").animate({width:'40px'}, 250);
	  $("li.menusez h3:not(.voceattiva) span.rettangolo").animate({width:'20px'}, 250);

	});*/
    $("li.menusez.singolo h3").click(function(event){
        window.location =$(this).children("a").attr('href');
	});
    $("li.subvoce").click(function(event){
        window.location =$(this).children("a").attr('href');
	});
    $("li.menusez.multi h3").click(function(event){
      var c=$(this).parent();
      clickmenu(c,event);
	});
    $("li.menusez.multi h3 span.rettangolo").click(function(event){
      var c=$(this).parent().parent();
      clickmenu(c,event);
	});
    function clickmenu(c,event){
	  c.children("ul.subsez").slideToggle(250,"easeInOutSine").parent().siblings("li").children("ul.subsez:visible").slideUp(250,"easeInOutSine");
	  c.children("h3").toggleClass("voceattiva");
	  c.children("ul").toggleClass("sezattiva");
	  c.siblings("li").children("h3").removeClass("voceattiva");
	  c.siblings("li").children("ul").removeClass("sezattiva");
	  $("li.menusez h3.voceattiva span.rettangolo").animate({width:'40px'}, 250);
	  $("li.menusez h3:not(.voceattiva) span.rettangolo").animate({width:'20px'}, 250);
      event.stopPropagation();
	};
    function mover(c,event){
    	c.animate({ paddingRight: '5px'}, 150);//,fontSize:'13px'
    	c.css("color","#a70038");
    	c.siblings("span.rettangolo").animate({paddingRight: '5px',backgroundColor: "#a70038"}, 150);
    	c.children("span.minirett").animate({paddingRight: '5px',backgroundColor: "#a70038"}, 150);
	};
    function mout(c,event){
    	c.animate({paddingRight: '0'}, 150);
    	c.parent("li.subvoce:not(.subezcorr)").children("a").css("color","#000000");
    	c.parent("h3:not(.sezcorr)").children("a").css("color","#000000");
    	c.siblings("span.rettangolo.rettangoloattivo").animate({paddingRight: '0'}, 150);
    	c.siblings("span.rettangolo:not(.rettangoloattivo)").animate({paddingRight: '0',backgroundColor: "#b0b0b0"}, 150);
    	c.children("span.minirett.minirettattivo").animate({paddingRight: '0'}, 150);
    	c.children("span.minirett:not(.minirettattivo)").animate({paddingRight: '0',backgroundColor: "#b0b0b0"}, 150);
	};
    $("li.menusez h3").hover(
		function(event){mover($(this).children("a"),event)},function(event){mout($(this).children("a"),event)}
    );
    $("li.subvoce").hover(
		function(event){mover($(this).children("a"),event)},function(event){mout($(this).children("a"),event)}
    );
    $("a.nolink").click(function(event) {
        event.preventDefault();
    });
    $("a[href*=#]").click(function(event) {
        //alert($(this).attr('href').split('#')[1]);
        nome=$(this).attr('href').split('#')[1];
        vai_a_ogg($("a[name='"+nome+"']"))
        //vai_a_ogg($("a[name='up']"))
        /*
        $("html,body").animate({scrollTop: $("a[name='up']").offset().top},"slow",function(){});
        */
        event.preventDefault();
    });
    $('a[rel*=external],a[href^=http]').click( function() {
        var href=$(this).attr('href');
        var serv=href.split('.')[1];
        if(serv=="fiatcamper"){
            location.href=href;
        }else{
            window.open(href);
        }
        return false;
    });
    $('.slide').cycle({
        fx:'fade',
        continuous:0,
        speed:1000,
        timeout:5000
    });
    try{auxload()}catch(e){};
});
function vai_a_ogg(ogg){
    var animSpeed=1500; //animation speed
    var easeType="easeInOutQuart"; //easing type
    if($(ogg).offset()){
        if($.browser.webkit){ //webkit browsers do not support animate-html
            $("body").stop().animate({scrollTop: $(ogg).offset().top}, animSpeed, easeType);
        } else {
            $("html").stop().animate({scrollTop: $(ogg).offset().top}, animSpeed, easeType);
        }
    }
};
function vai_a_id(id2Animate){
    vai_a_ogg($(id2Animate));
};
function popup(url,nome,w,h,r){
    var l=(screen.width-w)/2;
    var t=(screen.height-h)/2;
    var ogg=window.open(url,nome,'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars=1,resizable='+r+',menubar=0,toolbar=0,location=0,statusbar=1');
    try{ogg.window.focus()}catch(e){};
}
 function utf8decode(utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while ( i < utftext.length ) {

    	c = utftext.charCodeAt(i);

    	if (c < 128) {
    		string += String.fromCharCode(c);
    		i++;
    	}
    	else if((c > 191) && (c < 224)) {
    		c2 = utftext.charCodeAt(i+1);
    		string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    		i += 2;
    	}
    	else {
    		c2 = utftext.charCodeAt(i+1);
    		c3 = utftext.charCodeAt(i+2);
    		string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
    		i += 3;
    	}

    }

    return string;
}
function id2obj(id){
	return document.all?document.all[id]:document.getElementById?document.getElementById(id):undefined;
}
function recordOutboundLink(link, category, action) {
  try {
    var pageTracker=_gat._getTracker("UA-3674647-4");
    pageTracker._trackEvent(category, action);
    //setTimeout('document.location = "' + link.href + '"', 200);
    return false;
  }catch(err){}
}
