/***************************************************************
*
*  JavaScript DHTML layer menu
*
* $Id: jsfunc.layermenu.js 3439 2008-03-16 19:16:51Z flyguide $
*
*
*
*  Copyright notice
*
*  (c) 1998-2008 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_index = 0
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();
var actimage = 0;


function swapimages(obj,num) {

	cs2('#teaserimage'+obj+actimage).clearQueue().stop(true,true);

  var mlink = cs2('#teasermenu'+obj+num).attr('href');

	//cs2('#teaserheader'+obj+num).appendTo(cs2('#teaserimage'+obj+num));
	//cs2('#teasertext'+obj+num).appendTo(cs2('#teaserimage'+obj+num));
	//if(jQuery.contains(cs2('#teaserimage'+obj+num),cs2('#teaserdata'+obj+num))) {
		cs2('#teaserdata'+obj+num).appendTo(cs2('#teaserimage'+obj+num));	
		cs2('#teasermenu'+obj+num).addClass('tactive');
		cs2('#teasermenu'+obj+num).blur();

	//cs2('.mainteaserbuttontemp').appendTo(cs2('.mainteaserbutton'));
		cs2('#teaserbutton'+obj+num).appendTo(cs2('#teaserimage'+obj+num));
		cs2('#teaserbutton'+obj+num).wrap('<div></div>');
		cs2('#teaserbutton'+obj+num).parent().attr('class','mainteaserbutton');
	//}

		cs2('#teaserbutton'+obj+num).wrap('<a></a>');
		cs2('#teaserbutton'+obj+num).parent().attr('href',mlink);

	

	cs2('#teaserbutton'+obj+actimage).unwrap();
	//cs2('#teaserbutton'+obj+actimage).hide();
	
	if(actimage != num && actimage > 0)
	{

		cs2('#teasermenu'+obj+actimage).removeClass('tactive');
		if(jQuery.browser.msie &&  jQuery.browser.version < 7)	{
				//cs2('#teaserimage'+obj+actimage).hide();
				//cs2('#teaserimage'+obj+num).show();

			cs2('#teaserdata'+obj+actimage).hide();
			cs2('#teaserbutton'+obj+actimage).hide();			
			cs2('#teaserdata'+obj+num).hide();
			cs2('#teaserbutton'+obj+num).hide();						

	 		cs2('#teaserimage'+obj+actimage).clearQueue().stop(true,true).fadeOut('slow',function(){
				cs2('#teaserimage'+obj+num).removeAttr('style').hide().fadeIn('slow',function(){
			cs2('#teaserdata'+obj+num).show();
			cs2('#teaserbutton'+obj+num).show();								
					
					});
			});					
				
		}
		else {	
				cs2('#teaserimage'+obj+actimage).clearQueue().stop(true,true).fadeOut('slow',function(){
				cs2('#teaserimage'+obj+num).removeAttr('style').hide().fadeIn('slow',function(){});
			});	
		}	

	}
	else {

	 	//cs2('#teaserimage'+obj).fadeOut(500, function (){
		if(jQuery.browser.msie &&  jQuery.browser.version < 7)	{
			cs2('#teaserdata'+obj+num).hide();
			cs2('#teaserbutton'+obj+num).hide();	
			cs2('#teaserimage'+obj+num).removeAttr('style').hide().fadeIn('slow',function(){
				cs2('#teaserdata'+obj+num).show();
				cs2('#teaserbutton'+obj+num).show();												
			});			
			
		}
		else {	
			cs2('#teaserimage'+obj+num).removeAttr('style').hide().fadeIn('slow',function(){});
	}
			//cs2('#teaserimage'+obj+num).show();
		//});	

	}

	actimage = num;	


	return false;
}
	
function fnFixPng() {

		cs2('img[src$=.png]','.mainteaserlayer').each(function(index,obj) {

						var src = cs2(obj).attr('src');
						var ow = cs2(obj).width();
						var oh = cs2(obj).height();
						
				
						//if(ow > 0)
							//cs2(obj).width(500);
						//if(oh > 0)
							//cs2(obj).height(00);						
						
						//if(cs2(obj).attr('width') != 0 && cs2(obj).attr('height') != 0)
							//cs2(obj).attr('style','width:'+ow+'px; height:'+oh+'px;');
						//if(cs2(obj).attr('height') != 0)
							//cs2(obj).attr('style','height:'+cs2(obj).attr('height')+'px');			
					
					if(ow > 0 || oh > 0) {
						cs2(obj).attr('style','width: '+ow+'px; height: '+oh+'; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")');
						cs2(obj).attr('src','fileadmin/templates/pics/clear.gif');
					}

		});
		
		cs2('a[id^=teasermenu]','.mainteasermenu').each(function(index,obj) {
			
						var src = cs2(obj).css('backgroundImage');
						var len = cs2(obj).css('backgroundImage').length;
						
						//.substring(5,cs2(obj).attr('style.backgroundImage').length-2);
						var src = src.substring(4,len-1);

						var ow = cs2(obj).width();
						var oh = cs2(obj).height();
						//if(!cs2(obj).hasClass('tactive'))
							if(ow > 0 || oh > 0) {
								cs2(obj).attr('style','width: '+ow+'px; height: '+oh+'; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")');
								cs2(obj).attr('style.backgroundImage','url(fileadmin/templates/pics/clear.gif)');
							}
			
		});

};
	

	//browsercheck...
function GL_checkBrowser(){
	this.dom= (document.getElementById);

		// detect version (even if Opera disguises as Mozilla or IE)
	if (op = (navigator.userAgent.indexOf("Opera")>-1))	{
		switch (parseInt(navigator.userAgent.substr(navigator.userAgent.indexOf("Opera")+6)))	{
			case 5:
			case 6:
				this.op5= true;
				break;
			case 7:
			case 8:
				this.op7= true;
				break;
			default:
				this.op4= true;
		}
	}
	this.konq=  (navigator.userAgent.indexOf("Konq")>-1);
	this.ie4= (document.all && !this.dom && !op && !this.konq);
	this.ie5= (document.all && this.dom && !op && !this.konq);
	this.ie6= (this.ie5);
	this.ns4= (document.layers && !this.dom && !this.konq);
	this.ns5= (!document.all && this.dom && !op && !this.konq);
	this.ns6= (this.ns5);
	this.bw=  (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.konq || op);

	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="";
	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.op5)?this.css.left:this.el.offsetLeft;
	this.y= (bw.ns4||bw.op5)?this.css.top:this.el.offsetTop;
	this.height= (bw.ie4||bw.ie5||bw.ns6||bw.op7)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.op4?this.css.pixelHeight:0;
	this.width= (bw.ie4||bw.ie5||bw.ns6||bw.op7)?this.el.offsetWidth:bw.ns4?this.ref.width:bw.op4?this.css.pixelWidth:0;

	return this;
}
function GL_initLayers() {
	if(bw.ns4) document.captureEvents(Event.MOUSEMOVE);
	GL_timeout_func();
	//GLV_index = 1;
	GL_setindex();
	
}
function GL_updateTime(WMid)	{
	GLV_date = new Date();
	GLV_timeout[WMid] = GLV_date.getTime();
}

function GL_setindex() {
	x= document.getElementById("gmenu_layer").childNodes;
	for (i=0;i<x.length;i++)
	if(x[i].className != 'menuwrapact')
		x[i].style.zIndex = i;
	else x[i].style.zIndex = x.length;

}

function GL_changeindex(obj) {

 	x= document.getElementById("gmenu_layer").childNodes;
	
	if(obj.parentNode.parentNode.nextSibling)
	{

		if(obj.parentNode.parentNode.nextSibling.style.zIndex == x.length && obj.parentNode.parentNode.nextSibling.className != 'menuwrapact')
		{
			obj.parentNode.parentNode.style.zIndex = x.length+1;

			if(obj.parentNode.parentNode.nextSibling.lastChild.id == "menuspeacialright")
			{
				obj.parentNode.parentNode.nextSibling.style.zIndex = x.length-1;				
				var myobj = document.getElementById("menuspeacialright");
				obj.parentNode.parentNode.nextSibling.removeChild(myobj);
			}

		}
		else { 

			obj.parentNode.parentNode.style.zIndex = x.length;
			if(obj.parentNode.parentNode.previousSibling && obj.parentNode.parentNode.previousSibling.lastChild.id == "menuspeacialleft")
			{

				obj.parentNode.parentNode.previousSibling.style.zIndex = x.length-1;				
				var myobj = document.getElementById("menuspeacialleft");
				obj.parentNode.parentNode.previousSibling.removeChild(myobj);
			}
				
		}
			
		if(obj.parentNode.parentNode.nextSibling.className == 'menuwrapact') {
			obj.parentNode.parentNode.nextSibling.style.zIndex = x.length-1;
			if(obj.parentNode.parentNode.nextSibling.nextSibling)
				obj.parentNode.parentNode.nextSibling.nextSibling.style.zIndex = x.length-2;

			if(!document.getElementById("menuspeacialright"))
			{
				mydiv = document.createElement('div');
				mydiv.id = 'menuspeacialright'; 			
				obj.parentNode.parentNode.appendChild(mydiv);
			}
		
			
		}
	}


	
	if(obj.parentNode.parentNode.previousSibling)
	{
		if(obj.parentNode.parentNode.previousSibling.className == 'menuwrapact') {
			
			obj.parentNode.parentNode.style.zIndex = x.length+1;

			if(!document.getElementById("menuspeacialleft"))
			{
				mydiv = document.createElement('div');
				mydiv.id = 'menuspeacialleft'; 			
				obj.parentNode.parentNode.appendChild(mydiv);
			}
		}
	}
	
	
	if(obj.parentNode.parentNode.className == 'menuwrapact') {
		obj.parentNode.parentNode.style.zIndex = x.length;
		if(obj.parentNode.parentNode.nextSibling)
			obj.parentNode.parentNode.nextSibling.style.zIndex = x.length-1;
	}
	
	

}


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 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 layerObjtemp = document.getElementById(id);		

		GLV_curLayerHeight[WMid] = layerObjtemp.clientHeight;
		
		//GLV_curLayerHeight[WMid] = layerObj.height;
		GLV_curLayerWidth[WMid] = layerObj.width;
		GLV_curLayerX[WMid] = layerObj.x;
		GLV_curLayerY[WMid]  = layerObj.y;
		GLV_currentLayer[WMid] = id;
		GLV_hasBeenOver[WMid]=0;

	}
/*	
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		var ieversion=new Number(RegExp.$1);
		if(ieversion < 7) {
			supersleight.run();
		} 
}	
	*/
}

	//Capturing mousemove
function GL_getMouse(e) {
	
cs2(function() {
	cs2(document).ready(function(){	
	
 if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
 
  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      GLV_x = e.pageX;
      GLV_y = e.pageY;
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
    	if(document.documentElement.scrollLeft)
      	GLV_x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      else if(document.body.scrollLeft) 
      			GLV_x = e.clientX + document.body.scrollLeft;
      	
      if(document.documentElement.scrollTop)
      	GLV_y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
      else 	if(document.body.scrollTop) 
      				GLV_y = e.clientY + document.body.scrollTop;
    }
    
  }
  
});
});
	
	//GLV_x= (bw.ns4||bw.ns5)?e.pageX:(bw.ie4||bw.op4)?event.x:(event.x-2)+document.body.scrollLeft;
	//GLV_y= (bw.ns4||bw.ns5)?e.pageY:(bw.ie4||bw.op4)?event.y:(event.y-2)+document.body.scrollTop;
}


function GL_mouseMoveEvaluate(WMid)	{

cs2(function() {
	cs2(document).ready(function(){		
	
var menulayer = document.getElementById("gmenulayer");
var menulayerx = menulayer.offsetLeft;
var menulayery = menulayer.offsetTop;

	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_x+GLV_gap[WMid]-GLV_curLayerX[WMid]-menulayerx <0 || GLV_y+GLV_gap[WMid]-GLV_curLayerY[WMid]-menulayery <0 || GLV_curLayerX[WMid]+GLV_curLayerWidth[WMid]+GLV_gap[WMid]-(GLV_x-menulayerx) <0 || GLV_curLayerY[WMid]+GLV_curLayerHeight[WMid]+GLV_gap[WMid]-(GLV_y-menulayery) <0)	{
			if (GLV_hasBeenOver[WMid])	{
				GLV_doReset[WMid]=true;

				GLV_index = 1;
			
				
			}
		} 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;


if(	GLV_index)
{
	x= document.getElementById("gmenu_layer").childNodes;
	for (i=0;i<x.length;i++)
	{
		if(x[i].className != 'menuwrapact')
			x[i].style.zIndex = i;
	}
	GLV_index = 0;
}
	
}

function GL_iframer(WMid,id,state)	{
	if (bw.ie4||bw.ie5) {
		ifrmObj = bw.ie4?document.all["Iframe"+WMid]:document.getElementById("Iframe"+WMid);
		if (state) {
			parentObj = bw.ie4?document.all[id]:document.getElementById(id);
			ifrmObj.style.filter='Alpha(opacity=0)';
			ifrmObj.style.width = parentObj.offsetWidth + "px";
			ifrmObj.style.height = parentObj.offsetHeight + "px";
			ifrmObj.style.left = parentObj.offsetLeft + "px";
			ifrmObj.style.top = parentObj.offsetTop + "px";
			ifrmObj.style.zIndex = parentObj.style.zIndex-1;
			ifrmObj.style.display = "";
		}
		else ifrmObj.style.display = "none";
	}
}

