var path_assoluto;
function init(){
	menu();	
	my_accordion();
	/* VIRTUAL EXPLORE */
		delay=9000;
		virtual_explore(delay);
	/*-------------------------*/
	//active_gallery();
}

/* Funzione per Menù 
- - - - - - - - - - - - - - - - - - - - */
function menu(){
	$("#menu_vert_3lev a.active").parent().parent().addClass("on");
	$("#menu_vert_3lev ul li ul").not(".on").hide();
	$("#menu_vert_3lev ul li a").click(function(){
		if($(this).attr("href")=="#"){
			if ($(this).next().attr("class") == "on") {
//				$(this).next().removeClass("on").slideUp("fast");
				// scriverlo due volte per trovare gli elementi successivi con classe .on
				$(this).parent().children().not("a").removeClass("on").slideUp("fast"); 
			} else {
				$(this).parent().parent().find("ul.on").removeClass("on").slideUp("fast");
				$(this).parent().children().not("a").addClass("on").slideDown("normal");
//				$(this).next().addClass("on").slideDown("fast");
//				$(this).next().next().addClass("on").slideDown("fast"); // serve per aprire l'UL fratello
			}
			return false;
		}
	});
	apriMenu();
	$("img[@src='']").src='/img/trasp.gif';

	
}
function apriMenu(){
	$("#menu_vert_3lev a.on").each(function(){
		var el=this;
		var conta=0;
		while(el !== null && conta<30){
			el=$(el).parent();
			if(el[0].tagName=="UL"){
//				$(el).show();
//				$(el).addClass("on");
				$(el).parent().children().not("a").show();
				$(el).parent().children().addClass("on");
				
			}else if (el[0].tagName=="LI"){
				conta++;
			}else if (el[0].tagName=="DIV"){
				el=null;
			}else{
				conta++;
			}
		}
	});
}
function active_gallery(){
	if (!$("#TB_Window").length && typeof(tb_init)=='function'){
//		imgLoader = new Image();// preload image
		//imgLoader.src = "/img/trasp.gif";
//		imgLoader.src = tb_pathToImage;
		tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
//		$("#TB_Image").load(function(){ $("#TB_Load").hide();alert("caricata"); });
		
	}
}

/*function my_accordion(){
	$("h2 a[@rel='accordion']").click(function(){
		var thed=$(this).parent().next();
		$(".hidden:visible").not($(thed)).slideUp("fast");
		$(this).parent().next().slideDown("fast");
		return false;
	});
}
*/

/* Funzione per Menù 
- - - - - - - - - - - - - - - - - - - - */
/*_____________________ menu da robopac*/
function my_accordion(){
	$("h2 a[@rel='accordion']").click(function(){
		var thed=$(this).parent().next();
		$(".hidden:visible").not($(thed)).slideUp("fast");
		$(this).parent().next().slideDown("fast");
		$("h2 a[@rel='accordion_ex']").each(function(){this.my_state='collapsed';});
		return false;
	});
	$("h2 a[@rel='accordion_ex']").each(function(){this.my_state=null; });
	$("h2 a[@rel='accordion_ex']").click(function(){
			if(this.my_state=='collapsed'){
				$("#cont_blocchetti .hidden:hidden").slideDown("normal"); //slideDown
				this.my_state='expanded';
			}else if(this.my_state=='expanded'){
				$("#cont_blocchetti .hidden:visible").slideUp("normal");// slideUp
				this.my_state='collapsed';
			}else{
				$("#cont_blocchetti .hidden:hidden").slideDown("normal"); //slideDown
				this.my_state='expanded';				
			}
			/*
			if ($(this).html()=="-") {
				$(this).html("+");
			}else{
				$(this).html("-");
			}
			*/
			return false;
		});
	$("#cont_blocchetti.template_ra div.hidden").show(); // mostra  Links e brochures (Allegati)  aperti in area riservata
}

/*_____________________ /menu da robopac*/

/* VIRTUAL EXPLORE */

if(typeof(Array.indexof)!=="function"){
	Array.prototype.indexOf = function(f, s) {
		if (typeof s == 'undefined') s = 0;
		for (var i = s; i < this.length; i++) {
			if (f === this[i]) return i;
		}
		return -1;
	}	
}

var ve_pages = new Array();
function virtual_explore(delay){
//	return;
	if (window.location.href.indexOf("&ve=1")>0){
		document.body.innerHTML+="<a href='"+window.location.href.replace('&ve=1','&ve=0')+"' style='position:fixed;top:0px;left:404px;z-index:100;padding:12px;border:1px solid #ff7777;background-color:#770000;color:#fff;'>stop virtual explore</a>";
		
		$("#menu_vert_3lev a").each(
					function(){if(this.href !=="#" && this.href.indexOf("?")>1 && this.href.indexOf("http://")<1)ve_pages.push(this.href+"&ve=1");}
					)
		/*
		ve_pages[0]="http://robopac.websolute.it/viewdoc.asp?co_id=28&ve=1";
		ve_pages[1]="http://robopac.websolute.it/viewdoc.asp?co_id=29&ve=1";
		ve_pages[2]="http://robopac.websolute.it/viewdoc.asp?co_id=30&ve=1";
		ve_pages[3]="http://robopac.websolute.it/viewdoc.asp?co_id=36&ve=1";
		ve_pages[4]="http://robopac.websolute.it/viewdoc.asp?co_id=8&ve=1";
		ve_pages[5]="http://robopac.websolute.it/viewdoc.asp?co_id=10&ve=1";
		ve_pages[6]="http://robopac.websolute.it/viewdoc.asp?co_id=7&ve=1";
		ve_pages[7]="http://robopac.websolute.it/viewdoc.asp?co_id=31&ve=1";
		ve_pages[8]="http://robopac.websolute.it/viewdoc.asp?co_id=32&ve=1";
		ve_pages[9]="http://robopac.websolute.it/viewdoc.asp?co_id=33&ve=1";
		ve_pages[10]="http://robopac.websolute.it/viewdoc.asp?co_id=34&ve=1";
		*/
		var i=0;
		//alert(window.location.href);
		i=ve_pages.indexOf(window.location.href);
		setTimeout(function(delay){if (i+1<ve_pages.length){window.location.href=ve_pages[i+1];}else{window.location.href=ve_pages[0];}},delay);
	} else if (window.location.href.indexOf("&ve=0")>0){
		document.body.innerHTML+="<a href='"+window.location.href.replace('&ve=0','&ve=1')+"' style='position:fixed;top:0px;left:404px;z-index:100;padding:12px;border:1px solid #ff7777;background-color:#770000;color:#fff;'>start virtual explore</a>";
	}
}

/* LANCIA INIT */
if(typeof($)=="function"){
	path_assoluto = location.href;
	$(document).ready (init);

}

