function $(o) {return document.getElementById(o);}
function get_obj(o) {if(String(o)===o) o=$(o); return o;}
function ch_vis(o) {
	img=$("ico_"+o);
	o=get_obj(o);
	if (o.className=="hide") {o.style.display="block"; return;}
	if (o.style.display=="block" || o.style.display=="") type="none";
	else type="block";
	o.style.display=type;
	if (img) {img.src="img/ico_"+type+".gif";}
}

function show(o) {o=get_obj(o);o.style.display="block";}
function hide(o) {o=get_obj(o);o.style.display="none";}
function start_show(o, min, max) {
	o.className="alpha1";
	show(o);
	for (i=min;i<max+1;i++) {setTimeout('$("'+o.id+'").className="alpha'+i+'"', 50*i);}
}
function start_hide(o, min, max) {
	o.className="alpha2";
	setTimeout('$("'+o+'").className="alpha3"', 50);
	setTimeout('$("'+o+'").className="alpha2"', 100);
	setTimeout('$("'+o+'").className="alpha1"', 150);
	setTimeout('hide("'+o+'")', 250);
}
function body_onload() {
	if (undefined===window.js_exec) {}else eval(js_exec);
}
function close_tab(id) {
	$("a_tab_"+id).className="tab";
	$("content_"+id).className="tab_content";
}
function open_tab(id) {
	close_tab(0);close_tab(1);close_tab(2);
	$("a_tab_"+id).className="tab_on";
	$c=$("content_"+id);
	$c.className="tab_content_on";
	$c.focus();
	if ($c.getAttribute("type")=="ajax" && $c.getAttribute("loaded")!=1) {
		load_content($c);
	}
}
function open_folder(id) {
	ch_vis(id);
	$c=$(id);
	$c.style.display="block";
//	if ($c.getAttribute("type")=="ajax" && $c.getAttribute("loaded")!=1) {
		load_content($c);
//	}
}

function load_content($c) {
//	$c.innerHTML="<div style='text-align:center;'>...Loading.... <br/><br/><br/><img src='img/loading2.gif' /></div>";
	$("gallery_files").innerHTML="<div style='text-align:center;'>...Loading.... <br/><br/><br/><img src='img/loading2.gif' /></div>";
	getURL("module.php", 
		[ ["mod", $c.getAttribute("mod")]
		, ["dir", $c.getAttribute("dir")]]
		, null, 2
		,'return_open_tab(content, "'+$c.id+'")'
		, "POST");
}
function return_open_tab(content, obj_id) {
	$(obj_id).innerHTML=content;
	$(obj_id).setAttribute("loaded", "1");
	if ($(obj_id+"_files")) $("gallery_files").innerHTML=$(obj_id+"_files").innerHTML;
	else $("gallery_files").innerHTML="Selezionare una area di interesse";
}
function create_tag(tag_name, id, style) {var t = document.createElement(tag_name);t.id=id;t.className=style;return t;}
function create_div(id, style) {return create_tag("DIV", id, style)}
function append_tag(tag, where) {where.appendChild(tag);}
var counter_id=0;
function new_id() {counter_id++;return "new_id_"+counter_id;}
function create_popup() {
	if ($("div_pellicola")) return;
	div_a=create_div("div_pellicola", "hide alpha2");
	append_tag(div_a, document.body);
	div_b=create_div("div_show_img_container", "hide");
//	div_a.onclick=function (){alert(1)};
	out='<table border="0" cellspacing="0" cellpadding="0" style="width:100%;height:100%;">';
	out+='<tr><td height="0" width="49%"></td><td ></td><td width="30%" valign="bottom"><DIV style="position:relative;top:20px;left:-20px;">'
		+'<A href="javascript:hide_img();" style="text-align:right;"><img src="img/close.gif" width="32" height="32" style=""/></a>'
		+'</DIV></td></tr>';
	out+='<tr><td ></td><td id="div_show_img" valign="top">';
	out+='</td><td ></td></tr>';
	out+='<tr><td height="49%" width="49%"></td><td ></td><td width="49%"></td></tr>';
	out+='</table>';
	div_b.innerHTML=out;
	append_tag(div_b, document.body);
}

	
function show_flv(url, title, prev, next, th) {
// th e' l'oggetto DOM contenente la thumbnail - opzionale
	create_popup(prev, next);
	d=$("div_show_img_container");
	d_img=$("div_show_img");
	pellicola=$("div_pellicola");
	url_formatted=url.replace(/[\']/g,"\\'");
	out='<DIV style="position:absolute;"><DIV style="position:relative;text-align:left;top:-30px;color:#FFF;font-size:12pt;">'
		+'<b>'+title+'</b> <br/>&nbsp;&nbsp;&nbsp;&nbsp;'
		+((prev)?'&nbsp;&nbsp;&nbsp;<a href="javascript:show_file($(\''+prev.id.replace(/[\']/g,"\\'")+'\'));" class="more_info">&laquo; Prev</a>':'')
		+((next)?'&nbsp;&nbsp;&nbsp;<a href="javascript:show_file($(\''+next.id.replace(/[\']/g,"\\'")+'\'));" class="more_info">Next &raquo;</a>':'')
		+'</DIV></DIV>';
	out+='<DIV style="position:absolute;"><DIV id="big_img_info" style="overflow:auto;height:500px;width:100%;padding:10px;position:relative;text-align:left;color:#000;font-size:12pt;">'
		+'</DIV></DIV>';
	out+='<DIV id="big_img" style="width:640px;height:480px;"></DIV>';


	d_img.innerHTML=out;
	
$f("big_img", "plugin/flow/flowplayer-3.0.5.swf", { 
/*    clip: {  duration: 15  },  */
    playlist: [ url ], 
	wmode: ''
});		
	
	start_show(pellicola,0,3);
	setTimeout('show("'+d.id+'");', 500);
}
function show_img(url, title, prev, next, th) {
// th e' l'oggetto DOM contenente la thumbnail - opzionale
	create_popup(prev, next);
	d=$("div_show_img_container");
	d_img=$("div_show_img");
	pellicola=$("div_pellicola");
	url_formatted=url.replace(/[\']/g,"\\'");
	out='<DIV style="position:absolute;"><DIV style="position:relative;text-align:left;top:-30px;color:#FFF;font-size:12pt;">'
		+'<b>'+title+'</b> <br/><a href="javascript:show_info_big_img(\''+url_formatted+'\');" class="more_info">maggiori informazioni</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
		+((prev)?'&nbsp;&nbsp;&nbsp;<a href="javascript:show_file($(\''+prev.id.replace(/[\']/g,"\\'")+'\'));" class="more_info">&laquo; Prev</a>':'')
		+((next)?'&nbsp;&nbsp;&nbsp;<a href="javascript:show_file($(\''+next.id.replace(/[\']/g,"\\'")+'\'));" class="more_info">Next &raquo;</a>':'')
		+'</DIV></DIV>';
	out+='<DIV style="position:absolute;"><DIV id="big_img_info" style="overflow:auto;height:500px;width:100%;padding:10px;position:relative;text-align:left;color:#000;font-size:12pt;">'
		+'</DIV></DIV>';
	out+='<img src="img/e.gif" width="660" height="1" style="display:block;"/>';
	//Creo la th grande per fare da sfondo
	out+='<img class="loading" src="get_th.php?imgname='+url+'&max_w=650&max_h=500" id="big_img"/>';

/* @todo: sistemare. codice per pre-caricare la thumbnail in attesa dell'immagine vera
th sopra immagine vera, calcolo dimensione da sistemare per le immagini h > w
	if (th) {
		w=th.firstChild.firstChild.offsetWidth-7;
		h=th.firstChild.firstChild.offsetHeight-7;
		max_w=650;
		max_h=Math.round(h*max_w/w);
		out+='<img class="alpha5" src="get_th.php?imgname='+url+'&max_w=100&max_h=90" width="650" height="'+max_h+'" style="position:absolute;"/>';
	} */
//	out+=title;
	d_img.innerHTML=out;
	start_show(pellicola,0,3);
	setTimeout('show("'+d.id+'");', 500);
}
function show_file(o) {
	if (!o || !o.getAttribute("url")) return;
	prev=o.previousSibling;
	next=o.nextSibling;
	if (!prev || !prev.getAttribute("url") ) prev=null;
	if (!next || !next.getAttribute("url") ) next=null;
	ext=o.getAttribute("ext");
	if (ext=="jpg") show_img(o.getAttribute("url"), o.getAttribute("title"), prev, next, o);
	else show_flv(o.getAttribute("url"), o.getAttribute("title"), prev, next, o);
}	
function show_info_big_img(url) {
	img=$("big_img"); 
	txt=$("big_img_info");
//	txt.style.width=img.offsetWidth;
	txt.style.width="650px";
	txt.style.height=img.offsetHeight;	
	txt.style.display="block";
	img.className="alpha2";
//	url_txt=url.substr(0, url.length-4)+".txt";
	getURL("load_txt.php?url="+url, null, "big_img_info", 1, null, "", true);
}
function hide_info_big_img() {
	img=$("big_img");
	txt=$("big_img_info");
	txt.style.display="none";
	img.className="";
}
function hide_img() {
	hide("div_show_img_container");
	start_hide("div_pellicola");
}
function get_swf(url, w, h) {
	out='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" height="'+h+'" width="'+w+'">';
	out+='<param name="movie" value="'+url+'">';
	out+='<param name="wmode" value="transparent">';
	out+='<embed wmode="transparent" src="'+url+'" height="'+h+'" width="'+w+'">';
	out+='</embed></object>';
	return out;
}
function get_player_mp3(d) {
w=100;h=20;
url ='swf/mp3player.swf?file='+d+''
	+'&amp;backColor=990000'
	+'&amp;frontColor=ddddff'
	+'&amp;repeatPlay=false'
	+'&amp;songVolume=90'
	+'&amp;autoStart=true'
	+'&amp;showDownload=true';
	out=get_swf(url, w, h);
	return out;
 }
function open_player_mp3(id) {
	obj=$("file_"+id);
	f=obj.getAttribute("url");
	t=obj.getAttribute("title");
	w=400;h=80;
	out='<h3>'+t+'</h3>';
	out+=get_player_mp3(f);
	$("player_mp3_container").innerHTML=out;
//	return out;
}
function debug() {}

// TOOLTIP
function show_tooltip_file(obj) {
	f=obj.getAttribute("url");
	t="<b>"+obj.getAttribute("title")+"</B><BR/>";
//Dati non necessari
//	t+="<DIV style=\"font-size:0.7em;\"> ";
//	t+="<b>Tipo file:</b> "+obj.getAttribute("ext")+"<BR/>";
//	t+="<b>Dimensioni:</b> "+obj.getAttribute("filesize")+"<BR/>";
//	t+="<b>Percorso:</b> "+obj.getAttribute("dir")+"<BR/>";
//	t+="<b>Ultimo aggiornamento:</b> "+obj.getAttribute("last_mod")+"<BR/>";
//	if (obj.getAttribute("img_w")) {
//		t+="<b>Dimensioni immagine:</b> "+obj.getAttribute("img_w")+" x "+obj.getAttribute("img_h")+"<BR/>";
//	}
//	t+="</DIV> ";
	show_tooltip(t);
}
function create_tooltip() {if ($(divTooltip)) return;div_t=create_div(divTooltip, "tooltip");append_tag(div_t, document.body);}
function show_tooltip(t) {create_tooltip();div=$(divTooltip);div.innerHTML=t;show(div);}
function hide_tooltip() {hide($(divTooltip))}
var divTooltip = 'div_tooltip'; // div that is to follow the mouse
var offX = 45;          // X offset from mouse position
var offY = -45;          // Y offset from mouse position
function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}
function follow(evt) {if ($d=$(divTooltip)) if ($d.style.display=="block") {var obj = $d.style; obj.visibility = 'visible';obj.left = (parseInt(mouseX(evt))+offX) + 'px';obj.top = (parseInt(mouseY(evt))+offY) + 'px';}}
document.onmousemove = follow;

function openW(win,title,width,height,scroll) {
	var x;
	var y;
	var param;
        //Valori di default
        if (!width) width='750';
        if (!height) height='400';
	x = screen.width / 2 - width / 2;
	y = screen.height / 2 - height / 2;
	param = "width="+width+",height="+height+",left="+x+",top="+y+",scrollbars="+scroll+",toolbar=0,location=0,directories=0,menuBar=0,resizable=1";
	window.open(win,title,param);
}

