var last
last=""

    	function show(objName) {
    		if (document.getElementById(objName).style.display == "none") {
    			if (last != "") {
    			document.getElementById(last).style.display = "none"
    			}
    			document.getElementById(objName).style.display = "block"
    			last = objName
    		}
    		else {
    		document.getElementById(objName).style.display = "none"
    		last = ""
    		}
    	}

function changeClass(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}


// Part imgPupUp

// Alte Version

function showImgPupUp(object,imageSrc)
{
	var pupUpImage = new Image();
	var objImage 
	
	if (typeof(document.getElementById("newImg")) == 'undefined' || document.getElementById("newImg") == null){
		var objImage = document.createElement("img");
	    objImage.setAttribute('id','newImg');	
    	document.getElementById(object).appendChild(objImage);
	}
	
	var top =  (insyma.window.getScrollTop() + parseInt((insyma.window.getInnerHeight() - 16) / 2))
	top  = (top > 0) ? top : 0
	var left = (parseInt((insyma.window.getInnerWidth() - 16) / 2))
	left = (left > 0) ? left : 0
	
	document.getElementById('loading-popup').style.top = top + 'px';
	document.getElementById('loading-popup').style.left = left + 'px';
	document.getElementById('loading-popup').style.display = 'block';
	
	pupUpImage.onload = function(){
				
		document.getElementById("newImg").src = pupUpImage.src;
		document.getElementById('loading-popup').style.display = "none";
		
		var top =  (insyma.window.getScrollTop() + parseInt((insyma.window.getInnerHeight() - pupUpImage.height) / 2))
		top  = (top > 0) ? top : 0
		var left = (parseInt((insyma.window.getInnerWidth() - pupUpImage.width) / 2))
		left = (left > 0) ? left : 0
	
		document.getElementById(object).style.top = top + 'px';
		document.getElementById(object).style.left = left + 'px';
		document.getElementById(object).style.display = 'block';

	}

	pupUpImage.src = imageSrc;
	
	document.getElementById("closeWindow").onclick = function() {
		document.getElementById(object).style.display = 'none';
		return false;
	};

}


function ClosePupUp(object)
{
	document.getElementById(object).style.display = 'none';
}

// ib replaces old imgPupUp

ib =  {

    // CSS classes
    anchorClass:'PopimgBox',
    popDivId:'PopDiv',
    loadingId:'loading-popup',
    closeLink:'closeWindow',
    captionId:'imgCaption',

    init:function(){
        
        // get all the links
        ib.popDiv = document.getElementById(ib.popDivId);
        ib.anchors = document.getElementsByTagName('a');
        

        for(i=0;i<ib.anchors.length;i++)
        {
            anchor = ib.anchors[i];
            // check for links with the anchorClass
            
            if(anchor.href && (anchor.className == ib.anchorClass))
            {
                anchor.onclick = function(){ib.show(this); return false;}
            }
        }
    },
	
	
    show:function(objLink){
        // show loading gif
        
		if (typeof(document.getElementById("newImg")) == 'undefined' || document.getElementById("newImg") == null) {
			ib.objImage = document.createElement("img");
			ib.objImage.setAttribute('id', 'newImg');
			ib.popDiv.appendChild(ib.objImage);
		}
        
        // read alt property and set value as caption
        ib.Caption = '';
        if(objLink.firstChild.nodeName.toLowerCase() == 'img')
        {
            ib.altNode = objLink.firstChild;
            ib.Caption = (ib.altNode.getAttribute('alt') == '') ? '' : ib.altNode.getAttribute('alt');
        }
        if(ib.Caption != '')
        {
			if (typeof(document.getElementById(ib.captionId)) == 'undefined' || document.getElementById(ib.captionId) == null) {
				ib.objCaption = document.createElement("p");
				ib.objCaption.setAttribute('id', ib.captionId);
				ib.popDiv.appendChild(ib.objCaption);
			}			
			document.getElementById(ib.captionId).innerHTML = ib.Caption;
        }
        
        var toploading =  (insyma.window.getScrollTop() + parseInt((insyma.window.getInnerHeight() - 16) / 2));
        toploading  = (toploading > 0) ? toploading : 0;
        var leftloading = (parseInt((insyma.window.getInnerWidth() - 16) / 2));
        leftloading = (leftloading > 0) ? leftloading : 0;

        document.getElementById(ib.loadingId).style.top = toploading + 'px';
        document.getElementById(ib.loadingId).style.left = leftloading + 'px';
        document.getElementById(ib.loadingId).style.display = 'block';
        
        ib.newImg = new Image();
        ib.newImg.onload = function(){
            
            
            
            document.getElementById("newImg").src = objLink.href;
            // Alert was used to test 
            //alert('width ' + ib.newImg.width + ', height ' + ib.newImg.height);
            var top =  (insyma.window.getScrollTop() + parseInt((insyma.window.getInnerHeight() - ib.newImg.height) / 2));
            top  = (top > 0) ? top : 0;
            var left = (parseInt((insyma.window.getInnerWidth() - ib.newImg.width) / 2));
            left = (left > 0) ? left : 0;
            
            document.getElementById(ib.loadingId).style.display = 'none';
            
            ib.close = document.getElementById(ib.closeLink);
            ib.close.onclick = function(){ib.hide(this); return false;}
            
            document.getElementById(ib.popDivId).style.top = top + 'px';
            document.getElementById(ib.popDivId).style.left = left + 'px';
            document.getElementById(ib.popDivId).style.display = 'block';

            return false;
        }
        ib.newImg.src = objLink.href;
    },
    
    hide:function(closeAnchor){
            ib.divImg = document.getElementById(ib.popDivId);
            if(ib.divImg.style.display != 'none'){
                ib.divImg.style.display = 'none';
            }
            if(document.getElementById(ib.captionId)){
                ib.divImg.removeChild(ib.altCaption);
            }
            return false;
    },
    
    addEvent:function(elm, evType, fn, useCapture){
		if (elm.addEventListener){
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
    }

}
//ib.addEvent(window,'load',toggle.init,false);
ib.addEvent(window,'load',ib.init,false);


// Inhalt ausklappen (ausgeklappter Inhalt automatisch einklappen)
var sublast = ""
function displaySubDiv(objName)
{
	if (document.getElementById)
	{
		if (document.getElementById(objName).style.display == 'none')
		{
			if (sublast != "")
			{
				document.getElementById(sublast).style.display = 'none';
			}
			document.getElementById(objName).style.display = 'block';
			sublast = objName;
		}
		else
		{
			document.getElementById(objName).style.display = 'none';
			sublast = "";
		}
	}
}

// Klasse auf aktiven Link setzen
function activeLink() {
	for (i=0; i<document.getElementsByTagName("a").length; i++) {
		if (document.getElementsByTagName("a")[i] == document.location.href ){
		document.getElementsByTagName("a")[i].className = "active";
		}
	}
}
