/*
 * Copyright (c) 2006 Wazap AG, Germany -- all rights reserved.
 * Author:Danny Goersdorf
 */


/* hide box at sartpage*/
function hideLayer(id){
 var lay = document.getElementById(id);
 if (lay != null && boxes != null) {
	 var box = boxes[id];
	 if (box != null) {
			box.height = lay.offsetHeight;
			lay.style.overflow="hidden";
			fadeOut(id, 100);
	 }
 }
}
/* Show box at startpage*/
function showLayer(id){
 	var lay = document.getElementById(id);
 	opacIn = 0;
	if (lay != null && boxes != null) {
		var box = boxes[id];
		if (box != null) {
 			fadeIn(id, 0);
			lay.style.display="block";
 		}
 	}
}

/* Fade out the layer with the specified id*/
function fadeOut(layerId,opac) {
	lay = document.getElementById(layerId);
 	if(lay == null) return;
 	if(opac > 0){
 	    opac = opac -10;
      	lay.style.height = ((boxes[layerId].height/100)* opac) + "px";
      	setFadeOpacity(layerId,opac);
      	setTimeout('fadeOut("'+layerId+'","'+ opac + '")',30);
  	}else{
    	lay.style.display="none";
  	}
}

/* Fade in the layer with the specified id*/
function fadeIn(layerId,opac) {
	lay = document.getElementById(layerId);
	if(lay==null)return;
   	if(opac <100 ){
   	    opac = parseInt(opac)+10;
        lay.style.height =  ((boxes[layerId].height/100)* opac) + "px";
		setFadeOpacity(layerId,opac);
		setTimeout('fadeIn("'+layerId+'","'+ opac + '")',20);
	}
}


function setFadeOpacity(id, opac){
    lay = document.getElementById(id);
    try{
		if(ie){
    		lay.filters.alpha.opacity = opac;
    	}else{
    		lay.style.MozOpacity = opac/100;
    	}
    }catch(e){
    	handleException(e);
     	return true;
    }
}

//################ Fade Tooltips ##############################

var ttTimer = null;
var currentAlt = "";
var currentTT = null;
var fadeInterval = 5; //msec

function getTooltipContainer(obj){
  myParent= obj.parentNode.parentNode;
  mySpans = myParent.getElementsByTagName("span");
  for(i=0;i< mySpans.length;i++)
     if(mySpans[i].className=="tooltip")
        return mySpans[i];
}

function showTip(image){
   image.src = image.src.replace(/\.gif/, "_over.\gif");
   currentTT = getTooltipContainer(image);
   if(currentTT != null){
	currentAlt = image.alt;
   	image.alt = "";
   	image.title="";
   	window.clearTimeout(ttTimer);
   	fadeTip(currentAlt,0);
   }
}

function hideTip(image){
  image.src = image.src.replace(/_over/, "");
  image.alt = currentAlt;
  image.title = currentAlt;
  window.clearTimeout(ttTimer);
  if(currentTT!=null){
	currentTT.style.display="none";
  	currentTT = null;
  }
}


function fadeTip(text,i){
  i= (i==null)? 1:i+1;

  if(i<text.length+1 && currentTT!= null){

        currentTT.style.display="inline";
 	    currentTT.innerHTML = text.substr(0,i);
        /* NO FADING!
	        opac = Math.floor(100/text.length*i);
	        try{
	         netscape=(navigator.userAgent.indexOf("Gecko")!=-1)?true:false;
		 	if(!netscape){
	    		currentTT.filters.alpha.opacity = opac;
	    	 }else{
	    		currentTT.style.MozOpacity = opac/100;
	    	 }
			}catch(e){
				handleException(e);
			 
			 return 
			 }
    	 */
	ttTimer = setTimeout('fadeTip("'+ text +'",'+ i + ')',fadeInterval);
  }
}
//#############################################
var extHdHeight = 0;
var hdTimer = null;
var hdExtended = true;

function toggleExtHeader(){
   var exHd = $("extWebHd");
   
   if(hdTimer!=null || !exHd) return;

   if(extHdHeight==0){
	extHdHeight = exHd.offsetHeight;
	exHd.style.overflow="hidden";
   }

   hdTimer = (!hdExtended)? window.setInterval('fadeHeader(+10)',40):window.setInterval('fadeHeader(-10)',40);
}

/*collapse or expand extended header*/
function fadeHeader(step){

    var obj = $("extWebHd");
    if(!obj) return ;
    
    obj.style.overflow="hidden";
    
	var minHeight = $("hdsb").offsetHeight - ((ie5)? 0:2) ;
 	var curHeight = (obj.style.height=='') ? obj.offsetHeight : parseInt(obj.style.height);
 	
 	if(step > 0)
 		stop = (curHeight+step >= extHdHeight)? true:false;
 	else
	 	stop = (curHeight+step <= minHeight) ? true:false;
	 	
 	if(!stop){
 	    obj.style.height = (curHeight + step) + "px";
  	}else{
	  	obj.style.height = (step > 0) ? extHdHeight+"px" : (minHeight) + "px"; 
	  	window.clearInterval(hdTimer) ;
    	hdTimer = null;
    	hdExtended = !hdExtended;
    	$("tglExtHd").className = (hdExtended) ? "extended":"";
    	if(hdExtended) obj.style.overflow="";
    	displayHdContent(hdExtended);

  	}
}

/*close header without visual effect*/
function closeHeader(){
  try{
  	displayHdContent(false);
	var obj = $("extWebHd");
	extHdHeight = 183;
	hdExtended = false;
    obj.style.overflow="hidden";
	obj.style.height = ($("hdsb").offsetHeight - ((ie5)? 0:2)) + "px" ;
	}
	catch(ex){
	 handleException(ex);
	}
}

function displayHdContent(show){
  if(!opera && !ns7 && ! ns8)return;
 
    var hdCont = $("extWebHd").getElementsByTagName("div");
    var i=0;
    for(i=0;i<hdCont.length;i++){
      if(hdCont[i].className != 'switch' && hdCont[i].className != 'menuItems')
	      hdCont[i].style.display = (show) ? "block":"none" ;
	 }
}


