/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lib.js for Superlumpi (or whatever their name is)

Author:			manfred.schneiderbauer@world-direct.at
Version:		0.1
Last Changed	2003-09-11

This project needs a W3 DOM compliant browser for most JS functions to execute.
Users of non-DOM browsers will therefor be presented with an informative popup on every page load.
Currently supported: MSIE 5.0 and up (Win only), Gecko 1.0 and up, Opera 7 and up

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/

/*_______________________________________________________________________
PAGE INITIALIZATION FUNCTIONS
_______________________________________________________________________*/

// Return browser identity values
// Used by almost all functions in this library
// based on b() Version: 1.1, Date: 2002-11-27.
function b(whichValue) {
var isDOM=document.getElementById ? true:false;
var isNN4=document.layers ? true:false;
var isIE4=document.all ? true:false;
var isOpr=false;
var isOpr7up=false;
var isLinux=false;
var isIE55up=false;
var isMac=false;
var isGecko=false;
var GeckoVersion='';
if (isDOM&&isIE4) {var isIE5up=true; isIE4=false; isDOM=false;} else {var isIE5up=false;}
if ((isIE5up)&&(navigator.appVersion.indexOf('MSIE 5.0')==-1)) {isIE55up=true;}
if (navigator.userAgent.indexOf('Opera')!=-1) {isOpr=true;isDOM=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;}
if (navigator.userAgent.indexOf('Linux')!=-1) {isLinux=true;}
if (isOpr&&(navigator.userAgent.indexOf('Opera 0')==-1&&navigator.userAgent.indexOf('Opera 1')==-1&&navigator.userAgent.indexOf('Opera 2')==-1&&navigator.userAgent.indexOf('Opera 3')==-1&&navigator.userAgent.indexOf('Opera 4')==-1&&navigator.userAgent.indexOf('Opera 5')==-1&&navigator.userAgent.indexOf('Opera 6')==-1)){isOpr7up=true;}
if(isOpr&&(navigator.userAgent.indexOf('Opera/0')!=-1||navigator.userAgent.indexOf('Opera/1')!=-1||navigator.userAgent.indexOf('Opera/2')!=-1||navigator.userAgent.indexOf('Opera/3')!=-1||navigator.userAgent.indexOf('Opera/4')!=-1||navigator.userAgent.indexOf('Opera/5')!=-1||navigator.userAgent.indexOf('Opera/6')!=-1)){isOpr7up=false;}
if (navigator.userAgent.indexOf('Mac')!=-1){isMac=true;}
if (navigator.userAgent.indexOf('Gecko')!=-1){isGecko=true;}
if (isGecko){GeckoVersion=navigator.userAgent.substring(navigator.userAgent.indexOf('rv:')+3,navigator.userAgent.indexOf('rv:')+6);}
var whichValueValue=eval(whichValue);
return(whichValueValue);
}

// Set browser variables
/* 23.07.2009   mharesi   Browsercheck removed */

var isDOM=b('isDOM');var isNN4=b('isNN4');var isIE4=b('isIE4');var isOpr=b('isOpr');var isLinux=b('isLinux');var isIE5up=b('isIE5up');var isIE55up=b('isIE55up');var isOpr7up=b('isOpr7up');var isMac=b('isMac');var isGecko=b('isGecko');var GeckoVersion=b('GeckoVersion');
if(isIE5up&&!isIE55up){var undefined='undefined';} // define undefined on IE5.0

// Fork out the not supported browsers
var browserIsValid=false;
if(isMac)									// Mac
	{
	if(isGecko&&GeckoVersion>0.9){browserIsValid=true;}
	if(isOpr7up){browserIsValid=true;}
	} else {								// non-Mac
	if(isGecko&&GeckoVersion>0.9){browserIsValid=true;}
	if(isIE5up||isIE55up){browserIsValid=true;}
	if(isOpr7up){browserIsValid=true;}
}

/*if(!browserIsValid){alert('Sorry, aber Sie verwenden einen alten und/oder nicht unterstützten Browser.\n\nUnterstützt werden unter Microsoft Windows: Internet Explorer 5.0 und höher, Netscape 7 und höher sowie alle Gecko-basierten Browser mit Mozilla/Gecko 1.0 und höher, Opera 7 und höher. Unter Mac OS und unter Unix/Linux: Netscape 7 und höher sowie alle Gecko-basierten Browser mit Mozilla/Gecko 1.0 und höher, Opera 7 und höher.\n\nSie können mit diesem Browser fortfahren, es ist jedoch wahrscheinlich, daß vereinzelt Fehler auftreten und Funktionen nicht genutzt werden können.');}*/

// Change a menu item's status
function menu_LinkSwap(status,menuItemId,cell){
if(status)
	{
	document.getElementById(menuItemId).onmouseout=stickyhide; // set event hiding handler for item
	document.getElementById(menuItemId).onmouseover=null;
	cell.style.backgroundColor='#B9B28D'; // change bg color
	} else {
	cell.style.backgroundColor='white'; // change bg color
	document.getElementById(menuItemId).onmouseout=null;
	document.getElementById(menuItemId).onmouseover=stickyhide; // reverse hiding event handler for item
	}
}

// Initialize the menu positioning
function menu_Position(){
var xOffset=0;
var width=0;
window.menuXOffset=0;
if(!document.body.clientWidth||document.body.clientWidth==0) // if clientWidth is not known or 0 (Moz1.0-1.2)...
	{
	if(window.innerWidth) //...but innerWidth is known...
		{
		width=window.innerWidth; //...use innerWidth...
		}
	} else {
	width=document.body.clientWidth; //...else use clientWidth
	}
// calc the left gap according to the content width
window.menuXOffset=Math.ceil(width/2-360);
window.status=window.menuXOffset;
}

function menu_Init(){
window.Style="'','black','','','','','','','','','fixed','sticky','','','*','',1,1,window.menuXOffset,93,"+window.menuTransition+","+window.menuTransitionDuration+",'','',''";
// define the HTML fragments
var menuHTMLStart1='<span id="'
var menuHTMLStart2='"><table class="menuOuterTable" width="'+menuMinWidth+'" cellspacing="1" cellpadding="0"><tr><td><table width="100%" cellspacing="0" cellpadding="1" class="menuTable">';
var menuHTMLRow1='<tr><td width="100%" valign="middle" class="menuTd" onmouseover="menu_LinkSwap(true,*'
var menuHTMLRow2='*,this);" onmouseout="menu_LinkSwap(false,*'
var menuHTMLRow3='*,this);"><a class="menulink" href="'
var menuHTMLRow4='">'
var menuHTMLRow5='</a></td></tr>';
var menuHTMLEnd='</td></tr></table></span>';
window.Text=new Array();
// loop through each page-defined menu item and define its 'Text' window variable
var itemArray=new Array;
var thisItemArray=new Array;
var thisText=''
var thisURL=''
for(var menus=0;menus<=window.menuId.length-1;menus++)
	{
	window.Text[menus]=menuHTMLStart1+window.menuId[menus]+menuHTMLStart2; // append the start block
	itemArray=window.menuItems[menus].split('|');
	for(var items=0;items<=itemArray.length-1;items++)
		{
		thisItemArray=itemArray[items].split(',');
window.Text[menus]=window.Text[menus]+menuHTMLRow1+window.menuId[menus]+menuHTMLRow2+window.menuId[menus]+menuHTMLRow3+encodeURI(thisItemArray[1])+menuHTMLRow4+thisItemArray[0]+menuHTMLRow5;
		}
	while(window.Text[menus].indexOf('*')!=-1){window.Text[menus]=window.Text[menus].replace("*","\\'");} // replace asteriks by escaped apostrophs
	window.Text[menus]="['','"+window.Text[menus]+menuHTMLEnd+"']"; // append the end block
	}

menu_Position(); // call the positioner once
}

/*
___________________________________________________________________________
News
News Clip Functions for the world-direct.at Corporate Web Site
_______________________________________________________________________________

Author:			geet from framefab
Date:			2001-05-01
Compiled by:	michaell@world-direct.com
Last modified:	2002-04-30
by:				manfred.schneiderbauer@world-direct.at

*/

var upH = 9; // Height of up-arrow
var upW = 13; // Width of up-arrow
var downH = 9; // Height of down-arrow
var downW = 13; // Width of down-arrow
var dragH = 17; // Height of scrollbar
var dragW = 13; // Width of scrollbar
var scrollH = 430; // Height of scrollbar
var speed = 4; // Scroll speed

// And now... go to the bottom of the page...

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){

	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startY = (mouseY - dragT);
	
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))) {
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){

	var ns6 = document.getElementById ? true:false;
	var ns = document.layers ? true:false;
	var ie = document.all ? true:false;
	if (navigator.userAgent.indexOf('Opera')!=-1) {var opr = true;} else {var opr = false;}
	
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);
		
		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie||opr)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads content layer top
function getT(){

	var ns6 = document.getElementById ? true:false;
	var ns = document.layers ? true:false;
	var ie = document.all ? true:false;
	if (navigator.userAgent.indexOf('Opera')!=-1) {var opr = true;} else {var opr = false;}
	
	if(ie||opr)
		contentT = document.all.news.style.pixelTop;
	else if(ns)
		contentT = document.contentClip.document.news.top;
	else if(ns6)
		contentT = parseInt(document.getElementById("news").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){

	var ns6 = document.getElementById ? true:false;
	var ns = document.layers ? true:false;
	var ie = document.all ? true:false;
	if (navigator.userAgent.indexOf('Opera')!=-1) {var opr = true;} else {var opr = false;}
	
	if(ie){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(opr){ 
		mouseY = e.y + pageYOffset;
		mouseX = e.x + pageXOffset;
	}
	else if(ns || ns6){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// Moves the layer
function moveTo(){

	var ns6 = document.getElementById ? true:false;
	var ns = document.layers ? true:false;
	var ie = document.all ? true:false;
	if (navigator.userAgent.indexOf('Opera')!=-1) {var opr = true;} else {var opr = false;}
	
	if(ie||opr){
		document.all.news.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(ns){
		document.contentClip.document.news.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(ns6){
		document.getElementById("news").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
}

// Scrolls up
function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(contentT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){

	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			
			moveTo();

			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to reposition page elements @ nn4
function reloadPage(){
	location.reload();
}

// Initializes the events for the News Clip
function eventLoader(){

	var ns6 = document.getElementById ? true:false;
	var ns = document.layers ? true:false;
	var ie = document.all ? true:false;
	if (navigator.userAgent.indexOf('Opera')!=-1) {var opr = true;} else {var opr = false;}
	
	if (ie || opr) {

		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = parseInt(document.all.news.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
		
		if (opr) {contentH = document.all.news.offsetHeight;}
	}
	else if (ns) {
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerT = document.ruler.top;
		// Height of content layer and clip layer
		contentH = document.contentClip.document.news.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
		
	}
	else if (ns6) {
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left) - 7; // substract hard coded value to solve mouse cursor positioning problem in browsers != IE
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left) - 7; // substract hard coded value to solve mouse cursor positioning problem in browsers != IE
		downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left) - 7; // substract hard coded value to solve mouse cursor positioning problem in browsers != IE
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("news").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
		document.getElementById("news").style.top = 0 + "px";
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	window.onresize = reloadPage;
	if(ns){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		
	}
	document.onmousedown = down;
	//document.onmousemove = move;
	document.onmouseup = up;
}

/*
End of News Functions
*/

//
// centerNews
// positions the news scroller
//
function centerNews(oldDocWidth) {
if (isNN4) {
    		 var docWidth = self.innerWidth;
  			} 
else if (isDOM) {
    		 var docWidth = window.innerWidth;
			 var docWidth2 = document.documentElement.offsetWidth;
			 var diffDocWidth = docWidth - docWidth2;
			 
	    	 if (diffDocWidth==0) { docWidth = docWidth + 16 }
  			} 
else if (isIE4||isIE5up||isOpr) {
   			 var docWidth = document.body.clientWidth;
 			}
			 
  		var x = docWidth/2;
		var newx = x+356;
		var contentx = x+150;
		
		if (isDOM) {
				document.getElementById("up").style.left = newx-10 + "px";
				document.getElementById("down").style.left = newx-10 + "px";
				document.getElementById("drag").style.left = newx-10 + "px";
				document.getElementById("scrollbar").style.left = newx-10 + "px";
				document.getElementById("ruler").style.left = newx-10 + "px";	
				document.getElementById("contentClip").style.left = contentx-10 + "px";
				}
			
		else if (isNN4) {
  				document.layers['up'].left = newx-10;
  				document.layers['down'].left = newx-10;
  				document.layers['drag'].left = newx-10;
  				document.layers['scrollbar'].left = newx-10;
  				document.layers['ruler'].left = newx-10;
  				document.layers['contentClip'].left = contentx-10;
				}
				
		else if (isIE4||isIE5up||isOpr) {
				document.all["up"].style.pixelLeft = newx;		
				document.all["down"].style.pixelLeft = newx;	
				document.all["drag"].style.pixelLeft = newx;		
				document.all["scrollbar"].style.pixelLeft = newx;	
				document.all["ruler"].style.pixelLeft = newx;		
				document.all["contentClip"].style.pixelLeft = contentx;		
				}

// detect width change on opera (who does not know onresize) and reload the page if necessary
// (no check on existing URL parameters, if there are any, they will be lost here!)

		// if we're running opera, the old width is not undefined and the widths have changed...

		if ( (isOpr)&&(oldDocWidth!=undefined)&&(oldDocWidth!=docWidth) ) {
			var locationString;
			var locationRandom = String(Math.random(1)); // generate a random value

			locationRandom = locationRandom.substring(2,locationRandom.length); // format to 16 single numbers
			locationString = location.href.substring(0,location.href.indexOf('?'-1)) + '?nocache=' + locationRandom; // construct the new location string
			location.href = locationString; // change to the new born location
	
			}
							
if (isOpr||isDOM) {window.setTimeout('centerNews('+docWidth+')',500);}
				
}

//
// Reloads the page once @ NN and Opera; can be called from any page in the body's onload; preserves the URL parameters
//
function reloadOnce() {

/*
var isDOM = document.getElementById ? true:false;
var isNN4 = document.layers ? true:false;
var isIE4 = document.all ? true:false;
var isOpr = false;
if (isDOM && isIE4) {var isIE5up = true; isIE4 = false; isDOM =false;} else {var isIE5up = false;}
if (navigator.userAgent.indexOf('Opera') != "-1") {isOpr = true; isDOM=false; isNN4=false; isIE4=false; isIE5up=false;}
*/

// if it's NN4 or Opera and there's no 'reflown' flag set...
if ((location.search.indexOf('reflown')==-1)&&((isNN4)||(isOpr)) )
	{
	// ...and there's no parameter given at all, set the reflown flag as first parameter.
	if (location.search=='')
		{
		location.href=location.href+'?reflown';
		} else {
		// ...or, if already parameters are given, just add the reflown flag.
		location.href=location.href+'&reflown';
		}
	}
}