/*===============================================
   CASOart javascript functions
   Alessio Cartocci  [Terrafertile  © 2005/06]
===============================================*/

onload = function() {
	showItem("all");
	pHover();
	enableAbbr();

	// opacita' menu (css 2.1)
	ulMenu = document.getElementById("menudx").getElementsByTagName("ul")[0];
	if (IEdetect()>0) ulMenu.style.filter = "alpha(opacity=95)";
	else ulMenu.style.opacity = ".97";
}



/*  detect IE version
------------------------*/

function IEdetect() {
	isIE = 0;
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		IEver = navigator.appVersion.split("MSIE");
		isIE = parseFloat(IEver[1]);
	}
	return isIE;
}



/*  paragraph hover (IE)
--------------------------*/

function pHover() {
	if (IEdetect()>0 && IEdetect()<7) {
		p = document.getElementById("content").getElementsByTagName("p");
		for (k=0; k<p.length; k++) {
			if (p[k].className==""&&p[k].id!="homevent") {
				p[k].onmouseover = function() {this.className="hover";}
				p[k].onmouseout = function() {this.className="";}
			}
		}
	}
}



/* emulazione tag <abbr> per IE5+/win:
   basato sullo script di Jason Davis
   [http://www.jasonkarldavis.com/scripts/abbrhack]
------------------------------------------------------*/

function enableAbbr() {
	isMac = navigator.userAgent.toLowerCase().indexOf("mac");
	if (IEdetect()<7) {
		if (isMac==-1) {
			document.documentElement.setAttribute("xmlns:acc","http://www.w3.org/1999/xhtml");
			abbrTag = document.body.getElementsByTagName("abbr");
			for (i=0; i<=abbrTag.length-1; i++) {
				abbrTag[i].parentElement.innerHTML = abbrTag[i].parentElement.innerHTML.replace(/<abbr/gi, "<acc:abbr class=\"abbr\"").replace(/<\/abbr/gi, "</acc:abbr");
			}
		}
	}
}



/*  menu
-----------*/

function showItem(i,el) {
	isSafari = navigator.appVersion.indexOf("Safari");
	line = document.getElementById("menudx").getElementsByTagName("li");
	a = document.getElementById("menudx").getElementsByTagName("a");
	if (document.getElementById("pathbar")) a_path = document.getElementById("pathbar").getElementsByTagName("a");
	else a_path = null;
	j = 0;
	for (k=0; k<line.length; k++) {
		if (line[k].className.indexOf("sub")!=-1) {
			subline = line[k].getElementsByTagName("ul");
			if (i=="all") subline[0].className = "hidden";
			else subline[0].className = "hidden";
			line[k].onkeyup = line[k].onmouseover = function() {showItem(j,this);}
			line[k].onmouseout = function() {subline[0].className="hidden";}
			j++; 
		}
		else line[k].onkeyup = line[k].onmouseover = function() {showItem("all");}
	}
	if (el) subline = el.getElementsByTagName("ul");
	if (i!="all") {
		/*if (a_path!=null) {
			for(b=0; b<a_path.length; b++) {
				if (el && el.className=="sub" && el.parentNode.id=="pathbar") {
					//if (line[i].className=="sub")
					line[i].getElementsByTagName("ul");
				}
			}
		}*/
		if (subline[0].className=="hidden") subline[0].className = "showed";
		else subline[0].className = "hidden";
	}
}



/*  image resize
-------------------*/

function reSize() {
	var imag,i;
		imag = document.getElementById("content").getElementsByTagName("img");
		for (i=0; i<=imag.length-1; i++) {
			if (imag[i].style.pixelWidth>710 || imag[i].width>710) {
				imag[i].width = "710px";
				imag[i].style.width = "710px";
			}
		}
}



/*  select skin
------------------*/

function test() {
	sel1 = document.getElementById("colore").value;
	sel2 = document.getElementById("font").value;
	sel3 = document.getElementById("dimensione").value;
	target = "selecthigh.asp?test="+sel1+sel2+sel3;
	window.location.href = target;
}



/*  audioplayer
------------------*/

function mmgenerate(sez,mmlen) {
	items = document.getElementById("mmplaylist").getElementsByTagName("a");
	for (i=0; i<=items.length; i++) {
		len = mmlen[i-1];
		if (document.getElementById("mmcmd"+i+"")) {
			cmd = document.getElementById("mmcmd"+i+"");
			cmd.href = "javascript:mmplay("+i+",'"+sez+"',"+len+");";
			//cmd.title = "ascolta " + document.getElementById("mmcmd"+i+"").title.split(":");
			cmd.innerHTML = "play";
			cmd.className = "stop";
		}
	}
}

function mmplay(id,sez,len) {
	// aggiunto per plugin Flash Mozilla - Linux
	isLinux = navigator.userAgent.toLowerCase().indexOf("linux");
	styles = "";
	if (isLinux!=-1) styles = " style=\"width: 1px;\"";

	mmgenerate(sez,mmlen);
	cmd = document.getElementById("mmcmd"+id+"");
	cmd1 = document.getElementById("mmobj");
	newtitle = document.getElementById("mmcmd"+id+"").title.split("ascolta ");
	if (isIE>0) {
		cmd1.style.display = "block";
		cmd1.style.marginTop = "-1px";
	}
	cmd1.innerHTML = "<object type=\"application/x-shockwave-flash\" data=\"play.swf?id=http://www.casoart.com/audio/"+sez+"/"+id+".swf\" width=\"0\" height=\"0\"><!--[if IE]><param name=\"movie\" value=\"play.swf?id=http://www.casoart.com/audio/"+sez+"/"+id+".swf\" /><![endif]--></object>";
	cmd.innerHTML = "stop";
	cmd.href = "javascript:mmstop("+id+",'"+sez+"',"+len+");"
	//cmd.title = "ferma l'ascolto di " + newtitle;
	//state = document.getElementById("mmobj").playState;
	cmd.className = "play";
	setTimeout("mmstop("+id+",'"+sez+"',"+len+")",(len*1000)+1000);
}

function mmstop(id,sez,len) {
	cmd = document.getElementById("mmcmd"+id+"");
	newtitle = document.getElementById("mmcmd"+id+"").title.split("ferma l'ascolto di ");
	if (isIE>0) document.getElementById("mmobj").style.display = "none";
	document.getElementById("mmobj").innerHTML = "";
	cmd.href = "javascript:mmplay("+id+",'"+sez+"',"+len+");";
	//cmd.title = "ascolta " + newtitle;
	cmd.innerHTML = "play";
	cmd.className = "stop";
}



/*  alert message
--------------------*/

function hidenote() {
	document.getElementById("avvertenza").style.display = "none";
	document.getElementById("imgavvertenza").innerHTML = "<a href=\"#\" onclick=\"shownote(); return false;\" title=\"mostra l'avvertenza\"><img src=\"images/avvertenza.gif\" alt=\"mostra l'avvertenza\" /></a>";
}

function shownote() {
	document.getElementById("imgavvertenza").innerHTML = "";
	document.getElementById("avvertenza").style.display = "block";
}

function timernote() {
	//setTimeout("hidenote()",15000);
}