var fenster_anfahrt;var fenster_tour;var fensterlein;var fenstersteuer;var fensterveranstaltungen;var fenstereuropa;var fensterintro;var eigenschaften;var datei;var ort;var weite;var hoehe;fenster_anfahrt="zu";fensterlein="zu";fenstersteuer="zu";fensterveranstaltungen="zu";fenstereuropa="zu";fenster_tour="zu";fensterintro="zu";var colorlink;var weightlink;var colorhoover;var weighthoover;colorlink="#333333";weightlink="normal";colorhoover="#999999";weighthoover="normal";var lastclickeddivzn;var i;var bw;var resizeDuration;var ObjectRange;var schonmaloffen;var widthFlash;var heightFlash;var srcFlash;var srcImg;var next_month;
var ar = new Array();
var preloaded = false;

var imageNameRoot = "_logogif.gif";
var cntImages = 4;
var altBlock = 0;
var altEbene = 0;
var altId = 0;
var altWert = 0;
var clicked = 0;
var clicked3 = 0;
var clickedEbene = 0;

var cnt_search = 0;

function warten(prmSec)
  {
  prmSec *= 1000;
  var eDate = null;
  var eMsec = 0;
  var sDate = new Date();
  var sMsec = sDate.getTime();

  do {
      eDate = new Date();
      eMsec = eDate.getTime();

  } while ((eMsec-sMsec)<prmSec);
  skipflash();
}

function startAni()
{
    preload('images/1_logogif.gif', 'images/2_logogif.gif', 'images/3_logogif.gif', 'images/4_logogif.gif', 'images/1_logogif.gif');
    i = 0;
    doAni();
}

function doAni()
{   
    if(i < ar.length){
        document.getElementById("aniLog").src = ar[i].src;
        i++;
        window.setTimeout("doAni("+i+")", 250);
    } 
}

function zeigen(wert)
{
if(wert.substr(0,5)=='link_'){wert=wert.substr(5,wert.length);}
    
    startAni();
	/*
	 * "wert" (spaeter "echtWert") ist zunaechst ggf. "4-stellig" (z.B. "3x1x20x1"); dies wird so fuer die 
	 * Bookmark- bzw. "Zurueck"-Funktionalitaet benoetigt. 
	 * Fuer die Darstellung der Navigation werden nur die ersten 3 Stellen benoetigt.
	 * Diese stehen dann bald als "wert" zur Verfuegung.
	 */
    var echtWert = wert
	wert = wert.replace(/^(\d+_\d+_\d+)(_\d+)?$/, '$1');
    var daten = wert.split("_");
    
    var parentElem = document.getElementById("navigation");
    var Knoten = parentElem.firstChild;
    
    var start = 0;
    
 
	// In einem Schritt mehrere Ebenen aufklappen
	// (via rekursiven Aufruf)
 	if (daten[1] > (1*altEbene + 1) 
 		 || (daten[1]>1 && daten[0]!=altBlock) ) {
		var prevBlockA = getPreviousBlockATag('link_'+wert);
		zeigen(prevBlockA.id)
 	}
 	
    if(altEbene >= daten[1]){
        
        var zuKnoten = Knoten;
        
        while (zuKnoten != null) {
            if(zuKnoten.nodeType == 1 && zuKnoten.nodeName=="A"){
                var child = zuKnoten.getAttribute("id");
                var temp_child = child.substr(0,3);
                if(temp_child=='img'){var child = child.substr(4, child.length);}
                if(temp_child=='lin'){var child = child.substr(5, child.length);}
                var childDaten = child.split("_");
                
                if(childDaten[1] >= daten[1] && document.getElementById('link_'+child)){
                    document.getElementById('link_'+child).style.color = colorlink;
                    document.getElementById('link_'+child).style.fontWeight = weightlink;
                    document.getElementById('img_'+childDaten[2]).src = "images/"+childDaten[1]+"_off.gif";
                }
                
                if(childDaten[1] > daten[1] && document.getElementById('link_'+child)){
                   	document.getElementById('link_'+child).style.display = "none";
                   	document.getElementById('img_'+childDaten[2]).style.display = "none";
                }
            }
            zuKnoten = zuKnoten.nextSibling;
        }
    }else{
        if(altId > 0){
            if(daten[1] == 4){
                document.getElementById('img_'+altId).src = "images/"+altEbene+"_halfoff.gif";
            }else{
                document.getElementById('img_'+altId).src = "images/"+altEbene+"_off.gif";
            }
        }
    }
    
    if (document.getElementById('link_'+wert)) {
	    document.getElementById('link_'+wert).style.color = colorhoover;
	    document.getElementById('link_'+wert).style.fontWeight = weighthoover;
	    document.getElementById('img_'+daten[2]).src = "images/"+daten[1]+"_on.gif";
	}
    
    while (Knoten != null) {
      if(Knoten.nodeType == 1 && Knoten.nodeName=="A"){
        var child = Knoten.getAttribute("id");
        var temp_child = child.substr(0,3);
        if(temp_child=='img'){var child = child.substr(4, child.length);}
        if(temp_child=='lin'){var child = child.substr(5, child.length);}

        var childDaten = child.split("_");

            if(start > 0 && start == childDaten[1] && document.getElementById('link_'+child)){
                if(altWert != wert){
                    document.getElementById('link_'+child).style.display = "block";
                    document.getElementById('img_'+childDaten[2]).style.display = "block";
                }else{
                    document.getElementById('link_'+child).style.display = "none";
                    document.getElementById('img_'+childDaten[2]).style.display = "none";
                }
            }else{
                if(childDaten[1] == start-1){  
                    start = 0;
                }
            }
                
                if(daten[0] == childDaten[0]){
                    if(daten[2] == childDaten[2]){
                        start = parseInt(daten[1])+1;
                    }
                }
      }
      Knoten = Knoten.nextSibling;
    }
    altBlock = daten[0];
    altEbene = daten[1];
    altId = daten[2];

    if(altWert && (altWert == echtWert)){
        altWert = 0;
    }else{
        altWert = echtWert;
    }
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// DIESE FUNKTIONEN WERDEN BENUTZT, UM MEHRERE EBENEN IN EINEM SCHRITT AUFZUKLAPPEN
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function getPreviousBlockATag(wert)
{
if(wert.substr(5,5)=='link_'){wert=wert.substr(5,wert.length);}
	var blockAlt = getBlock(wert);
	var blockNeu = blockAlt;
	var	elem = document.getElementById(wert);
	var notbremse = 0;
	while (blockNeu == blockAlt && notbremse++ < 1000) {
		elem = getPreviousATag(elem);
		blockNeu = getBlock(elem.id);
	}
	return elem;
}
function getPreviousATag(elem)
{
	var tagname = "";
	var notbremse = 0;
	var prev = elem;
	while (tagname != "A" && notbremse++ < 1000) {
		prev = prev.previousSibling;
		tagname = prev.nodeName;
	}
	return prev;
}
function getBlock(idx) { return idx.replace(/^\d+_(\d+)_\d+(_\d+)?$/, '$1'); }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (ENDE - DIESE FUNKTIONEN WERDEN BENUTZT, U... )

function changeimg(lid,action)
{
    var daten = lid.split("_");
    
    var block = daten[0];
    var ebene = daten[1];
    var wert = daten[2];
    
    if(action == "in" && wert != clicked){
        if(clicked3 > 0){
            if(wert != clicked3){
                document.getElementById('img_'+wert).src = "images/"+ebene+"_hover.gif";
                document.getElementById('link_'+lid).style.color = colorhoover;
                document.getElementById('link_'+lid).style.fontWeight = weighthoover;
            }else{
                document.getElementById('img_'+clicked3).src = "images/3_halfhover.gif";
                document.getElementById('link_'+lid).style.color = colorhoover;
                 document.getElementById('link_'+lid).style.fontWeight = weighthoover;
           }
        }else{
            document.getElementById('img_'+wert).src = "images/"+ebene+"_hover.gif";
            document.getElementById('link_'+lid).style.color = colorhoover;
                document.getElementById('link_'+lid).style.fontWeight = weighthoover;
        }
    }else if(action == "out" && wert != clicked){
        if(clicked3 > 0){
            if(wert != clicked3){
                document.getElementById('img_'+wert).src = "images/"+ebene+"_off.gif";
                document.getElementById('link_'+lid).style.color = colorlink;
                document.getElementById('link_'+lid).style.fontWeight = weightlink;
            }else{
                document.getElementById('img_'+clicked3).src = "images/3_halfoff.gif";
            }
        }else{
            document.getElementById('img_'+wert).src = "images/"+ebene+"_off.gif";
            document.getElementById('link_'+lid).style.color = colorlink;
            document.getElementById('link_'+lid).style.fontWeight = weightlink;
         }
    }else if(action == "click"){
        
        if(ebene > 3){
            clicked3 = clicked;
        }else{
            clicked3 = 0;
        }
        
        clicked = wert;
        clickedEbene = ebene;
    }
}

function preload()
{
	if (preloaded) { return; }
    if (!document.images) {
        return;
    }
	preloaded = true;

    ar = new Array();
    //arguments = preload.arguments;
    arguments = arguments;

    for (var i=0; i<arguments.length; i++) {
        ar[i] = new Image();
        ar[i].src = arguments[i];
    }
}

function getAktuelles(urli)
{
    dA = window.open(urli,'Aktuelles','width=625,height=600,left=100,top=100,scrollbars=yes');
    dA.focus();	
}

function popupCheck()
{
	
	dF = window.open("http://www.advision.de/praxis-check/popup/index.html","PraxisCheck","width=800,height=600,scrollbars=no");
	dF.moveTo(0,screen.height0);
	dF.focus();
	
}

function popupEMB()
{
	
	dEMB = window.open("http://www.advision.de/emb/index.html","EMB","width=533,height=400,scrollbars=no");
	dEMB.moveTo(300,200);
	dEMB.focus();
	
}

function popupVeranstaltungen(id)
{
	dV = window.open("content/"+id+".php","dV","width=800,height=400,scrollbars=auto");
	dV.moveTo(100,100);
	dV.focus();
}

function checkForm(formType,id_inst,bereich)
{
    var grundfarbe = "#efefef";
    var signalfarbe = "#ff9999";
    var error = "Die rot gekennzeichneten Felder sind Pflichtfelder.\nBitte füllen Sie diese aus.";
    
    
    if(formType == "depesche"){
        var pflichtfelder = new Array("firma;name", "strasse", "plz", "ort", "email");
        var felder = new Array("anrede", "grad", "vorname", "telefon", "telefax");
    }else if(formType == "newsletter"){
        var pflichtfelder = new Array("email");
        var felder = new Array();
    }else if(formType == "del_newsletter" || formType == "del_depesche"){
        var pflichtfelder = new Array("email");
        var felder = new Array();
    }
    
    for(var i=0;i<pflichtfelder.length;i++){   
        var tmp = pflichtfelder[i].split(";");
        var cnt = 0;
        
        for(var x = 0;x < tmp.length;x++){
            felder = felder.concat(tmp[x]);
            document.getElementById(tmp[x]).style.background = grundfarbe;
            if(document.getElementById(tmp[x]).value){
                if(tmp[x] == "email"){
                    if(!checkMail(document.getElementById(tmp[x]).value)){
                        if(formType == "depesche"){
                            error = "Bitte prüfen Sie Ihre E-Mail-Adresse und füllen Sie ggf. die übrigen rot gekennzeichneten Pflichtfelder.";
                        }else if(formType == "newsletter"){
                            error = "Bitte prüfen Sie Ihre E-Mail-Adresse.";
                        }
                        cnt++;
                    }
                }
            }else{
                cnt++;
            }
        }

        if(cnt == tmp.length){
            var warnings = 0;

            while(tmp[warnings] && warnings < tmp.length){
                document.getElementById(tmp[warnings]).style.background = signalfarbe;
                warnings++;
            }
            
        }
        
    }
    
    if(warnings > 0){
        alert(error);
    }else{
        var formValues = new Array();
        
        for(var y=0;y<felder.length;y++){
            if(document.getElementById(felder[y]).type == "radio"){
                for(var z=0;z<document.getElementsByName(felder[y]).length;z++){
                    if(document.getElementsByName(felder[y])[z].checked == true){
                        formValues[felder[y]] = document.getElementsByName(felder[y])[z].value;
                    }
                }
            }else{
                formValues[felder[y]] = document.getElementById(felder[y]).value;
            }
        }
        
        formValues["id_inst"] = id_inst;
        formValues["bereich"] = bereich;
        
        if(formType == "newsletter" || formType == "depesche"){
            xajax_getNewsletter(formType,formValues);
        }else if(formType == "del_newsletter" || formType == "del_depesche"){
            xajax_delNewsletter(formType,formValues);
        }
    }
    
}

function checkMail(mail)
{
    var reg = /^([a-zA-Z0-9_\.\-])+@(\[)?([a-zA-Z0-9_\.\-])*([a-zA-Z0-9]{2,})\.([a-zA-Z]{2,4}|[0-9]{1,3}\])$/;
    return reg.exec(mail);
}

function weihnachten()
{
    weite=636;
    hoehe=476;
	eigenschaften = 'top=10,left=10,screenX=10,screenY=10,width='+weite+',height='+hoehe+',menubar=no,resizable=no,scrollbars=no';
    datei = 'weihnachtsintro/20081211_flash_ETLsekt2.html';
	weihnachten = window.open(datei,'weihnachten',eigenschaften);
	return void(0);
}

function kontaktformular()
{
    g = document.getElementById('person').value;
    h = document.getElementById('mailaddy').value; 
    h1 = document.getElementById('telefono').value; 
    i = document.getElementById('nachricht').value;
    xajax_sendeKontaktformular(g,h,h1,i);
}

function rueckrufformular()
{
    a = document.getElementById('empresa').value;
    b = document.getElementById('person').value;
    c = document.getElementById('telefono').value;
    var f = document.hoheTelefonkosten, i;
    for (i=0;i<f.wann.length;i++){
        if (f.wann[i].checked==true){
            d = f.wann[i].value;
            if(i==2){
                d = d + "&nbsp;&nbsp;" + document.getElementById('termin').value;
            }else{
                d = "Termin:&nbsp;&nbsp;" + d;
            }
        }
    }
    xajax_sendeRueckrufformular(a,b,c,d);
}

function angebotsformular()
{
    a = document.getElementById('empresa').value;
    b = document.getElementById('person').value;
    c = document.getElementById('telefono').value;
    d = document.getElementById('strasse').value;
    e = document.getElementById('ortplz').value;
    e1 = document.getElementById('plzplz').value;
    var x = document.angebotserstellung, y;
    for (y=0;y<x.lohnbuero.length;y++){
        if (x.lohnbuero[y].selected==true){
            f = x.lohnbuero[y].innerHTML;
        }
    }
    g = document.getElementById('anz_mitarbeiter').value; 
    j = document.getElementById('mailaddy').value; 
    k = document.getElementById('nachricht').value;
    xajax_sendeAngebotsformular(a,b,c,d,e,e1,f,g,j,k);
}

function anfahrtskizze(ort)
{
    if (fenster_anfahrt!='zu') { fenster_anfahrt.close(); }
    if(ort=="berlin"){weite=930;hoehe=440;}
    if(ort=="neubrandenburg"){weite=930;hoehe=620;}
    if(ort=="dresden"){weite=930;hoehe=620;}
    if(ort=="halle"){weite=930;hoehe=620;}
    if(ort=="leipzig"){weite=930;hoehe=620;}
    if(ort=="erfurt"){weite=930;hoehe=620;}
    if(ort=="eschborn"){weite=930;hoehe=620;}
    if(ort=="essen"){weite=930;hoehe=620;}
	eigenschaften = 'top=10,left=10,screenX=10,screenY=10,width='+weite+',height='+hoehe+',menubar=no,resizable=yes,scrollbars=yes';
    datei = 'content/anfahrt_'+ort+'.php';
	fenster_anfahrt = window.open(datei,'fenster_anfahrt',eigenschaften);
}

function fenster_content(file,titel,bildnr,tuehpe)
{
    datei='content/fenster.php';
    if(!tuehpe){tuehpe=1;}else{datei='content/fenster_klein.php';}
    datei = datei+'?c='+file+'&t='+titel+'&b='+bildnr;
    xajax_marypoppins(datei,tuehpe);
}

function xfenster_content(file,titel,bildnr)
{
    if (fensterlein!='zu') { fensterlein.close(); }
    weite=744;
    hoehe=450;
	eigenschaften = 'top=10,left=10,screenX=10,screenY=10,width='+weite+',height='+hoehe+',menubar=no,resizable=no,scrollbars=no';
    datei = 'content/fenster.php?c='+file+'&t='+titel+'&b='+bildnr;
	fensterlein = window.open(datei,'fensterlein',eigenschaften);
	return void(0);
}

function zusatzclicked(wert)
{
    for(var i = 0;i<document.getElementsByName("zusatzlink").length;i++){
        document.getElementsByName("zusatzlink")[i].style.color = "";
    }
    
    document.getElementById("zusatzlink"+wert).style.color = "#333333";
}
/**
 * ALLE LINKS sollten über Aufruf dieser Funktion geschehen.
 * Aufruf mit "nav('1_1_2')" oder "nav('2_3_12_3', this)" 
 */

function nav(zeig)
{
    seitenWechsel(zeig);
}

/**
 * Hier wird alles ausgelöst, was beim Seitenwechsel passieren soll. 
  */
function seitenWechsel(zeig)
{
	var x = zeig.replace(/^\d+_\d+_(\d+(_\d+)?)$/, '$1');
	var zusatz = zeig.replace(/^\d+_\d+_\d+(_(\d+))?$/, '$2');
	var zeig2 = zeig.replace(/^(\d+_\d+_\d+)(_\d+)?$/, '$1');
	//if (arguments.length > 1) { arguments[1].blur(); }

    changeimg(zeig2,"click");
    zeigen(zeig);
    lnkClr(false);
}

function cleanHtmlTitle()
{
	var ttl = document.title;
	document.title = ttl.replace(/^(.*)#[0-9_x]*$/, "$1");
}
function setHtmlTitle(ttl)
{
	document.title = ttl;
}


function lnkClr(ele)
{
	var ul = document.getElementById('idNavUnten');
	var navUnten = getLinksAusElement(ul);
	for (var i=0; i<navUnten.length; i++) {
			navUnten[i].className = 'nav';
	}
	if (ele && ele.className) {
		ele.className = 'navAc';
	} else if (ele && parseInt(ele)) {
		zuordId = parseInt(ele);
		document.getElementById('idHnds_'+zuordId).className = 'navAc';
	}
	return void(0);
}

var _dieLinks = new Array();
function getLinksAusElement(ele)
{
	_dieLinks = new Array();
	_getLinksAusElement(ele);
	return _dieLinks;
}
function _getLinksAusElement(ele)
{
	var chlds = ele.childNodes;
	var z = 0;
	for (var i=0; i<chlds.length; i++) {
		if (chlds[i].nodeName && chlds[i].nodeName!='A') {
			_getLinksAusElement(chlds[i]);
		} else if (chlds[i].nodeName && chlds[i].nodeName=='A') {
			_dieLinks.push(chlds[i]);
		}
	}
}


/*
 * @param dieId (int) ID des Navpunkts wie in $navigat oder "zuordnungen.php"
 * @param -- (int) (optional) Sub-Unternavpunkt, wie "16_1" für "branchen_1"
 */
function navSpezial(dieId)
{
	var linkZ = navArr[dieId];
	if (linkZ) {
		if (arguments.length > 1) {
			linkZ = linkZ + '_' + arguments[1];
		}
		if (arguments.length > 2) {
			nav(linkZ, arguments[2]);
		} else {
			nav(linkZ);
		}
	}
	return void(0);
}

var upH = 9; 
var upW = 9; 
var downH = 9; 
var downW = 9; 
var dragH = 7;
var dragW = 7; 
var scrollH = 340; 
var speed = 9; 

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()


function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='hidden'
}

function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='visible'
}
	
/* 
		Custom Scrollbar by Horizone v0.7
		based mainly on code from geeeet@ghtml.com and adomas palanvicius
		Keep this commentblock and use freely
*/

/*	
		Current problems in this version:
		-Safari does not wheelscroll
*/

// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

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 inhaltT; // inhalt layer Y;
var inhaltH; // inhalt height
var contentMaskH; // inhalt clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){
	//this line was hindering scrollbar to work in Opera
	//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){
	if(clickDrag && inhaltH > contentMaskH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		inhaltT = ((dragT - rulerT)*(1/scrollLength));
		inhaltT = eval('-' + inhaltT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads inhalt layer top
function getT(){
	if(ie4)
		inhaltT = document.all.inhalt.style.pixelTop;
	else if(nn4)
		inhaltT = document.contentMask.document.inhalt.top;
	else if(dom)
		inhaltT = parseInt(document.getElementById("inhalt").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// Moves the layer
function moveTo(){
	if(ie4){
		document.all.inhalt.style.top = inhaltT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentMask.document.inhalt.top = inhaltT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("inhalt").style.top = inhaltT + "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(inhaltT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			inhaltT = inhaltT + speed;
			if(inhaltT > 0)
				inhaltT = 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(inhaltT > -(inhaltH - contentMaskH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			inhaltT = inhaltT - speed;
			if(inhaltT < -(inhaltH - contentMaskH))
				inhaltT = -(inhaltH - contentMaskH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(ie4){
		// 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 inhalt layer and clip layer
		inhaltH = parseInt(document.all.inhalt.scrollHeight);
		contentMaskH = parseInt(document.all.contentMask.style.height);
	}
	else if(nn4){
		// 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 inhalt layer and clip layer
		inhaltH = document.contentMask.document.inhalt.clip.bottom;
		contentMaskH = document.contentMask.clip.bottom;
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top);
		// Height of inhalt layer and clip layer
		inhaltH = parseInt(document.getElementById("inhalt").offsetHeight);
		contentMaskH = parseInt(document.getElementById("contentMask").offsetHeight);
		document.getElementById("inhalt").style.top = 0 + "px";
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(inhaltH-contentMaskH));
    if(scrollLength<=0){
        document.getElementById("up").style.visibility='hidden';
        document.getElementById("down").style.visibility='hidden';
        document.getElementById("drag").style.visibility='hidden';
        document.getElementById("bg").style.visibility='hidden';
        document.getElementById("ruler").style.visibility='hidden';
    } else {
        document.getElementById("up").style.visibility='visible';
        document.getElementById("down").style.visibility='visible';
        document.getElementById("drag").style.visibility='visible';
        document.getElementById("bg").style.visibility='visible';
        document.getElementById("ruler").style.visibility='visible';    
    }
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}


/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta)
{
	if (delta > 0)
	{
		//alert("up");
		clickUp = true;
		scrollUp();
		scrollUp();
		scrollUp();
		clickUp = false;
	}
  else
  {
		//alert("down");
		clickDown = true;
		scrollDown();
		scrollDown();
		scrollDown();		
		clickDown = false;
	}
}

/** Event handler for mouse wheel event.

 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}


/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = parent.onmousewheel = wheel;