var current_num_row=1;
var my_bigimageslider;
var useCookieForTabs = false;

function dropDownMenuInit(ul_id){
	var obj=document.getElementById(ul_id);
	var list=obj.getElementsByTagName('li');
	for (i=0;i<list.length;i++){


		list[i].onmouseover=function(){
			if(this.className != "do_nothing_class" && this.className != "separator"){
				obj=this.getElementsByTagName('span');
				if (obj[2]) obj[2].style.display='block';
				obj2=this.getElementsByTagName('img');
				if (obj2[0] && obj2[1]) {
					obj2[0].style.display='none';
					obj2[1].style.display='inline';
				}
				if(this.id != "navi_li_element_1"){
					this.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/menu_a.jpg)";
				} else {
					this.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/menu_a_grey.jpg)";
					if(element = document.getElementById("navi_li_element_1_left")){
						element.style.backgroundImage="url(http://www.textilmacher.com/img/nav/menu_a_grey_left.jpg)";
					}
					if(element = document.getElementById("navi_li_element_1_right")){
						element.style.backgroundImage="url(http://www.textilmacher.com/img/nav/menu_a_grey_right.jpg)";
					}
				}
			}
		}
		list[i].onmouseout=function(){
			if(this.className != "do_nothing_class" && this.className !="navielement_active" && this.className != "separator"){
				obj=this.getElementsByTagName('span');
				if (obj[2]) obj[2].style.display='none';
				obj2=this.getElementsByTagName('img');
				if (obj2[0] && obj2[1]) {
					obj2[1].style.display='none';
					obj2[0].style.display='inline';

				}
				this.style.backgroundImage = "";
				this.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/menu.jpg)";
				if(this.id == "navi_li_element_1"){
					this.style.backgroundImage = "";
					if(element = document.getElementById("navi_li_element_1_left")){
						element.style.backgroundImage="";
					}
					if(element = document.getElementById("navi_li_element_1_right")){
						element.style.backgroundImage="";
					}
				}
			}

		}
	}
}

function activateHomeButton(){
	if(element = document.getElementById("home_bgleft")){
		element.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/mainmenu_bg_l_a.jpg)";

		element.style.backgroundRepeat = "no-repeat";
	}
	if(element = document.getElementById("home_bgmiddle")){
		element.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/menu_a.jpg)";
		element.style.backgroundRepeat = "repeat-x";
	}
	if(element = document.getElementById("home_button_image")){
		element.src="http://www.textilmacher.com/img/menu_home_img_a.jpg";
	}
}

function deactivateHomeButton(){
	if(element = document.getElementById("home_bgleft")){
		element.style.backgroundImage = "url(http://www.textilmacher.com/img/nav/mainmenu_bg_l.jpg)";

		element.style.backgroundRepeat = "no-repeat";
	}
	if(element = document.getElementById("home_bgmiddle")){
		element.style.backgroundImage = "";
	}
	if(element = document.getElementById("home_button_image")){
		element.src="http://www.textilmacher.com/img/menu_home_img.jpg";
	}
}

function activateSearch(searchtype){

	if(element = document.getElementById("search_inputfield")){
		//element.style.backgroundColor = "#FFFFFF";
		element.style.color = "#000000";
		if(element.value == "Suche"){
			element.value = "";
		}
	}

	if(element = document.getElementById("navi_search_td_left")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_left_active.jpg)';
	}
	if(element = document.getElementById("navi_search_td_middle")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_middle_active.jpg)';
	}
	if(element = document.getElementById("navi_search_td_right")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_right_active.jpg)';
	}
	if(searchtype == "big"){
		scaleNavi(90, '135px');
		scaleSearch(144, '236px');
	} else {
		scaleNavi(90, '135px');
		scaleSearch(158, '196px');
	}

}

function deactivateSearch(searchtype){
	if(element = document.getElementById("search_inputfield")){
		//element.style.backgroundColor = "#575757";
		//element.style.borderColor = "#575757";
		element.style.color = "#FFFFFF";
		if(element.value == ""){
			element.value = "Suche";
		}
	}

	if(element = document.getElementById("navi_search_td_left")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_left_inactive.jpg)';
	}
	if(element = document.getElementById("navi_search_td_middle")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_middle_inactive.jpg)';
	}
	if(element = document.getElementById("navi_search_td_right")){
		element.style.backgroundImage = 'url(http://www.textilmacher.com/img/nav/searchfield_right_inactive.jpg)';
	}
	if(searchtype == "big"){
		scaleNavi(111, '150px');
		scaleSearch(67, "161px");
	} else {
		scaleNavi(111, '150px');
		scaleSearch(61, "121px");
	}


}

function scaleNavi(percentage, shouldwidth){
	navielements = new Array();
	navielements[1] = "navi_li_element_1";
	navielements[2] = "navi_li_element_2";
	navielements[3] = "navi_li_element_3";
	navielements[4] = "navi_li_element_4";
	navielements[5] = "navi_li_element_5";
	for (i=1;i<=navielements.length;i++){
		if(element = document.getElementById(navielements[i])){
			//new Effect.Scale(element, percentage, {scaleContent: false, scaleX:true, scaleY:false, scaleFrom:100})
			//setTimeout("checkElementWidth('"+navielements[i]+"', '"+shouldwidth+"')", 1100);
			new Effect.Morph(element, {
			  style: 'width: '+shouldwidth, // CSS Properties
			  duration: 0.3 // Core Effect properties
			});
		}
	}
}

function scaleSearch(percentage, shouldwidth){
	if(element = document.getElementById("navigation_search_field_li")){
		//new Effect.Scale(element, percentage, {scaleContent: false, scaleX:true, scaleY:false})
		//setTimeout("checkElementWidth('navigation_search_field_li', '"+shouldwidth+"')", 1100);
	}

	new Effect.Morph('navigation_search_field_li', {
	  style: 'width: '+shouldwidth, // CSS Properties
	  duration: 0.3 // Core Effect properties
	});
}

function checkElementWidth(elementId, shouldWidth){
	if(element = document.getElementById(elementId)){

		if(element.style.width != shouldWidth){
			element.style.width = shouldWidth;
		}

	}
}

function isset(varname){
  return(typeof(window[varname])!='undefined');
}

function showBlock(id){
	$(id).style.display='block';
}

function setActiveShowPrice(active){
	if (active=='netto'){
		$('a_min_price_netto').className="active";
		$('a_min_price_brutto').className="";
		$('block_min_price_netto').style.display='block';
		$('block_min_price_brutto').style.display='none';
		$('list_price_p_netto').style.display='block';
		$('list_price_p_brutto').style.display='none';
		$('summ_price_netto').style.display='inline';
		$('summ_price_brutto').style.display='none';

	}
	else{
		$('a_min_price_netto').className="";
		$('a_min_price_brutto').className="active";
		$('block_min_price_netto').style.display='none';
		$('block_min_price_brutto').style.display='block';
		$('list_price_p_netto').style.display='none';
		$('list_price_p_brutto').style.display='block';
		$('summ_price_netto').style.display='none';
		$('summ_price_brutto').style.display='inline';
	}
}

function checkProductRowNext(id, num){

	getPriceSelProducts(id);

	if ( $('product_sel_color_'+num).value!=0 && $('product_sel_size_'+num).value!=0 ){
		changePriceProduct(id, $('product_sel_color_'+num).value, $('product_sel_size_'+num).value);
	}

	if (num==current_num_row && $('product_sel_color_'+num).value!=0 && $('product_sel_size_'+num).value!=0 && $('product_count_'+num).value!=''){
		if (num==1) checkStyleFirtRow();
		current_num_row=current_num_row+1;
		addProductRowNext(id, current_num_row);
		resetSelectedColor();
	}
}

function checkStyleFirtRow(){
	$('product_sel_color_1_div_mm').style.border="0px solid #B8030A";
	$('product_sel_size_1_div_mm').style.border="0px solid #B8030A";
	$('product_count_1').style.border="1px solid #CCC";
	$('id_product_message').innerHTML='';
}

function addProductRowNext(id, num){
	var url = 'index.php?type=color_size_row&id='+id+"&num="+num;
	var myAjax = new Ajax.Request(url,{method: 'get',onComplete: showResponse});

	function showResponse(ret){
		var div=document.createElement("div");
		div.innerHTML=ret.responseText;
		$('color_size_row').appendChild(div);
	}
}

function changePriceProduct(id, color, size){
	var articleCount = 0;
	for(i=1;i<=current_num_row;i++){
		if ($('product_count_'+i))
		if ($('product_sel_color_'+i).value!=0 && $('product_sel_size_'+i).value!=0 && $('product_count_'+i).value!='')
		articleCount = parseInt(articleCount) + parseInt($('product_count_'+i).value);
	}
	var url = 'index.php?type=get_price_info_product_cs&id='+id+"&color="+color+"&size="+size+"&articleCount="+articleCount;
	var myAjax = new Ajax.Request(url,{method: 'get',onComplete: showResponse});

	function showResponse(ret){
		if (ret.responseText){
			var mas=ret.responseText.split("||");
			if (mas[0] != "leider ausverkauft"){
				toggleWKButton(true);
			}
			else{
				toggleWKButton(false);
			}
			$('p_c_price_n').innerHTML=mas[0];
			$('p_c_price_b').innerHTML=mas[1];
			if ($('p_economy_n')) $('p_economy_n').innerHTML=mas[2];
			if ($('p_economy_b')) $('p_economy_b').innerHTML=mas[3];
			$('list_price_p_netto').innerHTML=mas[4];
			$('list_price_p_brutto').innerHTML=mas[5];
		}
	}
}

function toggleWKButton(show){
	if (document.getElementById('wkBtnContainer')){
		if (show == false){
			document.getElementById('wkBtnContainer').style.visibility = 'hidden';
		}
		else{
			document.getElementById('wkBtnContainer').style.visibility = 'visible';
		}
	}
}


function getPriceSelProducts(id){
	var url = 'index.php?type=get_price_info_products&id='+id;
	var pars = '';
	for(i=1;i<=current_num_row;i++){
		if ($('product_count_'+i))
		if ($('product_sel_color_'+i).value!=0 && $('product_sel_size_'+i).value!=0 && $('product_count_'+i).value!='')
			pars+="&color["+i+"]="+$('product_sel_color_'+i).value+"&size["+i+"]="+$('product_sel_size_'+i).value+"&count["+i+"]="+$('product_count_'+i).value;
	}
	if (pars!='')
	var myAjax = new Ajax.Request(url,{method: 'post', parameters: pars, onComplete: showResponse2});

	function showResponse2(ret){
		if (ret.responseText){
			var mas=ret.responseText.split("|");
			$('summ_price_netto').innerHTML=mas[0]+' &euro;';
			$('summ_price_brutto').innerHTML=mas[1]+' &euro;';
			if (mas[2]!=0)
				$('price_economy_next').innerHTML='(ab '+mas[2]+' St&uuml;ck sparen Sie '+mas[3]+'%)';
			else
				$('price_economy_next').innerHTML='';
		}
	}
}

function DropDownChangeClass(li){
	if ($(li).className=='')
		$(li).className='active';
	else
		$(li).className='';
}

function setDropDownActive(mass){
	var n=mass.length;
	for(i=0;i<n;i++){
		name=$('list_dd_li_'+mass[i]).getAttribute('name');
		if (location.hash=='#'+name) $('list_dd_li_'+mass[i]).className='active';
	}
}

function setAllDropDownActive(id){
	eval('var mass=mas_li_'+id);
	var n=mass.length;
	for(i=0;i<n;i++){
		$('list_dd_li_'+mass[i]).className='active';
	}
	$('list_dd_show_hide_'+id).innerHTML='alle schlie?en';
}
function setAllDropDownNotActive(id){
	eval('var mass=mas_li_'+id);
	var n=mass.length;
	for(i=0;i<n;i++){
		$('list_dd_li_'+mass[i]).className='';
	}
	$('list_dd_show_hide_'+id).innerHTML='alle anzeigen';
}

function show_property_info_text(link){
	window.open(link,'window','width=830, height=600, scrollbars=yes,status=no,toolbar=no,menubar=no,resizable=yes,location=no');
}

function left_block_menu_click(obj_a, id_text){
	if ($(id_text).style.display=='none'){
		obj_a.className='link_a';
		$(id_text).style.display='block';
	}
	else{
		obj_a.className='link';
		$(id_text).style.display='none';
	}
}

function show_info_pop(link){
	window.open(link,'window','width=830, height=600, scrollbars=yes,status=no,toolbar=no,menubar=no,resizable=yes');
}


/*function loadTeaserUnter(){
    return 0;
    if ($('unter_teaser_content') && $('teaser_unten_inner')){
        var top_b=$('bottom').offsetTop;
        var top_e=$('unter_teaser_content').offsetTop;
        var h=$('unter_teaser_content').offsetHeight;

            $('teaser_unten_inner').innerHTML=$('unter_teaser_content').innerHTML;
            $('unter_teaser_content').innerHTML="";
            $('unter_teaser_content').style.height=h+"px";
    }
}*/

var currentlyOpendZettelTeaser = "";

function show_zettel_teaser(divName){
	var e = document.getElementById(divName);
	if (e){
		if (currentlyOpendZettelTeaser != "" && currentlyOpendZettelTeaser != divName){
			var oe = document.getElementById(currentlyOpendZettelTeaser);
			if (oe){
				oe.style.display='none';
			}
		}
		if (e.style.display !='block'){
			e.style.display='block';
			var x = tempX;
			var y = tempY;

			e.style.top = (y+20)+'px';
			e.style.left = (x-510)+"px";
			currentlyOpendZettelTeaser = divName;
		}
		else{
			e.style.display='none';
			currentlyOpendZettelTeaser = "";
		}



	}
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

var currentSmallImageSelected = 0;
var currentZoomImageSelected = 0;

function getMouseXY(e) {
  	if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			tempX = e.pageX;
			tempY = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			tempX = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			tempY = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}
		// posx and posy contain the mouse position relative to the document
		// Do something with this information

  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  return true;
}


function moveSliderToElement(elementnr){
	my_bigimageslider.moveToFast('section'+elementnr,my_bigimageslider.scroller,my_bigimageslider.options);
	markSmallImage(elementnr);
}

function selectPrevSlider(){
	my_bigimageslider.previous();
	markSmallImage((currentSmallImageSelected-1));
}

function selectNextSlider(){
	my_bigimageslider.next();
	markSmallImage((my_bigimageslider.current._index+1));
}

function markSmallImage(elementnr){
	if (elementnr < 1){
		elementnr = my_bigimageslider.sections.length;
	}
	if (currentSmallImageSelected > 0 && currentSmallImageSelected != elementnr){
		oldElement = document.getElementById('small_image_id_'+currentSmallImageSelected);
		if (oldElement){
			oldElement.style.border='1px solid #d9d9d9';
		}
	}
	newElement = document.getElementById('small_image_id_'+elementnr);
	if (newElement){
		newElement.style.border='1px solid #000';
	}
	currentSmallImageSelected = elementnr;
}

var currentSelectedColorID = '';

function setWKColorByColorTable(id,fileName,colorName){
	idname = 'colorid_'+id;

	resetSelectedColor();

	newElement = document.getElementById(idname);
	if (newElement){
		newElement.style.border='3px solid #000';
	}

	div_select_value(id,"<img src='apps/shop/pictures/farben/"+fileName+"' border=\'0\' width=\'15\' height=\'15\' /> "+colorName,'product_sel_color_'+current_num_row,'product_sel_color_'+current_num_row+'_div1');

	currentSelectedColorID = idname;
}

function resetSelectedColor(){
	if (currentSelectedColorID != ''){
		oldElement = document.getElementById(currentSelectedColorID);
		if (oldElement){
			oldElement.style.border='1px solid #000';
		}
	}
}


function scrollToDescription(){
	  if (getInternetExplorerVersion() < 0){
	  	new Effect.ScrollTo('tab-pane-27',{duration:1.5});
	  }
	  else{
	  	$('tab-pane-27').scrollTo();
	  }
}


function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}

function openZoomImage(id){
	currentZoomImageSelected =
	document.getElementById('zoomIFrame').src='/template/artikel_zoom.php?itemID='+id+'&active='+currentSmallImageSelected+'#section'+currentSmallImageSelected;
	document.getElementById('artikelZoomContainer').style.display='block';

	/*showWinPhp('artikelZoomContainer','/template/artikel_zoom.php?itemID='+id,'',110,265); */
}

function hideZoomWin(){
	parent.document.getElementById('artikelZoomContainer').style.display='none';
}


function selectPrevSliderZoom(){
	my_zoomslider.previous();
	markSmallZoomImage((currentZoomImageSelected-1));
}

function selectNextSliderZoom(){
	my_zoomslider.next();
	markSmallZoomImage((my_zoomslider.current._index+1));
}

function moveZoomSliderToElement(elementnr){
	my_zoomslider.moveToFast('section'+elementnr,my_zoomslider.scroller,my_zoomslider.options);
	markSmallZoomImage(elementnr);
}

function markSmallZoomImage(elementnr){
	if (elementnr < 1){
		elementnr = my_zoomslider.sections.length;
	}
	if (currentZoomImageSelected > 0 && currentZoomImageSelected != elementnr){
		oldElement = document.getElementById('small_zoom_image_id_'+currentZoomImageSelected);
		if (oldElement){
			oldElement.style.border='1px solid #b3b3b3';
		}
	}
	newElement = document.getElementById('small_zoom_image_id_'+elementnr);
	if (newElement){
		newElement.style.border='1px solid #000';
	}
	currentZoomImageSelected = elementnr;
}


faderI = 0;
function fadeReferenzImages(delayTime) {
   	if(faderI == (imagesFader.length - 1)) {
   		faderI = 0;
   	} else {
   		faderI = faderI + 1;
   	}
	setTimeout('CustomFadeOut()', 1000);
	setTimeout('CustomSetNewSrc()', 2000);
	setTimeout('CustomFadeIn()', 2000);
    setTimeout('fadeReferenzImages('+delayTime+')', delayTime);
}


function CustomFadeOut(){
	 new Effect.Opacity('rotater_image1', { duration: 1.0, from: 1.0, to: 0.0});
}

function CustomFadeIn(){
	 new Effect.Opacity('rotater_image1', { duration: 1.0, from: 0.0, to: 1.0});
}

function CustomSetNewSrc(){
	document.getElementById('rotater_image1').src=imagesFader[(faderI)];
}

var overlaytimer = false;

function showBasketOverlay(){
	if(overlay = document.getElementById('warenkorb_overlay')){
		clearTimeout(overlaytimer);
		if(overlay.style.display != "block"){
			overlay.style.display = "block";
			var url = '/index.php?type=basket_for_nav';
			var myAjax = new Ajax.Request(url,{method: 'get',onComplete: fillBasketOverlay});
		}

	}
}

function fillBasketOverlay(ret){
	if(element = document.getElementById("basket_overlay_article_div")){
		element.innerHTML=ret.responseText;
	}
}

function hideBasketOverlay(){
	if(overlay = document.getElementById('warenkorb_overlay')){
		overlaytimer = setTimeout('overlay.hide();', 1000);
	}
}

