/*Browsercheck*/
var browser=navigator.userAgent.toLowerCase();
window.ie = (browser.indexOf('msie')>-1);
window.iesix = (browser.indexOf('msie 6.0')>-1);
window.firefox = (browser.indexOf('firefox')>-1);
window.nn4 = (browser.indexOf('netscape')>-1);
/**/



/**
 * search
 *
 */
var tpaySearchHandle = null;


function tpaySearch()
{

    if (tpaySearchHandle != null) {
        window.clearInterval(tpaySearchHandle);
    }
    
    tpaySearchHandle = window.setInterval('tpayStartSearch()', 100);

}
function tpayStartSearch()
{
	tx_ajaxsearch_search(document.getElementById('tx_ansearchit_form').value);
    window.clearInterval(tpaySearchHandle);
    tpaySearchHandle = null;
}

/**
* interval based slideshow
**/
function intervalSlideshow(command, slideContainer){
       

          if(!command 
             || (command && command == 'start' 
             && $(slideContainer).parentNode.style.display != 'none' )){
            intervalSlider = window.setInterval('moveToNext(\''+slideContainer+'\',170)', 2500);
            eval ('intervalSlider_'+slideContainer+' = intervalSlider');
          } else {
            try {
            eval('window.clearInterval(intervalSlider_'+slideContainer+');');
            } catch(e){}
          }  
}


/**
* slideshow
*/

function moveToPrevious(slideContainer, elementWidth)
{
    eval('movePrev = window.movePrev_'+slideContainer); 
    
    if ((typeof(movePrev) == 'object')
        && movePrev != false) {
        new Effect.Move(slideContainer, { x: parseInt(elementWidth), y: 0, transition: Effect.Transitions.sinoidal, fps: 100, beforeStart:OnStartPrev, afterFinish:OnFinishPrev });
        chNodesLev1 = getNodeChilds($(slideContainer).parentNode.parentNode.childNodes);
        sliderImage = chNodesLev1[2].childNodes[0].src;
        chNodesLev1[2].childNodes[0].src = sliderImage.replace('_gray.gif','.gif');
   
    }
} 

function moveToNext(slideContainer, elementWidth)
{

    eval('moveNext = window.moveNext_'+slideContainer);
    chNodesLev1 = getNodeChilds($(slideContainer).childNodes);
    visibleElements = 4;
    sliderContainerWidth = 690;
    posHack = 0
    // -10 ie6 hack because of boxmodel
    if (window.iesix)posHack = 10   
    
    if ((this[moveNext] === undefined 
        || (typeof(moveNext) == 'object'))
        && moveNext != false
        && (getComputedWidth(chNodesLev1[0]) >= sliderContainerWidth)) {
 
	    if (parseInt($(slideContainer).offsetLeft + ((visibleElements * elementWidth)*-1)-posHack) <= (getComputedWidth(chNodesLev1[0]) * -1)) {
	        //eval ('delete(window.moveNext_'+slideContainer+')');
            eval ('window.moveNext_'+slideContainer+' = $(slideContainer)'); 
	        
	        eval ('window.movePrev_'+slideContainer+' = $(slideContainer)');   
	           
	        moveToPrevious(slideContainer, parseInt(getComputedWidth(chNodesLev1[0])-(visibleElements * elementWidth)-posHack));
	    } else {
	        new Effect.Move(slideContainer, { x: parseInt('-'+elementWidth), y: 0, transition: Effect.Transitions.sinoidal, fps: 100, beforeStart:OnStartNext, afterFinish:OnFinishNext });
	        chNodesLev1 = getNodeChilds($(slideContainer).parentNode.parentNode.childNodes);
	        chNodesLev2 = getNodeChilds(chNodesLev1[0].childNodes);
	        sliderImage = chNodesLev2[0].src;
	        chNodesLev2[0].setAttribute('src', sliderImage.replace('_gray.gif','.gif'));
	    }
    }
    
}


function OnStartNext(Obj) 
{
    eval ('window.moveNext_'+Obj.element.id+' = false');
	
}

function OnFinishNext(Obj)
{
    eval ('window.movePrev_'+Obj.element.id+' = Obj.element');
    eval ('window.moveNext_'+Obj.element.id+' = Obj.element');
    
}

function OnStartPrev(Obj) 
{
    eval ('window.movePrev_'+Obj.element.id+' = false');
}

function OnFinishPrev(Obj)
{

    if (Obj.element.offsetLeft >= 0) {
        eval ('window.movePrev_'+Obj.element.id+' = false');   
             // hier die images ausgrauen
        chNodesLev1 = getNodeChilds(Obj.element.parentNode.parentNode.childNodes);
        sliderImage = chNodesLev1[0].childNodes[0].src;
        chNodesLev1[0].childNodes[0].src = sliderImage.replace('.gif','_gray.gif');
   
        
    } else {
        eval ('window.movePrev_'+Obj.element.id+' = Obj.element');
        eval ('window.moveNext_'+Obj.element.id+' = Obj.element');
    }
}



/**
* get computed width
*/
function getComputedWidth(theElt){
        if(window.ie){

                tmphght = theElt.offsetWidth;
        }
        else{
                var tmphght1 = document.defaultView.getComputedStyle(theElt, "").getPropertyValue("width");
                tmphght = tmphght1.split('px');
                tmphght = tmphght[0];
        }
        return tmphght;
}

/**
* use tab für infolayer mit tabulator
**/
function useTab(myCaller)
{

    tabContainerId = myCaller.parentNode.parentNode.parentNode.id

    eval('usedTab = window.usedTab_'+tabContainerId);

    if (usedTab != undefined) {
        usedTab.style.display = 'none';
        chNodesLev1 = getNodeChilds(usedTab.parentNode.childNodes); 
        chNodesLev1[0].setAttribute('class', 'tab');
        chNodesLev1[0].setAttribute('className', 'tab');
    } else {
        chNodesLev1 = getNodeChilds(myCaller.parentNode.parentNode.parentNode.childNodes);
        chNodesLev2 = getNodeChilds(chNodesLev1[0].childNodes);
        chNodesLev3 = getNodeChilds(chNodesLev2[0].childNodes);
        chNodesLev3[2].style.display = 'none';
        chNodesLev3[0].setAttribute('class', 'tab');
        chNodesLev3[0].setAttribute('className', 'tab');
    }
    
    chNodesLev1 = getNodeChilds(myCaller.parentNode.childNodes);
    if (chNodesLev1[2].style.display != 'block') {
        chNodesLev1[2].style.display = 'block';
        
        chNodesLev1[0].setAttribute('class', 'tab selected');
        chNodesLev1[0].setAttribute('className', 'tab selected');
        eval('window.usedTab_'+tabContainerId+'= chNodesLev1[2]');
    }   
}




/**
* shows infolayer opened by menu
*/
function showInfolayerMenu(myCaller, infolayerId)
{

    if (window.infolayer != undefined) {
        window.infolayer.style.display = 'none';
    }

    callerPos=findPos(myCaller);

 
    infolayer = $(infolayerId);
    

    
    if (window.ie) {
        infolayer.style.filter = "alpha(opacity=100)";
    }
    infolayer.style.opacity = '1';
    infolayer.style.display = 'block';
    
    
    if (window.iesix) {
        infolayer.style.left = (callerPos[0]-199)+'px';
    } else if (window.ie) { 
        infolayer.style.left = (callerPos[0]-392)+'px';
    } else {
        infolayer.style.left = (callerPos[0]-196)+'px';
    }
    window.infolayer = infolayer;

}


/**
* slides in and out a child element
*/
function openCloseSegment(myCaller)
{
	targetChilds = myCaller.parentNode.childNodes;
	childs       = getNodeChilds(targetChilds);

    if ((childs[1].style.display != 'block') && (childs[1].getAttribute('class') != 'display_block' || childs[1].getAttribute('className')!='display_block') && (childs[1].getAttribute('class')||childs[1].getAttribute('className'))) {
        myCaller.childNodes[1].childNodes[0].src = "fileadmin/images/icons/arrow_vert_top.gif";
        childs[1].style.display='block';
	    childs[1].setAttribute('class', 'display_block');
	    childs[1].setAttribute('className', 'display_block');
	    
	    
    } else {
        myCaller.childNodes[1].childNodes[0].src = "fileadmin/images/icons/arrow_vert.gif";
        childs[1].style.display='none';
	    childs[1].setAttribute('class', 'display_none');
	    childs[1].setAttribute('className', 'display_none');
    }
}

/*
* changes certain class attribs of caller object
*/
function changeClassAttribs(myCaller,className){
	//get actuall class of caller
	if(!window.actClassName)window.actClassName = myCaller.getAttribute('class');
	
	if (className) {
		myCaller.setAttribute('class',className);
		myCaller.setAttribute('className',className);
	} else {
		myCaller.setAttribute('class','');
		myCaller.setAttribute('className','');
	}
}



/*
* changes the startpage teasertextcontent	
*/
function changeContentTeaser(myCaller,open)
{
	
	targetChilds = myCaller.childNodes;
	childs=getNodeChilds(targetChilds);
	
	
	var text1Id=childs[2].id;
	var text2Id=childs[3].id;
	var link=childs[4].id;
	
	if (open) {
		try {
		    window.clearTimeout(eval(text1Id+'timer'));
		} catch(e) {}
		
		
		childs[3].className = "alpha_none";
        eval(text2Id+'timer='+window.setTimeout('Element.hide(\''+text1Id+'\');new Effect.Appear(\''+text2Id+'\');',0));
	} else {
        try{
        window.clearTimeout(eval(text2Id+'timer'));
        }catch(e){}
		eval(text1Id+'timer='+window.setTimeout('Element.hide(\''+text2Id+'\');new Effect.Appear(\''+text1Id+'\');',1000));

	}
}

/*
* don't fetch text nodes
*/
function getNodeChilds(targetChilds) 
{
	childs = new Array();
	cnt=0;
	for (i=0;i<targetChilds.length;i++) {
		if (targetChilds[i].nodeType == 1) {
			childs[cnt] = targetChilds[i];
			cnt++;			
		}
		
	}
	return childs;
}

/*
* shows infolayer
*/
function showInfolayer(myCaller,infolayerId){
	callerPos=findPos(myCaller);
	target = document.getElementById(infolayerId);

    if (window.iesix) {
        target.style.left=(callerPos[0]-205)+'px';
        target.style.top=(callerPos[1]-330)+'px';
	} else if (window.ie) {
        target.style.left=(callerPos[0]-400)+'px';
        target.style.top=(callerPos[1]-240)+'px';
	} else {
		target.style.left=(callerPos[0]-200)+'px';
		target.style.top=(callerPos[1]-230)+'px';
	}
	new Effect.Appear(infolayerId);

}

function closeInfolayer(myCaller){
	new Effect.Fade(myCaller.parentNode.parentNode.id);
}


/*
 *	shows and hides a layer
 */
function layerShowHide(myCaller, layercontent, light)
{
	
	
	callerPos=findPos(myCaller);
	parentContainerPos = findPos(myCaller.parentNode.parentNode.parentNode);
	targetChilds=myCaller.parentNode.parentNode.parentNode.childNodes;
	childs=getNodeChilds(targetChilds);
	target = childs[2];
	
	
	
	if (layercontent) {
	    
		target.style.display='block';
		
		targetChilds=myCaller.parentNode.parentNode.parentNode.childNodes
		childs=getNodeChilds(targetChilds);
		
		if (!eval('window.infolayer_'+childs[3].getAttribute('name'))) {
			eval('window.infolayer_'+childs[3].getAttribute('name')+' = \''+target.childNodes[0].src+'\'');
		}


		if (light) {	
			target.childNodes[0].src = 'fileadmin/images/infolayer/light_infolayer.png';
			
		} else {
			target.childNodes[0].src = eval('window.infolayer_'+childs[3].getAttribute('name'));
		
		}
		target.childNodes[1].innerHTML = layercontent;
		strechLayer(target);
		
		targetPos = findPos(target);

		target.style.left=(callerPos[0]-parentContainerPos[0])+'px';

		
	} else {
		target.style.display='none';
		if(layerImgElement){
			target.removeChild(target.childNodes[2]);
		}
	}
}

function findPos(myCaller) 
{
	var curleft = curtop = 0;
	if (myCaller.offsetParent) {
		curleft = myCaller.offsetLeft
		curtop = myCaller.offsetTop
		while (myCaller = myCaller.offsetParent) {
			curleft += myCaller.offsetLeft
			curtop += myCaller.offsetTop
		}
	}
	return [curleft,curtop];
}



/*
* string replace function for js
*/
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}


function getCurrentValue(value,elem) 
{
	if (window.getComputedStyle) {
	   retValue=window.getComputedStyle(document.getElementById(elem),"" ).getPropertyValue("width");
	} else if(document.getElementById("sample").currentStyle) {
	   retValue=document.getElementById("sample").currentStyle.width; 
	} 
	 
 return retValue;
}


/**
* @param string layer: filename of infolayer (###INFOLAYERCLASS###_infolayer.png)
*/

function strechLayer(layerdiv){
 var clipH = 29;
 var clipW = 134;
 var x = 10;
 var y = 0;
 var layerImg = new Image();
 layerImgElement = '';
 layerImg = layerdiv.childNodes[0].src;
 if(window.iesix) layerImg = target.childNodes[0].getAttribute('src');
 
 
 
 
 var textW=layerdiv.childNodes[1].offsetWidth;
 

 //add new image element
 if((textW+10)>clipW) { 
	  layerImgElement = document.createElement('img');
	 _setStyle(layerImgElement,'position:absolute;left:'+parseInt(textW-clipW+10)+'px;width:'+clipW+'px;');
	 layerImgElement.src = layerImg;
	 layerdiv.appendChild(layerImgElement);
	 
	  if(nn4){
	
	    if(layerImgElement.clip.left > 0){
		    layerImgElement.clip.top = y
		    layerImgElement.clip.right = clipW
		    layerImgElement.clip.bottom = clipH
		    layerImgElement.clip.left = parseInt(textW-clipW-67)
	    } 
	
	   } else {
		    topVal =y;
		    rightVal=clipW;
		    bottomVal=clipH;
		    leftVal=clipW-(textW-clipW+13);
		   
		    	layerImgElement.style.clip="rect("+topVal+"px "+rightVal+"px "+bottomVal+"px "+leftVal+"px)";
		    
	   }
	  //correctPNG(); 
  }
} 

/**
* http://www.peterbe.com/plog/setAttribute-style-IE
*/
 function rzCC(s){
   // thanks http://www.ruzee.com/blog/2006/07/\
   // retrieving-css-styles-via-javascript/
   for(var exp=/-([a-z])/; 
       exp.test(s); 
       s=s.replace(exp,RegExp.$1.toUpperCase()));
   return s;
 }

 function _setStyle(element, declaration) {
   if (declaration.charAt(declaration.length-1)==';')
     declaration = declaration.slice(0, -1);
   var k, v;
   var splitted = declaration.split(';');
   for (var i=0, len=splitted.length; i<len; i++) {
      k = rzCC(splitted[i].split(':')[0]);
      v = splitted[i].split(':')[1];
      eval("element.style."+k+"='"+v+"'");

   }
 }





/*
* load transparent pngs
*/
function correctPNG() 
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (version < 7.0) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgAlt = "alt='" + img.src + "'"
            var imgStyle = "display:inline-block;" + img.style.cssText
            var imgWidth = (img.width < 1) ? 135 : img.width;
            var imgHeight = (img.height < 1) ? 29 : img.height;
            if (img.align == "right") {
                imgStyle = "float:right;" + imgStyle;
            } else if (img.align == "left") {
                imgStyle = "float:left;" + imgStyle
            }
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgAlt + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + imgWidth + "px; height:" + imgHeight + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
            img.outerHTML = strNewHTML;
            i = i-1;
         }
      }
   }    
}

/**
* react to hash changes
*/
function pollHash()
{
    window.setInterval("handleHistory()", 100);
    return true;
}

/**
* handles history hash changes
*/
function handleHistory()
{
    try{
    if (window.location.hash != window.expectedHash) {
        window.expectedHash = window.location.hash
        if (window.expectedHash.indexOf('category')!=-1){
            chNodesLev1 = getNodeChilds($(window.expectedHash.replace('#category','scroller')).parentNode.parentNode.parentNode.childNodes);
            openCloseSegment(chNodesLev1[0]);
        }
    }
    }catch(e){}
    
}


window.onload = function()
{
    if(document.getElementById('tx_ansearchit_form') != null){
        document.getElementById('tx_ansearchit_form').setAttribute("autocomplete","off");
        pollHash();
    }
}


   
 try {
        //window.attachEvent("onload", correctPNG);
 } catch(e) {}
