var delayproduccion = null;
var delayclip = null;
var etiqueta = false;
var etiquetaB = false;
var coloractive = "#FF7F00";
var colorclicked = "#8C8C8C";
var tiempo = 400;

function initProduccion(ny,nx){
    var div = document.getElementById("glowmenu");
    var div1st = document.getElementById("dropmenu1_d");
	var x=getposOffset(div, "left");
	var y=getposOffset(div, "top");

	if (ny != 0)
    	y = y - ny;
    if (nx != 0)
    	x = x + nx;

	div1st.style.left=x-clearbrowseredge(div, "rightedge")+150+"px";
	//div1st.style.left="200px";
	div1st.style.top=y-clearbrowseredge(div, "bottomedge")+div.offsetHeight+9+"px";
}
function initClip(ny,nx){
    var div = document.getElementById("glowmenu");
    var div1st = document.getElementById("dropmenu2_d");
	var x=getposOffset(div, "left");
	var y=getposOffset(div, "top");
	if (ny != 0)
    	y = y - ny;
    if (nx != 0)
    	x = x + nx;
	div1st.style.left=x-clearbrowseredge(div, "rightedge")+355+"px";
	//div1st.style.left="200px";
	div1st.style.top=y-clearbrowseredge(div, "bottomedge")+div.offsetHeight+9+"px";
}
function mostrarProduccion(){
	initProduccion(0,0);
	ocultarClip();
	if (delayproduccion!="undefined")
			clearTimeout(delayproduccion);
	var produccion = document.getElementById("dropmenu1_d");
	produccion.style.visibility = "visible";
}
function mostrarProduccion_onLoad(ny,nx){
	initProduccion(ny,nx);
	ocultarClip();
	if (delayproduccion!="undefined")
			clearTimeout(delayproduccion);
	var produccion = document.getElementById("dropmenu1_d");
	produccion.style.visibility = "visible";
}
function justmostrarProduccion(){
	var produccion = document.getElementById("dropmenu1_d");
	produccion.style.visibility = "visible";
}
function mostrarClip(){
	initClip(0,0);
	ocultarProduccion();

	if (delayclip!="undefined")
			clearTimeout(delayclip);
	var clip = document.getElementById("dropmenu2_d");
	clip.style.visibility = "visible";
}
function mostrarClip_onLoad(ny,nx){
	initClip(ny,nx);
	if (delayclip!="undefined")
			clearTimeout(delayclip);
	var clip = document.getElementById("dropmenu2_d");
	clip.style.visibility = "visible";
}
function justshowClip(){
var clip = document.getElementById("dropmenu2_d");
	clip.style.visibility = "visible";
}
function ocultarProduccion_version2(){
	var produccion = document.getElementById("dropmenu1_d");
	produccion.style.visibility = "hidden";
	ocultarEtiqueta();
	mostrarClip_onLoad();
}
function ocultarNivel2(submenu){

	switch(submenu){
		case "produccion":	if (etiqueta == false){
							    var menu = document.getElementById("menu").value;
								var submenu = document.getElementById("submenu").value;
								if(submenu != ""){
									if(menu == "production")
										mostrarProduccion();
									if(menu == "clip"){
										delayproduccion = window.setTimeout('ocultarProduccion_version2()',tiempo);
									}
									pintarSelected(menu,submenu,1);
								}
								else{
									pintarSelected(menu,submenu,0);
									delayproduccion = window.setTimeout('ocultarProduccion()',tiempo);
								}
							}
							break;
		case "clip":		if (etiqueta == true)
								delayclip = window.setTimeout('ocultarClip_showEtiqueta()',tiempo);
							else{
								var menu = document.getElementById("menu").value;
								var submenu = document.getElementById("submenu").value;
								if(menu != "clip"){
									delayclip = window.setTimeout('ocultarClip()',tiempo);
								}

							}
							break;

	}

}
function ocultarProduccion(){
	var produccion = document.getElementById("dropmenu1_d");
	produccion.style.visibility = "hidden";


	ocultarEtiqueta();
/*
	var menu = document.getElementById("menu").value;
	var submenu = document.getElementById("submenu").value;
	//alert(submenu);
	if(submenu != ""){
		if(menu == "production")
			mostrarProduccion();
		if(menu == "clip")
			mostrarClip_onLoad();
			//justshowClip();
		pintarSelected(menu,submenu,1);
	}
	else
		pintarSelected(menu,submenu,0);
*/
}
function ocultarClip(){
	var clip = document.getElementById("dropmenu2_d");
	clip.style.visibility = "hidden";

	var menu = document.getElementById("menu").value;
	var submenu = document.getElementById("submenu").value;
	if(submenu != ""){
		if(menu == "production")
			justmostrarProduccion();
			//mostrarProduccion();
		if(menu == "clip")
			//mostrarClip_onLoad();
		pintarSelected(menu,submenu,1);
	}
	else
		pintarSelected(menu,submenu,0);
}
function ocultarClip_showEtiqueta(){
	var clip = document.getElementById("dropmenu2_d");
	clip.style.visibility = "hidden";
	showEtiqueta();
}
function showEtiqueta(){
	etiqueta = true;
	ocultarProduccion();
	var div_label = document.getElementById("etiqueta_EN");
	div_label.style.visibility = "visible";
	document.getElementById("home").style.color = coloractive;
	document.getElementById("spamhome").style.color = coloractive;
	document.getElementById("production").style.color = colorclicked;
	document.getElementById("spamproduction").style.color = colorclicked;
	document.getElementById("clip").style.color = coloractive;
	document.getElementById("spamclip").style.color = coloractive;
	document.getElementById("showroom").style.color = coloractive;
	document.getElementById("spamshowroom").style.color = coloractive;
	document.getElementById("note").style.color = colorclicked;
	document.getElementById("daste").style.color = coloractive;
	document.getElementById("note2").style.color = colorclicked;
	document.getElementById("daste2").style.color = coloractive;

	document.getElementById("home").style.textDecoration = "underline";
	//document.getElementById("production").style.textDecoration = "underline";
	//document.getElementById("clip").style.textDecoration = "underline";

	document.getElementById("production").style.textDecoration = "none";
	document.getElementById("spamproduction").style.textDecoration = "none";
	document.getElementById("note").style.textDecoration = "none";
	document.getElementById("note2").style.textDecoration = "none";
	document.getElementById("li_produktion").innerHTML = '<a title="" id="production"><span id="spamproduction" style="color:'+colorclicked+'">Individual Clips</span></a>';
}
function continuarProduccion(){
	if (delayproduccion!="undefined")
			clearTimeout(delayproduccion);
}
function ocultarEtiqueta(){
	var label_etiqueta = document.getElementById("etiqueta_EN");
	label_etiqueta.style.visibility = "hidden";
}
function cerrarEtiqueta(){
    ocultarEtiqueta();
	ocultarNivel2("produccion")
	etiqueta = false;
	var menu = document.getElementById("menu").value;
	var submenu = document.getElementById("submenu").value;
	if(submenu != ""){
		if(menu == "production")
			mostrarProduccion();
		if(menu == "clip")
			mostrarClip();
		pintarSelected(menu,submenu,1);
	}
	else
		pintarSelected(menu,submenu,0);
	document.getElementById("note").style.textDecoration = "underline";
	//document.getElementById("production").style.textDecoration = "underline";

	if (menu != "production")
		document.getElementById("li_produktion").innerHTML = '<a title="" id="production" onmouseover="mostrarProduccion();" onmouseout="ocultarNivel2(\'produccion\');"><span id="spamproduction">Individual Clips</span></a>';
	else
		document.getElementById("li_produktion").innerHTML = '<a title="" id="production" onmouseover="mostrarProduccion();" onmouseout="ocultarNivel2(\'produccion\');"><span id="spamproduction" style="color:'+colorclicked+'">Individual Clips</span></a>';
}

function continuarClip(){
	if (delayclip!="undefined")
			clearTimeout(delayclip);
}
function mostrarCombo(){
	var combo = document.getElementById("div_select");
	combo.style.overflow = "visible";
}
function ocultarCombo(){
	var combo = document.getElementById("div_select");
	combo.style.overflow = "hidden";
}
function check_menu(ny,nx){
	var menu = document.getElementById("menu").value;
	var submenu = document.getElementById("submenu").value;
	
	if(submenu != ""){
		if(menu == "production"){
			mostrarProduccion_onLoad(ny,nx);
		}
		if(menu == "clip")
			mostrarClip_onLoad(ny,nx);
		pintarSelected(menu,submenu,1);
	}
	else
		pintarSelected(menu,submenu,0);
}
function pintarSelected(menu,submenu,flag){
	//first level

	document.getElementById("home").style.color = coloractive;
	document.getElementById("spamhome").style.color = coloractive;
	document.getElementById("production").style.color = coloractive;
	document.getElementById("spamproduction").style.color = coloractive;
	document.getElementById("clip").style.color = coloractive;
	document.getElementById("spamclip").style.color = coloractive;
	document.getElementById("showroom").style.color = coloractive;
	document.getElementById("spamshowroom").style.color = coloractive;

	document.getElementById("home").style.cursor = 'hand';
	document.getElementById("spamhome").style.cursor = 'hand';
	document.getElementById("production").style.cursor = 'hand';
	document.getElementById("spamproduction").style.cursor = 'hand';
	document.getElementById("clip").style.cursor = 'hand';
	document.getElementById("spamclip").style.cursor = 'hand';
	document.getElementById("showroom").style.cursor = 'hand';
	document.getElementById("spamshowroom").style.cursor = 'hand';
	//second level
	document.getElementById("daste").style.color = coloractive;
	document.getElementById("note").style.color = coloractive;
	document.getElementById("daste").style.cursor = 'hand';
	document.getElementById("note").style.cursor = 'hand';


	document.getElementById("koste").style.color = coloractive;

	//footer
	document.getElementById("casting").style.color = coloractive;
	document.getElementById("casting").style.cursor = 'hand';
	document.getElementById("kontakt").style.color = coloractive;
	document.getElementById("kontakt").style.cursor = 'hand';
	document.getElementById("lizenzierung").style.color = coloractive;
	document.getElementById("lizenzierung").style.cursor = 'hand';
	document.getElementById("agb").style.color = coloractive;
	document.getElementById("agb").style.cursor = 'hand';
	document.getElementById("nutzungsbedingungen").style.color = coloractive;
	document.getElementById("nutzungsbedingungen").style.cursor = 'hand';
	document.getElementById("datenschutz").style.color = coloractive;
	document.getElementById("datenschutz").style.cursor = 'hand';
	//document.getElementById("show").style.color = coloractive;

	if (menu != ""){
		if((menu == "casting") || (menu == "kontakt") || (menu == "lizenzierung") || (menu == "agb") || (menu == "nutzungsbedingungen") || (menu == "datenschutz")){
			var casting = 'href="casting.html"';
			var contact = 'href="kontakt.html"';
			var licencia ='href="lizenzierung.html"';
			var agb = 'href="agb.html"';
			var nutzu = 'href="nutzungsbedingungen.html"';
			var data = 'href="datenschutz.html"';
			if (menu == "casting")
				casting = "";
			if (menu == "kontakt")
				contact = "";
			if (menu == "lizenzierung")
				licencia = "";
			if (menu == "agb")
				agb = "";
			if (menu == "nutzungsbedingungen")
				nutzu = "";
			if (menu == "datenschutz")
				data = "";

			var htn = '<a '+casting+' id="casting">Casting</a>&nbsp;&nbsp;<BR><BR><a '+contact+' id="kontakt">Imprint</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a '+licencia+' target="_blank" id="lizenzierung">Licensing Agreement</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a '+agb+' id="agb">General Terms and Conditions</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a '+nutzu+' id="nutzungsbedingungen" target="_blank">Usage Conditions</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a '+data+' id="datenschutz" target="_blank">Privacy Policy</a>';
			document.getElementById("1st_level").innerHTML = htn;

			document.getElementById(menu).style.color = colorclicked;
			document.getElementById(menu).style.cursor = 'default';
			document.getElementById(menu).style.textDecoration = "none";
		}else{
			if (menu == "home")
				document.getElementById("li_home").innerHTML = '<a title="Home" id="home"><span id="spamhome" >Home</span></a>';
			if (menu == "showroom")
				document.getElementById("li_show").innerHTML = '<a id="showroom" title="Showroom"><span id="spamshowroom">Showroom</span>';

			if (menu != "partner_agentur"){
				document.getElementById(menu).style.color = colorclicked;
				document.getElementById(menu).style.cursor = 'default';
				document.getElementById("spam"+menu).style.color = colorclicked;
				document.getElementById("spam"+menu).style.cursor = 'default';
				document.getElementById(menu).style.textDecoration = "none";
				document.getElementById("spam"+menu).style.textDecoration = "none";
			}
		}
	}

    if (flag == 1){
    	if (submenu != ""){
	    	document.getElementById(submenu).style.color = colorclicked;
	    	document.getElementById(submenu).style.cursor = 'default';
	    	document.getElementById(submenu).style.textDecoration = "none";
	  	}
    }

}
function cerrar(){
	var div_label = document.getElementById("etiqueta_EN");
	div_label.style.visibility = "hidden";
	ocultarmenu();
	etiqueta = false;

	var menuant = document.getElementById("menuant").value;
	var submenuant = document.getElementById("submenuant").value;

	if (menuant == "home"){
		document.getElementById(menuant).style.color = colorclicked;
		document.getElementById("spamhome").style.color = colorclicked;
		document.getElementById("production").style.color = coloractive;
		document.getElementById("spamproduction").style.color = coloractive;
		document.getElementById("note").style.color = coloractive;
		document.getElementById("daste").style.color = coloractive;
		document.getElementById("note2").style.color = coloractive;
		document.getElementById("daste2").style.color = coloractive;
	}else
		document.getElementById(menuant).style.color = colorclicked;

	if (submenuant != "")
		document.getElementById(submenuant).style.color = colorclicked;

}


//******************************************************************************
//******************************************************************************
//******************************************************************************
//******************************************************************************


function showLabel(){
	etiqueta = true;
	var div_label = document.getElementById("etiqueta_EN");
	div_label.style.visibility = "visible";
	document.getElementById("home").style.color = coloractive;
	document.getElementById("spamhome").style.color = coloractive;
	document.getElementById("production").style.color = colorclicked;
	document.getElementById("spamproduction").style.color = colorclicked;
	document.getElementById("note").style.color = colorclicked;
	document.getElementById("daste").style.color = coloractive;
	document.getElementById("note2").style.color = colorclicked;
	document.getElementById("daste2").style.color = coloractive;
}
function ocultarmenu(){
	var level2 = document.getElementById("dropmenu1_d");
	level2.style.visibility = "hidden";
}
function ocultarmenuB(){
	var level2 = document.getElementById("dropmenu2_d");
	level2.style.visibility = "hidden";
}
function delayhidemenu()
{
	//this.delayhide=setTimeout(function(){tabdropdown.dropmenuobj.style.visibility='hidden'; if (obj2.parentNode.className.indexOf('default')==-1) obj2.parentNode.className=''},this.disappeardelay) //hide menu

}
function ShowLevel2(){
	init();
	if (delayhide!="undefined")
			clearTimeout(delayhide);
	else
		alert("no pasa nada");
	var level2 = document.getElementById("dropmenu1_d");
	level2.style.visibility = "visible";
}
function ShowLevel2B(){
	initB();
	if (delayhideB!="undefined")
			clearTimeout(delayhideB);
	else
		alert("no pasa nada");
	var level2 = document.getElementById("dropmenu2_d");
	level2.style.visibility = "visible";
}
function continuarLevel2(){
	if (delayhide!="undefined")
			clearTimeout(delayhide);
	else
		alert("no pasa nada");
}
function HideLevel2(){
	var tiempo = 400;
	if (etiqueta == false)
		delayhide = window.setTimeout('ocultarmenu()',tiempo);
}
function HideLevel2B(){
	var tiempo = 400;
	if (etiquetaB == false)
		delayhideB = window.setTimeout('ocultarmenuB()',tiempo);
}
function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
		while (parentEl!=null){
			totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
			parentEl=parentEl.offsetParent;
		}
	return totaloffset;
}

function clearbrowseredge(obj, whichedge){
	var dropmenuobj = document.getElementById("dropmenu1_d");
	var edgeoffset=0;
	if (whichedge=="rightedge"){
		var windowedge=this.ie && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)  //move menu to the left?
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var topedge=this.ie && !window.opera? this.standardbody.scrollTop : window.pageYOffset
		var windowedge=this.ie && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
		}
//		dropmenuobj.firstlink.style.borderTopWidth=(edgeoffset==0)? 0 : "1px" //Add 1px top border to menu if dropping up
	}
	//alert(edgeoffset);
	return edgeoffset
}

function init(){
    var div = document.getElementById("glowmenu");
    var div1st = document.getElementById("dropmenu1_d");
	var x=getposOffset(div, "left");
	var y=getposOffset(div, "top");
	div1st.style.left=x-clearbrowseredge(div, "rightedge")+150+"px";
	//div1st.style.left="200px";
	div1st.style.top=y-clearbrowseredge(div, "bottomedge")+div.offsetHeight+10+"px";
}
function initB(){
    var div = document.getElementById("glowmenu");
    var div1st = document.getElementById("dropmenu2_d");
	var x=getposOffset(div, "left");
	var y=getposOffset(div, "top");
	div1st.style.left=x-clearbrowseredge(div, "rightedge")+318+"px";
	//div1st.style.left="200px";
	div1st.style.top=y-clearbrowseredge(div, "bottomedge")+div.offsetHeight+10+"px";
}
