/* $Id: js.js,v 1.27 2010/03/29 11:11:35 em Exp $ */
/* Added features by ATLAS in row: 8; 20-38; 198-199; 242; 304-318; 325-327; 337-339  */
var windo,body=document.getElementsByTagName("body")[0]

var boxDef=new Array();
boxDef.width=790
boxDef.height=400				// tampered by ATLAS
boxDef.innerheight=300			// added by ATLAS
boxDef.imgWidth=225
boxDef.top=0
boxDef.left=0
boxDef.gap=20						// ?? ich glaube: der Minimale Abstand der zwischen den Boxen liegt
boxDef.loadDelay=3000			// Der Intervall in dem die ganzen Iframes vorgeladen werden
boxDef.rescrollDelay=3000		// wie lange das Startbild angezeigt bleiben soll
boxDef.showDelay=800			// wie lange der Carpet mit dem TeaserText angezeigt bleiben soll, bis dann der echte TExt angezeigt wird.
boxDef.navOnDelay=350		// Millisekunden die verstreichen bis das Sybmenue nach dem Triger mouseover angezeigt wird
boxDef.navOffDelay=250		// Millisekunden die verstreichen bis das Sybmenue nach dem Mouseout wieder ausgeblendet wird
boxDef.run=false

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr){
var delta = maxValue - minValue;
var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
return Math.ceil(stepp)
}

/* Added features by ATLAS - Menu positioning tool */
function mainmenuposad()
	{
		var parent = document.getElementById("navigationList");
		var childCount = parent.getElementsByTagName("li").length;
		if(childCount == 2) {parent.style.marginTop = '45px'};
		if(childCount == 3) {parent.style.marginTop = '35px'};
		if(childCount == 4) {parent.style.marginTop = '25px'};
		if(childCount == 5) {parent.style.marginTop = '20px'};
		if(childCount == 6) {parent.style.marginTop = '10px'};
		if(childCount == 7) {parent.style.marginTop = '0px'};
	}

function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) { 
    if (elem.widthChangeMemInt)
	window.clearInterval(elem.widthChangeMemInt);
    var actStep = 0;
    elem.widthChangeMemInt = window.setInterval(
	function() { 
	  elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
	  elem.style.height = elem.currentWidth + "px"; 
	  actStep++;
	  if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
	} 
	,intervals)
}


windowShow=function(box,run){
    if(typeof run!='boolean')run=boxDef.run;
    var x
    this.scrollTop=this.scrollLeft=0
    clearTimeout(this.waitToMove)

    var b=document.getElementById(box)
    b=b||this.startBox

    // Wenn Box schon sichtbar dann geleich raus!
    if(this.myBackground.boxActiv==b)return false;
	/* ATLAS EDIT - kein herumspringen mehr - testphase ab 04.05.2010 */
    //window.scrollTo(0,0)

    // Link optisch deaktivieren
    if (this.myBackground.boxActiv){
        this.myBackground.boxActiv.showscene(0)
        if (x=document.getElementById("lnk_"+this.myBackground.boxActiv.id))x.className=""
        if (x=document.getElementById("butt_"+this.myBackground.boxActiv.id))x.className=x.className.replace(/_.*$/,"");
        if (x=document.getElementById("float_"+this.myBackground.boxActiv.id)){
            x.parentNode.parentNode.trigger.className=""
            x.className=""
        }
    }

    // Link optisch aktivsetzen
    if (x=document.getElementById("lnk_"+box))x.className="act"
    if (x=document.getElementById("butt_"+box))x.className=x.className.replace(/_.*$/,"")+"_act";
    if (x=document.getElementById("float_"+box)){
        x.parentNode.parentNode.trigger.className="act"
        x.className="act"
    }
    if (x=document.getElementById("opt_"+box))x.selected=true
    else if(x=document.getElementById("opt_none"))x.selected=true



    this.myBackground.boxActiv=b
    clearTimeout(b.waitToLoad)
    b.scene.load()
    // kalender im I-Frame aktualisieren
    try{
        b.scene.iframe.contentWindow.setTimeout("calFetch()",1);
    }catch(e){}


    this.scrollTop=this.scrollLeft=0    
    this.myBackground.moveTo(-b.left,-b.top,this.myBackground.START_SLOW_END_SLOW,1500,(run)?1:60)
    return false;
}

windowDropBox=function(s){
    for(var i=0;i<s.options.length ;i++)if(s.options[i].selected){this.show(s.options[i].value);return}
}

openWindow=function(win){
    var b,d,retry,sb,bts
    windo=win

    // Format Window
    win.scrollTop=win.scrollLeft=win.top=win.left=win.width=win.height=0
    with(win.style){
        width=boxDef.width+"px"
        height=boxDef.innerheight+"px"
        overflow="hidden"
    }
    // define Methodes
    win.show=windowShow;
    win.dropBox=windowDropBox;

    // define Background (layer for boxes)
    win.myBackground=win.appendChild(document.createElement("div"));
    win.myBackground.className="background"
    layout_add(win.myBackground)
    win.myBackground.onMoveEnd=function(){this.boxActiv.showscene(1)}
    
    // Load Boxes
    if (typeof boxList == 'undefined') return;
    win.startBox=boxList[0];
    sb=new shuffleArray(boxList)
    while(sb.hasNext()){
        b=sb.getCurrent()
        while(true){    
            d=b.diagonal/2*(1+Math.random())
            retry=0
            b.move(Math.round(d*Math.sin(b.angle)),Math.round(d*Math.cos(b.angle)),true);
            for (var ii in boxList){
                if (boxList[ii].id==b.id)continue;
                if(b.isCovered(boxList[ii])){
                    retry=1
                    break
                }
            }
            if (!retry) break;
        }       
        b.place(win.myBackground);

        // backround auf groesse der letzten Box erweitern      
        if (b.corners["bottomRight"].left > win.width )win.myBackground.style.width=(win.width=b.corners["bottomRight"].left)+"px"
        if (b.corners["bottomRight"].top > win.height)win.myBackground.style.height=(win.height=b.corners["bottomRight"].top)+"px"
    }

    // anzeigen des Startbildes
    win.show(win.startBox.id,true)
    
    // festlegen welche Box als erste angezeigt werden soll und Timeout fuer diese Box anmelden
    regex=/w_num=(\d+)/
    number=(location.search && regex.exec(location.search))?RegExp.$1:1
    regex=/w_id=(\w+)/
    bts=(location.search && regex.exec(location.search))?RegExp.$1:boxList[number].id
    win.waitToMove=setTimeout("document.getElementById('"+getId(win)+"').show('"+bts+"')",boxDef.rescrollDelay)
}


// ---- START BOX -----------------------------------------------------
boxIsCovered=function(otherBox){
    if (! otherBox.inPlace) return false;

    if (this.corners.topLeft.isItBottomRight(otherBox.corners.topLeft)&& this.corners.bottomRight.isItTopLeft(otherBox.corners.topLeft)) return true
    if (this.corners.topLeft.isItBottomRight(otherBox.corners.bottomRight)&& this.corners.bottomRight.isItTopLeft(otherBox.corners.bottomRight)) return true
    if (this.corners.topLeft.isItBottomRight(otherBox.corners.topRight)&& this.corners.bottomRight.isItTopLeft(otherBox.corners.topRight)) return true
    if (this.corners.topLeft.isItBottomRight(otherBox.corners.bottomLeft)&& this.corners.bottomRight.isItTopLeft(otherBox.corners.bottomLeft)) return true
    return false
}

boxMove=function(top, left, relative){
    var g=this.gap/2
    relative=relative || false
    this.style.top=(this.top=(top+((relative)?this.top:0)))+"px"
    this.style.left=(this.left=(left+((relative)?this.left:0)))+"px"
    this.corners=new Array()
    this.corners["topLeft"]=new Point(this.top-g,this.left-g)
    this.corners["topRight"]=new Point(this.top-g,this.left+this.width+g)
    this.corners["bottomLeft"]=new Point(this.top+this.height+g,this.left-g)
    this.corners["bottomRight"]=new Point(this.top+this.height+g,this.left+this.width+g)
}

boxPlace=function(node){
    if (this.inPlace) return;
    this.inPlace=1
    node.appendChild(this);
    this.waitToLoad=setTimeout("var b=document.getElementById('"+getId(this)+"');b.scene.load()",this.loadDelay*(this.number))
}

createPicBox=function(img){
    // create Box
    box=document.createElement("img")
    box.className="picBox"
    box.border="0"
    with(box.style){position="absolute";borderStyle="none"}

    // apply input parameter to box ans configure layout
    box.src=img || 'http://dev.usw.at/icons/logo_mini.gif'

    // apply Settings of boxDef to box
    var xxx=new Array("width", "height", "top", "left", "gap","loadDelay")
    for (var i in xxx) eval('box.style.'+xxx[i]+'=(box.'+xxx[i]+'=boxDef.'+xxx[i]+')+"px"')
	
	// workaround height
	box.style.height=300+"px";
	
    // create Methodes
    box.place=boxPlace;
    box.move=boxMove;
    box.move(box.top,box.left)
    box.isCovered=boxIsCovered;
    box.inPlace=0
    box.loaded=0

    // define direction this box will move outwards
    box.angle=Math.random()*Math.PI/2;
    box.diagonal=Math.sqrt(Math.pow(box.height,2)+Math.pow(box.width,2))
    
    // create scene
    xxx=box.scene=box
    xxx.loaded=false
    xxx.myBox=box
    
    xxx.load=function(){
        this.loaded=true
    }

    box.showscene=function(){}

    // lege boxes in boxList Array ab
    if (typeof boxList=='undefined') boxList=new Array();
    // nummer null, damit sie sofort laedt, und an den Anfanfang des arrays setzen
    box.number=0
    boxList.unshift(box)
    return box;
}

createBox=function(name,id, url, img, txt, img2){
    var box,xxx,id;

    // create Box
    box=document.createElement("div")
    box.className="box"
    box.style.position="absolute"

    // apply input parameter to box
    box.img=img || 'http://dev.usw.at/icons/logo_mini.gif'
	box.img2=img2
    box.url=url || 'about:blank'
    box.name=name || 'undefined'
    box.id=id || getId(box);

    // apply Settings of boxDef to box
    xxx=new Array("width", "height", "top", "left", "gap","loadDelay")
    for (var i in xxx) eval('box.style.'+xxx[i]+'=(box.'+xxx[i]+'=boxDef.'+xxx[i]+')+"px"')

    // create Methodes
    box.place=boxPlace;
    box.move=boxMove;
    box.move(box.top,box.left)
    box.isCovered=boxIsCovered;
    box.inPlace=0
    box.loaded=0
    // define direction this box will move outwards
    box.angle=Math.random()*Math.PI/2;
    box.diagonal=Math.sqrt(Math.pow(box.height,2)+Math.pow(box.width,2))
    
    // create blanket
    box.blanket=box.appendChild(document.createElement("div"));
    box.blanket.className="blanket"
    box.blanket.appendChild(document.createTextNode(txt));

    // create scene
    xxx=box.scene=document.createElement("div");
    xxx.className="scene"
    xxx.loaded=false
    xxx.myBox=box
    
    xxx.load=function(){
        var e;
        if (this.loaded)return

        // create pic
        this.pic=e=this.appendChild(document.createElement("img"))
        e.src=this.myBox.img
        e.border="0"
        with(e.style){
            position="absolute"
            top=left=0
            width=(boxDef.imgWidth)+"px"
			height=(boxDef.innerheight)+"px"
            borderStyle="none"
        }

        // create iframe
        this.iframe=e=this.appendChild(document.createElement("iframe"))
        e.name=getId(e)
        e.src=this.myBox.url
        e.scrolling="auto"
        e.border="0"
        e.frameBorder=0
        with(e.style){
            position="absolute"
            left=boxDef.imgWidth+"px"
            top=0
            width=(box.width-boxDef.imgWidth)+"px"
			height=(boxDef.innerheight)+"px"
        }
		
		// create claim pic
		if(this.myBox.img2) {
        this.pic=e=this.appendChild(document.createElement("img"))
        e.src=this.myBox.img2
        e.border="0"
        with(e.style){
            position="absolute"
            top=(boxDef.innerheight)+"px"
			left=0
			borderTop="1px"
            width=(boxDef.width)+"px"
			height=((boxDef.height-boxDef.innerheight)-1)+"px"
            borderStyle="solid"
			borderColor="#ffffff"
        }}
		
        this.loaded=true
    }

    box.showscene=function(on){
        clearTimeout(this.wait4scene)
		// ATLAS scene anpassen wenn ein ClaimPic vorhanden ist
		if(box.img2) {doWidthChangeMem(document.getElementById("window"),document.getElementById("window").offsetHeight,300,25,15,0.999)}
        this.scene.appendChild(this.scene.iframe);
        if(on){
            // Box heraussuchen
            var action='var x=document.getElementById("'+getId(this)+'")'
            // scene (Bild mit iFrame) einhaengen
            action+=';x.appendChild(x.scene)'
            // iframe ansprechen und nach oben scrollen
            action+=';window.frames[x.scene.iframe.id].scrollTo(0,0)'
			// ATLAS scene anpassen wenn ein ClaimPic vorhanden ist
			if(box.img2) {doWidthChangeMem(document.getElementById("window"),document.getElementById("window").offsetHeight,400,25,15,0.999)}
            this.wait4scene=setTimeout(action,boxDef.showDelay)
			// ATLAS removed the netscape browser Check because it prevented IE from unloading content
        }else if(this.scene.parentNode)this.scene.parentNode.removeChild(this.scene)
    }

    // lege boxes in boxList Array ab
    if (typeof boxList=='undefined') boxList=new Array();
    box.number=boxList.length
    boxList.push(box)
    return box;
}

// active Submenue Menue
addRunTagFunc('li','if(tag.className=="ml")initML(tag);')
initML=function(tag){
    tag.sn=document.getElementById("sub_"+tag.id);
    if(!tag.sn) return;
    tag.onmouseover=navMouseOver;
    tag.onmouseout=navMouseOut;
    tag.on=mlOn;
    tag.off=mlOff;

    tag.sn.onmouseover=navMouseOver;
    tag.sn.onmouseout=navMouseOut;
    tag.sn.on=snsOn;
    tag.sn.off=snsOff;
    tag.sn.ml=tag;
}

mlOn=function(){this.sn.on();}
mlOff=function(){this.sn.off();}
navMouseOver=function(e,force){
    if(!force){
        var e=e||window.event;
        standardizeEvent(e);
        if (! onMouseReally(this, e, 3)) return;
    }
    this.on();
}
navMouseOut=function(e,force){
    if(!force){
        var e=e||window.event;
        standardizeEvent(e);
        if (! onMouseReally(this, e, 3)) return;
    }
    this.off();
}

snsOn=function(){
    window.clearTimeout(this.wOff);
    if(this.style.display=="block")return;
    this.wOn=window.setTimeout('var xxx=document.getElementById("'+getId(this)+'");xxx.style.display="block";xxx.ml.className="mla"',boxDef.navOnDelay);
}

snsOff=function(){
    window.clearTimeout(this.wOn);
    if(this.style.display=="none")return;
    this.wOff=window.setTimeout('var xxx=document.getElementById("'+getId(this)+'");xxx.style.display="none";xxx.ml.className="ml"',boxDef.navOffDelay);
}


/** Definition des PopItUp Elements (nur für die Kleine Zeitung)*/
if(typeof(PopItUp)!="undefined"){
    new PopItUp(
        "<img src='!+0-!' alt='!+1-!' title='!+1-!'/><div class='body'>!+2-!<\/div><h5>!+1-!</h5>"
        ,"popitup"
        ,"div"
        ,"pinpop"
        ,3
        ,0.4
        ,null
        ,null
        ,true
        )
}