﻿/*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).parent().css('display') != 'none' )){
            intervalSlider = window.setInterval('moveToNext(\''+slideContainer+'\',282)', 2500);
            eval ('intervalSlider_'+slideContainer+' = intervalSlider');
          } else {
            try {
            eval('window.clearInterval(intervalSlider_'+slideContainer+');');
            } catch(e){}
          }  
}


/**
* slideshow
*/

function moveToPrevious(slideContainer, elementWidth)
{
    eval('movePrev = window.movePrev_'+slideContainer); 
	chNodesLev1 = getNodeChilds($('#' + slideContainer).parent().parent().children().children());
	sliderImage = chNodesLev1[0].src;
    posX = $('#' + slideContainer).css('left').replace('px','');
    if(posX == 'auto') posX = 0;


	if ($('#' + slideContainer).css('left') == '-' + elementWidth + 'px')
	{
		chNodesLev1[0].src = sliderImage.replace('.gif','_gray.gif');
		chNodesLev1[0].alt = '';
		chNodesLev1[0].title = '';
	}
	if ($('#' + slideContainer).css('left') != '0px' && $('#' + slideContainer).css('left') != 'auto'
		&& posX % elementWidth == 0
	)
	{
		$('#' + slideContainer).animate({"left": "+="+elementWidth}, "slow");
	}
} 

function moveToNext(slideContainer, elementWidth)
{
	eval('moveNext = window.moveNext_'+slideContainer);
    chNodesLev1 = getNodeChilds($('#' + slideContainer).children());
    visibleElements = 2;
    sliderContainerWidth = 550;
    posHack = 0
    // -12 ie6 hack because of boxmodel
    if (window.iesix)posHack = 12
    posX = $('#' + slideContainer).css('left').replace('px','');
    if(posX == 'auto') posX = 0;
    if ((this[moveNext] === undefined 
        || (typeof(moveNext) == 'object'))
        && moveNext != false
        && (getComputedWidth(chNodesLev1[0]) >= sliderContainerWidth)
        && posX % elementWidth == 0
        ) {
    	
	    var offset = parseInt($('#' + slideContainer).css('left'));
		var maxWidth = visibleElements * elementWidth * -1 - posHack;
		if (offset + maxWidth < (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 -1) * elementWidth)-posHack));
	    } else {
			$('#' + slideContainer).animate({"left": "-="+elementWidth}, "slow");
			//new Effect.Move(slideContainer, { x: parseInt('-'+elementWidth), y: 0, transition: Effect.Transitions.sinoidal, fps: 100, beforeStart:OnStartNext, afterFinish:OnFinishNext });
	        chNodesLev1 = getNodeChilds($('#' + slideContainer).parent().parent().children());
	        chNodesLev2 = getNodeChilds(chNodesLev1[0].childNodes);
	        sliderImage = chNodesLev2[0].src;
	        chNodesLev2[0].setAttribute('src', sliderImage.replace('_gray.gif','.gif'));
			chNodesLev2[0].setAttribute('alt', 'zurück blättern');
			chNodesLev2[0].setAttribute('title', 'zurück blättern');

	    }
    }
    
}


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[1].style.display = 'none';
        chNodesLev3[0].setAttribute('class', 'tab');
        chNodesLev3[0].setAttribute('className', 'tab');
    }
    
    chNodesLev1 = getNodeChilds(myCaller.parentNode.childNodes);
    if (chNodesLev1[1].style.display != 'block') {
        chNodesLev1[1].style.display = 'block';
        
        chNodesLev1[0].setAttribute('class', 'tab selected');
        chNodesLev1[0].setAttribute('className', 'tab selected');
        eval('window.usedTab_'+tabContainerId+'= chNodesLev1[1]');
    }   
}




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

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

    
	callerPos=findPos(myCaller);
 
    infolayer = $('#' + infolayerId);
    

    
    if (window.ie) {
        infolayer.css('filter','alpha(opacity=100)');
    }
    infolayer.css('opacity','1');
    infolayer.css('display','block');
    
    
    if (window.iesix) {
        infolayer.css('left',callerPos[0]-196+'px');
    } else if (window.ie) { 
        infolayer.css('left',callerPos[0]-196+'px');
    } else {
        infolayer.css('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'))) {
		//var image = $('#' + myCaller.children().children('IMG'));
		//alert(image);
		for (var i = 0; i < myCaller.childNodes.length; i++)
		{
			if (myCaller.childNodes[i].tagName == "A")
			{
				var child = myCaller.childNodes[i];
			}
		}
		
		for (i = 0; i < child.childNodes.length; i++)
		{
			if (child.childNodes[i].tagName == "IMG")
			{
				var child2 = child.childNodes[i];
			}
		}
		child2.src = "img/arrow_up.gif";
		child2.title = "zuklappen";
        childs[1].style.display='block';
	    childs[1].setAttribute('class', 'display_block');
	    childs[1].setAttribute('className', 'display_block');
	    
	    
    } else {
        for (i = 0; i < myCaller.childNodes.length; i++)
		{
			if (myCaller.childNodes[i].tagName == "A")
			{
				var child = myCaller.childNodes[i];
			}
		}
		
		for (i = 0; i < child.childNodes.length; i++)
		{
			if (child.childNodes[i].tagName == "IMG")
			{
				var child2 = child.childNodes[i];
			}
		}
		child2.src = "img/arrow_down.gif";
		child2.title = "aufklappen";
        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;
	if(targetChilds != undefined)
	{
		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';
	}

}

function closeInfolayer(myCaller){
	layerId = myCaller.parentNode.parentNode.id;
	$('#' + layerId).fadeOut('slow');
}


/*
 *	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;
         }
      }
   }    
}

function showLayer(layerId, posTop)
{
	$('#verkaufsstellensuche').css('display','none');
	$('#haendler').css('display','none');
	$('#' + layerId).css('top',posTop+'px');
	$('#' + layerId).css('display','block');
}

function closeLayer(layerId){
		$('#' + layerId).fadeOut('slow');
		if(layerId == 'geschenkkarte')
		{
			$('#gk_obenrechts').fadeOut('slow');
			$('#gk_mitterechts').fadeOut('slow');
			$('#gk_untenrechts').fadeOut('slow');
		}
}











/**
* 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()
{
//	$('#geschenkkarte').fadeIn(2000, function () {
//
//	});
//	
//	$('#gk_untenrechts').animate({
//	    top: '228'
//	  }, 3000, function() {
//	    $('#gk_obenrechts').fadeIn(3000, function () {
//
//	    });
//   	 	$('#gk_mitterechts').animate({
//   	 		top: '122'
//   	 	}, 1500);
//	    // Animation complete.
//	});
	
}


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

