var hBoxPrefix = 'articleteaser_';  // Bezeichnet den Rahmen
var bottomImgClass = 'content_bottom_image';
var hLightColor = '#e5f3fa';
var lLightColor = '#FFFFFF';
var hBoxActiveImage = '/bilder/layout/portlet_bottom_blue_big.gif';
var hBoxNormalImage = '/bilder/layout/portlet_bottom_white_big.gif';
var lastTop = 0;

function clickHighligthTeaser(e)
{
	suffix = divName.slice(hBoxPrefix.length, divName.length);
	tLinks = this.getElementsByTagName('A');
	myHREF = tLinks[0].href;
	myTARGET = tLinks[0].target;
	if (!myTARGET) {
		window.location.href=myHREF;
	} else {
		window.open(myHREF);
	}
    return false;
}


function onMover(e) {
	this.style.backgroundColor=hLightColor;
	tDivs = this.getElementsByTagName('DIV');
	for (i=0; i<tDivs.length; i++) { 
		 if (tDivs[i].className==bottomImgClass) { 
			 tDivs[i].style.background='url('+hBoxActiveImage+')'; 
		}
	}
}

function onMout(e) {
	this.style.backgroundColor=lLightColor;
	tDivs = this.getElementsByTagName('DIV');
	for (i=0; i<tDivs.length; i++) { 
		 if (tDivs[i].className==bottomImgClass) { 
			 tDivs[i].style.background='url('+hBoxNormalImage+')'; 
		}
	}
}

function initHighlightArticleBox() {
	var divs = document.getElementsByTagName('DIV');
	for(var a=0; a<divs.length; a++){
		divName = divs[a].id;
		if(divName.indexOf(hBoxPrefix)==0) {
			tDiv = document.getElementById(divName);
			tMover = document.createElement("DIV");
			tMover.id = "tMover"+a;
			tMover.style.width = tDiv.offsetWidth+'px';
			tMover.style.height = tDiv.offsetHeight+'px';
			tMover.style.position = 'absolute';
			tMover.style.left = '0px';
			tMover.style.top = lastTop+'px';
			lastTop += tDiv.offsetHeight
			tMover.style.backgroundColor = 'transparent';
			tDiv.style.cursor = pointerStyle;
			tDiv.onmouseover = onMover;
			tDiv.onmouseout = onMout;
			tLinks = tDiv.getElementsByTagName('A');
			myHREF = tLinks[0].href;
			myTARGET = tLinks[0].target;
			tDiv.onclick = clickHighligthTeaser;
			tDiv.appendChild(tMover);
		}		
	}	
}
function naviline(color)
{

    var check = navigator.appVersion;

    if (check.indexOf("MSIE") != -1) //Wenn IE, dann...
    {
        var select="false";
        var firstnavi = document.getElementById("first_navigation");
        firstnavi=firstnavi.childNodes[0];
        var clearance = document.getElementById("center_content_main_clearance");
        clearance.style.borderTop = color;
        clearance.style.borderLeft = color;
        clearance.style.marginLeft = "-1px";
        clearance.style.marginRight = "1px"
        var laenge1=firstnavi.childNodes.length;
        for (var i=0; i<laenge1+1; i++)
        {
            var area1 = firstnavi.childNodes[i];
            var laenge2 = area1.childNodes.length;
            if (laenge2<2)
            {
                var area2 = area1.childNodes[0];
                var laenge3 = area2.childNodes.length;
                for (var j=0; j<laenge3; j++)
                {
                    var area3 = area2.childNodes[j];
                    var text = area3.innerHTML;
                    var link = text.indexOf("</A>");
                    var highlight = text.indexOf("/SPAN");
                    if (link!=-1) area3.style.borderRight = color;
                    if (highlight!=-1)
                    {
                        area3.style.borderRight = color;
                        area3.style.borderBottom = color;
                        select = "true";break;
                    }
                }
            }
            area1.style.borderRight = color;
            if (select=="true") break;
        }
    }
    else // Wenn nicht IE, dann...
    {
        var select="false";
        var firstnavi = document.getElementById("first_navigation");
        firstnavi=firstnavi.childNodes[1];
        var clearance = document.getElementById("center_content_main_clearance");
        clearance.style.borderTop = color;
        clearance.style.borderLeft = color;
        clearance.style.marginLeft = "-1px";
        clearance.style.marginRight = "1px";
        var laenge1=firstnavi.childNodes.length;
        for (var i=0; i<laenge1; i++)
        {
            var area1 = firstnavi.childNodes[i];
            if (area1.innerHTML != null) 
            {
                var area2 = firstnavi.childNodes[i];
                var laenge2 = area2.childNodes.length;
                if (laenge2 ==1)area2.style.borderRight = color;
                if (laenge2!=1)
                {
                    var area3 = area2.childNodes[1];
                    var laenge3 = area3.childNodes.length;
                    for (var j=0; j<laenge3; j++)
                    {
                        var area4 = area3.childNodes[j];
                        if (area4.innerHTML != null)
                        {
                            var area5 = area3.childNodes[j];
                            var text = area5.innerHTML;
                            var link = text.indexOf("</A>");
                            var link2 = text.indexOf("</a>");
                            var highlight = text.indexOf("/SPAN");
                            var highlight2 = text.indexOf("/span");
                            if (link!=-1 || link2!=-1) area5.style.borderRight = color;
                            if (highlight!=-1 || highlight2!=-1)
                            {
                                area5.style.borderRight = color;
                                area5.style.borderBottom = color;
                                select = "true";break;
                            }
                        }
                    }
                    if (select=="true") break;
                }
            }
        }
    }
}
//aktuell last edit 10.12.2007 by jea

var slideSpeed = 24;	
var timer = 1;	

// Bezeichnerkonvention für IDs

var pointerStyle = 'pointer';  // Cursorform bei Button-mouseover

// Boxbezeichner
var vButtonPrefix = 'button_'; // für den Klickbaren Bereich zum Öffnen und Schliessen
var vBoxPrefix = 'box_';  // Bezeichnet den Rahmen
var vContentPrefix = 'content_'; // Bezeichnet den Inhalt im Rahmen. Sollte direkt nach dem BoxPrefix kommen
var vStatusPrefix = 'status_'; // für die Statusgrafik (+ -) Die Grafik sollte einziges Element im Div sein

// Infoboxbezeichner
var iButtonPrefix = 'infobutton_';  // s.o.
var iBoxPrefix = 'infobox_'; // s.o.
var iContentPrefix = 'infocontent_'; // s.o.
var iClosePrefix = 'infoclose_'; // Für den zweiten Schliessen-Button

var infoExtended = false;

// Werte initialisieren

var objectIdToSlideDown = false;
var activeId = false;
var slideInProgress = false;

var color; //Default-Wert der Farbe des Button-Icons setzen

function showHideContent(e, suffix)
{
	boxName = false;
	if(slideInProgress)return;
	objectIdToSlideDown = false;
	slideInProgress = true;
	if (!suffix) {
		divName = this.id;
		if (divName.indexOf(vButtonPrefix)==0) {
			suffix = divName.slice(vButtonPrefix.length, divName.length);
			if (suffix.indexOf("grey")>0) color="grey";
			else color="blue"
			boxName = vBoxPrefix+suffix;
			boxTyp = "v";
		} else {
			if (divName.indexOf(iButtonPrefix)==0) suffix = divName.slice(iButtonPrefix.length, divName.length);
			if (divName.indexOf(iClosePrefix)==0) suffix = divName.slice(iClosePrefix.length, divName.length);
			if (suffix.indexOf("grey")>0) color="grey";
			else color="blue"
			boxName = iBoxPrefix+suffix;
			boxTyp = "i";
		}
	} 
	if (!boxName) boxName = vBoxPrefix+suffix;
	var boxDiv = document.getElementById(boxName);
	if(!boxDiv.style.display || boxDiv.style.display=='none'){	
			boxDiv.style.display='block';
			boxDiv.style.visibility = 'visible';
			slideContent(suffix, color, boxTyp, 1);

			/*if (boxTyp=="i" && infoExtended) {
				b = document.getElementById(iButtonPrefix+suffix);
				b.style.borderTop = '1px dashed';
				b.style.paddingTop = '4px';
			}*/
	
	}else{
		slideContent(suffix, color, boxTyp, -1);

			if (boxTyp=="i" && infoExtended) {
				b = document.getElementById(iButtonPrefix+suffix);
				b.style.borderTop = '0px dashed';
				b.style.paddingTop = '0px';
			}

	}	
}

function slideContent(suffix, color, typ, direction)
{
	var movement = slideSpeed*direction;
	var boxDiv = document.getElementById(eval(typ+'BoxPrefix')+suffix);
	var contentDiv = document.getElementById(eval(typ+'ContentPrefix')+suffix);
	if (typ=="i") {
		var parentBoxDiv = document.getElementById(vBoxPrefix+suffix);
		parentBoxDiv.style.height = 'auto';
	}
	height = boxDiv.clientHeight;
	if(height==0) height = boxDiv.offsetHeight;
	height = height + movement;
	rerunFunction = true;
	if(height>(contentDiv.offsetHeight)){
		height = contentDiv.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}
	boxDiv.style.height = height + 'px';
	var topPos = height - contentDiv.offsetHeight;
	if (topPos>0) topPos = 0;
	contentDiv.style.top = topPos + 'px';
	if (rerunFunction) {
		setTimeout('slideContent("' + suffix + '", "'+color+'", "' + typ + '", ' + direction + ')', timer);
	} else {
		if (height<=1) {
			boxDiv.style.display='none'; 
			if (objectIdToSlideDown) {
				contentDiv.style.display='block';
				contentDiv.style.visibility='visible';
				slideContent(suffix, direction);				
			} else {
				slideInProgress = false;
				statusDiv = document.getElementById(vStatusPrefix+suffix)
				if ( (statusDiv) && (typ!="i") )
				{
					if (suffix.indexOf("grey")>-1) {
						statusDiv.firstChild.src= "/bilder/layout/plus_lightgrey.gif";
						statusDiv.firstChild.alt= "Box öffnen";
						statusDiv.firstChild.title= "Box öffnen";
					}
					else if (suffix.indexOf("blue")>-1) {
						statusDiv.firstChild.src= "/bilder/layout/plus_darkblue.gif";
						statusDiv.firstChild.alt= "Box öffnen";
						statusDiv.firstChild.title= "Box öffnen";
						
					}
				}
			}
		} else {
			activeId = suffix;
			slideInProgress = false;
			statusDiv = document.getElementById(vStatusPrefix+suffix)
			if ( (statusDiv) && (typ!="i") )
			{
				if (suffix.indexOf("grey")>-1) statusDiv.firstChild.src= "/bilder/layout/minus_lightgrey.gif";
				else if (suffix.indexOf("blue")>-1) statusDiv.firstChild.src= "/bilder/layout/minus_darkblue.gif";
				statusDiv.firstChild.alt= "Box schließen";
				statusDiv.firstChild.title= "Box schließen";
			}
		}
	}
}

function initBox(suffix, status, typ) {
		buttonDiv = document.getElementById(eval(typ+'ButtonPrefix')+suffix);
		contentDiv = document.getElementById(eval(typ+'ContentPrefix')+suffix);
		boxDiv = document.getElementById(eval(typ+'BoxPrefix')+suffix);
		buttonDiv.style.cursor = pointerStyle;
		buttonDiv.onclick = showHideContent;
		if (typ=="i") {
			iCloseDiv = document.getElementById(iClosePrefix+suffix);
			iCloseDiv.style.cursor = pointerStyle;
			iCloseDiv.onclick = showHideContent;
		}
		contentDiv.style.position = 'relative';
		boxDiv.style.position = 'relative';
		boxDiv.style.overflow = 'hidden';
	if (typ=="i") status="hide"; 
	if (status=="hide") {	
		contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';	
		boxDiv.style.display = 'none';
		boxDiv.style.overflow = 'hidden';
		boxDiv.style.height='1px';
		statusDiv = document.getElementById(vStatusPrefix+suffix)
		if (statusDiv && (typ=="v") && (suffix.indexOf("grey")>-1))
		{
		statusDiv.firstChild.src= "/bilder/layout/plus_lightgrey.gif";
		statusDiv.firstChild.alt= "Box öffnen";
		statusDiv.firstChild.title= "Box öffnen";
		}
		else if (statusDiv && (typ=="v") && (suffix.indexOf("blue")>-1))
		{
		statusDiv.firstChild.src= "/bilder/layout/plus_darkblue.gif";
		statusDiv.firstChild.alt= "Box öffnen";
		statusDiv.firstChild.title= "Box öffnen";
		}
		
	} else {
		contentDiv.style.display='block';
		contentDiv.style.visibility='visible';
		boxDiv.style.display='block';
		boxDiv.style.visibility='visible';
		statusDiv = document.getElementById(vStatusPrefix+suffix)
		if (statusDiv && (typ=="v") && (suffix.indexOf("grey")>-1))
		{
		statusDiv.firstChild.src= "/bilder/layout/minus_lightgrey.gif";
		statusDiv.firstChild.alt= "Box schließen";
		statusDiv.firstChild.title= "Box schließen";
		}
		else if (statusDiv && (typ=="v") && (suffix.indexOf("blue")>-1))
		{
		statusDiv.firstChild.src= "/bilder/layout/minus_darkblue.gif";
		statusDiv.firstChild.alt= "Box schließen";
		statusDiv.firstChild.title= "Box schließen";
		}
		}
}

function registerShowHideDivs(suffix, status)
{
	slideInProgress = false;
	initBox(suffix, status, "v");
	// Für Infoboxen
	infoBox = document.getElementById(iButtonPrefix+suffix);
	if (infoBox) {
		initBox(suffix, status, "i");	
	}
}
