/***************************************************************
*
*  JavaScript DHTML layer menu
*
* $Id: jsfunc.layermenu.js,v 1.2 2003/10/26 17:07:43 typo3 Exp $
* 
*
*
*  Copyright notice
* 
*  (c) 1998-2003 Kasper Skårhøj
*  All rights reserved
*
*  This script is part of the TYPO3 tslib/ library provided by
*  Kasper Skårhøj <kasper@typo3.com> together with TYPO3
*
*  Released under GNU/GPL (see license file in tslib/)
* 
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* 
*  This copyright notice MUST APPEAR in all copies of this script
***************************************************************/

var GLV_x=0;
var GLV_y=0;
var GLV_curLayerWidth = new Array();
var GLV_curLayerHeight = new Array();
var GLV_curLayerX = new Array();
var GLV_curLayerY = new Array();
var GLV_menuOn = new Array();
var GLV_gap = new Array();
var GLV_currentLayer = new Array();
var GLV_currentROitem = new Array();
var GLV_hasBeenOver = new Array();
var GLV_doReset = new Array();
var GLV_lastKey = new Array();
var GLV_menuXY = new Array();
var GLV_date = new Array();
var GLV_timeout = new Array();
var GLV_timeoutRef = new Array();
var GLV_onlyOnLoad = new Array();
var GLV_dontHideOnMouseUp = new Array();
var GLV_date = new Date();
var GLV_restoreMenu = new Array();
var GLV_timeout_count=0;
var GLV_timeout_pointers = new Array();
var GLV_dontFollowMouse = new Array();

	//browsercheck...

function GL_checkBrowser(){
	this.dom= (document.getElementById);
	this.op=this.opera= (navigator.userAgent.indexOf("Opera")>-1);
	this.konq=  (navigator.userAgent.indexOf("Konq")>-1);
	this.ie4= (document.all && !this.dom && !this.op && !this.konq);
	this.ie5= (document.all && this.dom && !this.op && !this.konq);
	this.ns4= (document.layers && !this.dom && !this.konq);
	this.ns5= (!document.all && this.dom && !this.op && !this.konq);
	this.ns6= (this.ns5);
	this.bw=  (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
	return this;
}
bw= new GL_checkBrowser();

	//NS4 resize fix.
if(document.layers){
    scrX= innerWidth; scrY= innerHeight;
    onresize= function()	{if(scrX!= innerWidth || scrY!= innerHeight)	{history.go(0);}};
}
	//Returns css
function GL_getObjCss(obj){								
	return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
};
function GL_isObjCss(obj){								
	flag = bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
	if (flag)	return true;
};
function GL_getObj(obj){
//	nest= (!nest)?"":"document."+nest+".";
	nest="";
	this.el= bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document."+obj):document.getElementById(obj);	
   	this.css= bw.ns4?this.el:this.el.style;
	this.ref= bw.ns4?this.el.document:document;		
	this.x= (bw.ns4||bw.op)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.op)?this.css.top:this.el.offsetTop;
	this.height= (bw.ie4||bw.ie5||bw.ns6)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.op?this.css.pixelHeight:0;
	this.width= (bw.ie4||bw.ie5||bw.ns6)?this.el.offsetWidth:bw.ns4?this.ref.width:bw.op?this.css.pixelWidth:0;
	return this;
}
function GL_initLayers() {
	if(bw.ns4) document.captureEvents(Event.MOUSEMOVE);
	GL_timeout_func();
}
function GL_updateTime(WMid)	{
	GLV_date = new Date();
	GLV_timeout[WMid] = GLV_date.getTime();
}
function GL_doResetAll(WMid) {
	var resetSubMenus="";
	eval('resetSubMenus = GL'+WMid+'_resetSubMenus();');
	if (GLV_doReset[WMid] && resetSubMenus) {
		GLV_doReset[WMid] = false;
		GL_hideAll(WMid);
		if (GLV_onlyOnLoad[WMid])	GL_restoreMenu(WMid);
	}
}
function GL_timeout_func()	{
	GLV_date = new Date();
	var stuff="";
	for (var a=0;a<GLV_timeout_count;a++)	{
		WMid = GLV_timeout_pointers[a];
		if (GLV_date.getTime()-GLV_timeout[WMid] > GLV_timeoutRef[WMid])	{
			GL_doResetAll(WMid);
		}
	}
//window.status = GLV_date.getTime()-GLV_timeout[WMid]-GLV_timeoutRef[WMid]
	window.setTimeout("GL_timeout_func();",200);
}
function GL_resetAll(WMid) {
	if (!GLV_doReset[WMid]) {
		GL_updateTime(WMid);
		GLV_doReset[WMid] = true;
	}
}
function GL_mouseUp(WMid,e) {
	GLV_doReset[WMid] = false;
	if (!GLV_dontHideOnMouseUp[WMid])	{
		GL_hideAll(WMid);
		if (GLV_onlyOnLoad[WMid])	GL_restoreMenu(WMid);
	}
}
function GL_stopMove(WMid) { 
	GLV_menuOn[WMid] = null;	
}
function GL_restoreMenu(WMid)	{
	eval('GL'+WMid+'_restoreMenu()');
}




function nw_my_move() {
	var myWidth, myHeight,srw,srh;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
		
	srw=(myWidth-980)/2;
	srh=(myHeight-450)/2 +6;

	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	srw=(myWidth-763)/2;
	srh=(myHeight-450)/2;

	}	
	my_x = 28 + srw;
	my_y = 189 + srh;
}

var first_time=true,nieu_y,nieu_x;
var visited_ids = new Array(); 
var menus_pos_x = new Array();
var menus_pos_y = new Array();
function GL_doTop(WMid,id) { 
	GL_hideAll(WMid);	
	if (GL_isObjCss(id))	{
		GLV_menuOn[WMid] = GL_getObjCss(id);
		GLV_menuOn[WMid].visibility = "visible";

		eval('GL'+WMid+'_doTop(WMid,id)');
		var layerObj = GL_getObj(id);
		
		var myWidth, myHeight,srw,srh;
		if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;		
		srw=(myWidth-980)/2;
		srh=(myHeight-450)/2 +6;

		} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
			myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
			srw=(myWidth-980)/2;
			srh=(myHeight-450)/2;
		}
	    var tmp_top,tmp_left;
		var visited = false;
		for(var i=0;i < visited_ids.length;i++)
		{
			if(visited_ids[i] == id)
			{
				visited = true;
				break;
			}
		}
		
		
		if(!visited){		
			/*tmp_top = parseInt(GLV_menuOn[WMid].top.substring(0,GLV_menuOn[WMid].top.indexOf("px")));
			tmp_left = parseInt(GLV_menuOn[WMid].left.substring(0,GLV_menuOn[WMid].left.indexOf("px")));			*/
			nieu_y = layerObj.y+srh+190+29;			
			nieu_x = layerObj.x+srw+158-20;
			menus_pos_y.push(nieu_y);
			menus_pos_x.push(nieu_x); 			
			visited_ids.push(id);
			GLV_menuOn[WMid].top = nieu_y+"px";
			GLV_menuOn[WMid].left = nieu_x+"px";
			GLV_curLayerX[WMid] = nieu_x;
			GLV_curLayerY[WMid] = nieu_y;
		}		
		
				
		GLV_curLayerHeight[WMid] = layerObj.height;
		GLV_curLayerWidth[WMid] = layerObj.width;
		if(visited)
		{		
			GLV_menuOn[WMid].top = menus_pos_y[i]+"px";
			GLV_menuOn[WMid].left =  menus_pos_x[i]+"px";
			GLV_curLayerX[WMid] = menus_pos_x[i];
			GLV_curLayerY[WMid] = menus_pos_y[i];
		}
		//GLV_curLayerX[WMid] = layerObj.x;
		//GLV_curLayerY[WMid]  = layerObj.y;		
		GLV_currentLayer[WMid] = id;
		GLV_hasBeenOver[WMid]=0;				
	}
}
	//Capturing mousemove
function GL_getMouse(e) {
	GLV_x= (bw.ns4||bw.ns5)?e.pageX:(bw.ie4||bw.op)?event.x:(event.x-2)+document.body.scrollLeft;
	GLV_y= (bw.ns4||bw.ns5)?e.pageY:(bw.ie4||bw.op)?event.y:(event.y-2)+document.body.scrollTop;
}
function GL_mouseMoveEvaluate(WMid)	{
	if (GLV_gap[WMid] && GLV_currentLayer[WMid]!=null)	{
		if (	GLV_x+GLV_gap[WMid]-GLV_curLayerX[WMid] <0 || GLV_y+GLV_gap[WMid]-GLV_curLayerY[WMid] <0 || GLV_curLayerX[WMid]+GLV_curLayerWidth[WMid]+GLV_gap[WMid]-GLV_x <0 || GLV_curLayerY[WMid]+GLV_curLayerHeight[WMid]+GLV_gap[WMid]-GLV_y <0)	{
			if (GLV_hasBeenOver[WMid])	{
				GLV_doReset[WMid]=true;
			}
		} else {
			GL_updateTime(WMid);
			GLV_hasBeenOver[WMid]=1;
			GLV_doReset[WMid]=false;	// Added 120902: When on the layer we do not want the layer to be reset... 
		}
	}
}
function GL_hideAll(WMid)	{
	GLV_doReset[WMid] = false;
	GLV_currentLayer[WMid] = null;
	if (GL_isObjCss(GLV_lastKey[WMid]) && GL_getObjCss(GLV_lastKey[WMid]))	{	eval('GL'+WMid+'_hideCode()');	}
	GLV_hasBeenOver[WMid]=0;
}

// Nieuwe created by Dragos
	var obj=document.getElementById("tt");
	var total_y =0,total_x=0;
	var forb_tags = "tr";
	function calc_top(ob)
	{		
		if(ob.parentNode.tagName.toLowerCase() != "html")
		{
			
			if(forb_tags.indexOf(ob.tagName.toLowerCase()) == -1)			
			{				
				total_y += ob.offsetTop;
				total_x += ob.offsetLeft;
			}			
			calc_top(ob.parentNode);
		}
		else
		{			
			return 0;
		}		
	}
	function nie_posit_layer(l_id)
	{
		var nie_l_obj =  document.getElementById(l_id);
		if(document.all){
		nie_l_obj.style.left = total_x  + 3 +"px";
		nie_l_obj.style.top = total_y  + 22 +"px";
		}
		else{
		nie_l_obj.style.left = total_x + 3 +"px";
		nie_l_obj.style.top = total_y + 20 +"px";
		}
	}
	function reset_values()
	{
		total_y=0;
		total_x=0;
	}
var submenus = new Array ();
var sub_menu_cont = 0;

function getTop(theelement)
{
if (theelement.offsetParent) return theelement.offsetTop + getTop(theelement.offsetParent);
else return theelement.offsetTop;
}
function getLeft(theelement)
{
if (theelement.offsetParent) return theelement.offsetLeft + getLeft(theelement.offsetParent);
else return theelement.offsetLeft;
}
function my_id_position(top_menu,submenu)
{
	Hide_my_id_position();
       if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1)
       {
           //IE
           deplasament = 26;
       }
              if(navigator.userAgent.toLowerCase().indexOf("gecko")!=-1)
       {
           //mozilla, firefox
           deplasament = 16;
       }
	
	
	var sub_menu = document.getElementById(submenu);
	var mx = getTop(top_menu);
	var my = getLeft(top_menu);
	
	sub_menu.style.top = mx+deplasament;
	sub_menu.style.left = my;
	sub_menu.style.visibility = "visible";
	
	//if(!submenus[])
	submenus[sub_menu_cont++] = submenu;
	
}

function Hide_my_id_position (){
	for (var i=0; i<sub_menu_cont;i++) {
		var sub_menu = document.getElementById(submenus[i]);
		sub_menu.style.visibility = "hidden";

	}
	
	
	
}


