var m = new Array();
var mouse = new Array("x","y");
var list_of_open_items = new Array();

var scrollTopOffset = false;
var mousecontrol_timer = 50;
var mousecontrol_interval = false;

var show_all = 0;
var show_in_progress = false;
var hide_in_progress = false;

var base_width = "175px";

var flashmovies = new Array();
var flashcounter = -1;

function proofSubmenues(id){
	
	if ( show_in_progress == true || hide_in_progress == true || show_all > 0) { return; }
	if (list_of_open_items[list_of_open_items.length-1] != id) {
		if (list_of_open_items.length > 0) {
			if (
				m[id].pid != m[list_of_open_items[list_of_open_items.length-1]].id 
				&& 
				m[id].pid == m[list_of_open_items[list_of_open_items.length-1]].pid
			) {
				if (m[list_of_open_items[list_of_open_items.length-1]].childrens.length > 0) {
					hideChildrens(list_of_open_items[list_of_open_items.length-1]);
				}
			}
			else if (m[id].pid != m[list_of_open_items[list_of_open_items.length-1]].id) {
				var counter = list_of_open_items.length;
				for(x=0; x < counter; x++) {
					var temp = (counter-x)-1;
					if (m[id].pid == m[list_of_open_items[temp]].id) {
						break;
					}
					else {				
						hideChildrens(list_of_open_items[temp]);
					}
				}
			}
		} 
		if (m[id].childrens.length > 0) {
			if (flashcounter > -1) {
				cutFlashDivs();
			}
			showChildrens(id);
			findChildrensArea(id);
		} 
	}
}

// flashmovies müssen ausgeblendet werden 
var flashcontent = new Array();
var flashvisibility = true;

function cutFlashDivs() {
	for(i = 0; i <= flashcounter; i++) {
		if (!flashcontent[i]) {
			flashcontent[i]       = flashmovies[i].d.innerHTML;
			flashmovies[i].width  = flashmovies[i].getWidth()-2;
			flashmovies[i].height = flashmovies[i].getHeight()-2;
			flashmovies[i].setWidth(flashmovies[i].width);
			flashmovies[i].setHeight(flashmovies[i].height);
		}
		flashmovies[i].rewrite('<div class="FlashHiddingDiv" style="width:' + flashmovies[i].width + 'px; height:' + flashmovies[i].height + 'px;">&nbsp;</div>');
//		flashmovies[i].rewrite('&nbsp;');
	}
	flashvisibility = false;
}
function pasteFlashDivs() {
	for(i = 0; i <= flashcounter; i++) {
		flashmovies[i].rewrite(flashcontent[i]);
	}
	flashvisibility = true;
}



function handleMouseMove(e) {
	mouse["x"] = (!document.all)? e.pageX : window.event.clientX;
	mouse["y"] = (!document.all)? e.pageY : (window.event.clientY);
	if (document.all) {
		if (document.documentElement.scrollTop) {
			scrollTopOffset = document.documentElement.scrollTop;
		}
		else {
			scrollTopOffset = window.document.body.scrollTop;
		}
	}
	mouse["y"] += scrollTopOffset;

}


function compareMousePosById() {
	
	if (show_in_progress == true || hide_in_progress == true || show_all > 0) { return; }
	if (list_of_open_items.length > 0) {
		
		var counter = list_of_open_items.length;
		
		for(z=0; z < counter; z++) {
			var temp = (counter-z)-1;
			var obj = m[list_of_open_items[temp]];
//			window.status = mouse["x"]+' X '+mouse["y"] +'/'+ (obj.area.t+obj.area.h)
			if (
				(
					mouse["x"] > obj.area.l 
					&&
					mouse["x"] < (obj.area.l+obj.area.w)
					&&
					mouse["y"] >= obj.area.t
					&&
					mouse["y"] <= ((obj.area.t+obj.area.h)+2)
				
					) || (
				
					mouse["x"] > obj.childrens.area.l 
					&&
					mouse["x"] < (obj.childrens.area.l+obj.childrens.area.w)
					&&
					mouse["y"] > obj.childrens.area.t 
					&&
					mouse["y"] < (obj.childrens.area.t+obj.childrens.area.h)
				)						
			) {
//				window.status = 'in';
				break;
			}
			else {
				hideChildrens(list_of_open_items[temp]);
//				window.status = 'out';

			}
		}
	}
}


function controlByTime() {
	if (list_of_open_items.length > 0) {
		compareMousePosById();
	}
	else if (saveFadeObj == false) {
		if (flashvisibility == false) pasteFlashDivs();
	}
	if (saveFadeObj != false) {
		compareMousePosByPrimery();
	}
	if (typeof saveSecondaryTop != 'undefined' && saveSecondaryTop != false) {
		compareMousePosBySecondaryTop();
	}
	if (mousecontrol_interval) {
		clearTimeout(mousecontrol_interval);
	}
	mousecontrol_interval = setTimeout("controlByTime()",mousecontrol_timer);
}

function showChildrens(id) {
	if (hide_in_progress == true || show_all > 0) { return; }
	show_in_progress = true;
	if (m[id].childrens.length > 0) {
		for(i=0; i < m[id].childrens.length; i++) {
			m[m[id].childrens[i]].css.backgroundPosition = '5px 2px';
			m[m[id].childrens[i]].setWidth(base_width);
			m[m[id].childrens[i]].paste("inline");
			m[m[id].childrens[i]].setZindex(100);
			m[m[id].childrens[i]].setPositionType("absolute");
			m[m[id].childrens[i]].css.border = "solid 1px #0072BC";
			m[m[id].childrens[i]].css.borderBottom = "0px";
			m[m[id].childrens[i]].css.padding = "2px";
			m[m[id].childrens[i]].css.paddingLeft = "5px";
			m[m[id].childrens[i]].setOpacity(95);
	
			var lastid = i;
		}
		list_of_open_items[list_of_open_items.length] = id;
		if (m[id].pid == 0) {
//			m[id].d.className = "folderOpen level_1";
		}
		else {
//			m[id].d.className = "folderOpen";
//			m[id].css.marginTop = "0px";
		}
		m[m[id].childrens[0]].css.borderTop = "solid 1px #0072BC";
		m[m[id].childrens[lastid]].css.borderBottom = "solid 1px #0072BC";
	}
	else {
		m[id].d.className = "fileOpen";
	}
	show_in_progress = false;
}

function hideChildrens(id) {
	if (show_in_progress == true || show_all > 0) { return; }
	hide_in_progress = true;
	if (m[id].childrens.length > 0) {
		for(i=0; i < m[id].childrens.length; i++) {
			m[m[id].childrens[i]].setZindex(0);
			m[m[id].childrens[i]].cut();
			lastid = i;
		}
		list_of_open_items.length = list_of_open_items.length-1;
		if (m[id].pid == 0) {
			m[id].d.className = "folderClose_level_1";
		}
		else {
			m[id].d.className = "folderClose";
		}
	}
	else {
		m[id].d.className = "fileClose";
	}
	hide_in_progress = false;
}

function findItemChildrens() {
	for(i=0; i < m.length; i++) {
		for(j=0; j < m.length; j++) {
			if (m[j].pid == m[i].id) {
				m[i].childrens[m[i].childrens.length] = j;
			}
		}
	}
}


function findChildrensArea(id) {
	
	if (m[id].childrens.length > 0) {
		var childrens_x = childrens_y = childrens_width = childrens_height = 0;

		childrens_x = (m[id].getLeft()+m[id].getWidth());
		childrens_y = (m[id].getTop());
				
		for(i=0; i < m[id].childrens.length; i++) {
			
			m[m[id].childrens[i]].setLeft(childrens_x);
			m[m[id].childrens[i]].setTop((childrens_y+childrens_height));
			
			childrens_height += m[m[id].childrens[i]].getHeight();
			childrens_width   = m[m[id].childrens[i]].getWidth();
			
		}	
		m[id].area            = new setAreaObject(m[id].getLeft(), (m[id].getTop()+Navbar.getTop()), m[id].getWidth(),m[id].getHeight());
		m[id].childrens.area  = new setAreaObject(childrens_x, (childrens_y+Navbar.getTop()), childrens_width, childrens_height);
	}	
}


function setAreaObject(l,t,w,h) {
	this.l = l;	
	this.t = t;	
	this.w = w;	
	this.h = h;
	return this;
}


function Event_init() {
	if (document.layers){
		window.captureEvents (Event.MOUSEMOVE);
	    window.onmousemove = handleMouseMove;
	}
	else {  document.onmousemove=handleMouseMove; }
}

function init() {
	findItemChildrens()
	Event_init();
	controlByTime();
	clearAllAltTags();

//	if ( "undefined" != typeof(Navbar)) Navbar.paste();

	// extrainit fuer formulare?
	if ( "undefined" != typeof(extrainit))
	{ eval(extrainit) }

	// extra fuer flashueberpruefung
	if (flashcounter > -1) {
		flash_detection(6, 10);
	}
}

var fadeInHandler    = false;
var fadeSteps        = 7;
var fadeTimer        = 10;
var saveFadeSteps    = fadeSteps;
var stepsBreakPoint  = 3;
var saveFadeObj      = false;

function fadeIn(obj,start,end) {
//	window.status = "";

	if (saveFadeObj && (saveFadeObj != obj)) {
		hidePrimary(saveFadeObj);
	}

	saveFadeObj = obj;
	saveObj   = obj;
	saveStart = start;
	saveEnd   = end;
	if (saveObj) saveNow   = saveObj.getTop();
	
	if (saveNow < saveEnd) {
		if ((saveEnd-saveNow)<(fadeSteps*stepsBreakPoint)) fadeSteps=1;
		saveObj.setTop(saveNow+fadeSteps);
		fadeInHandler = setTimeout("fadeIn(saveObj,saveStart,saveEnd)", fadeTimer);
	}
	else {
		clearTimeout(fadeInHandler);
		if (saveObj) saveObj.setTop(saveEnd);
		saveObj   = 0;
		saveStart = 0;
		saveEnd   = 0;
		saveNow   = 0;
		fadeSteps = saveFadeSteps;
		fadeInHandler = false;

	}
}


function showPrimary(obj) {
	if (!obj || saveFadeObj == obj) return;
	obj.paste();
	obj.setTop(Header.getHeight()-obj.getHeight());
	Header.setZindex(10);
	obj.setZindex(5);
	fadeIn(obj,0,139);
	if (flashcounter > -1) {
		if (flashvisibility == true) setTimeout("cutFlashDivs()",10);
	}
}
function hidePrimary(obj) {
	obj.setTop(obj.getHeight()-Header.getHeight()); 
	obj.cut();
	saveFadeObj = false;
	fadeInHandler = false;
	if (flashvisibility == false) pasteFlashDivs();
}


function compareMousePosByPrimery() {
	
	if (!saveFadeObj) { return; }
	obj = saveFadeObj;
	if (
		mouse["x"] < obj.getLeft() 
		||
		mouse["x"] > (obj.getLeft()+obj.getWidth())
		||
		mouse["y"] < (obj.getTop() - 20)
		||
		mouse["y"] > ((obj.getTop())+(obj.getHeight()))
	) {
		if (!fadeInHandler) hidePrimary(obj);
	}
}

function compareMousePosBySecondaryTop() {
	
	if (!saveSecondaryTop) { return; }
	obj = saveSecondaryTop;
	if (
		mouse["x"] < obj.getLeft() 
		||
		mouse["x"] > (obj.getLeft()+obj.getWidth())
		||
		mouse["y"] < (obj.getTop() - 20)
		||
		mouse["y"] > ((obj.getTop())+(obj.getHeight()))
	) {
		if (!fadeInHandler) resetSecondaryTop();
	}
}

function setSecondaryObj(id,pid,active,counter) {
	setSecondaryItem(0,id,"","","","","","",pid,active,counter);
}


function setSecondaryItem(print,id,divclass,texttransform,mov,mou,link,name,pid,active,counter) {

	if (print == 1) {
		document.write('<div id="' + id + '" ');
		document.write('class="' + divclass + '" ');
		document.write('style="text-transform:' + texttransform + '" ');
		document.write('onmouseover="' + mov + '" ');
		document.write('onmouseout="' + mou + '" ');
		document.write('onclick="location.href=\'front_content.php' + link + '\'" ');
		document.write('><a href=front_content.php' + link + '" onclick="return false;">' + name + '</a>');
		document.write('</div>');
	}
	counter = ''+ counter +'';
	m[''+ counter +''] = new LayerObject(id);
	m[''+ counter +''].pid = pid;
	m[''+ counter +''].childrens = new Array();
	m[''+ counter +''].active = active;
	
	if (m[''+ counter +''].pid != m['0'].pid && m[''+ counter +''].active == 0 && show_all == 0) {
		m[''+ counter +''].cut();
	}
}




window.onload = init;


