var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var version = "n2";
var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
if((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName == "Konqueror" || browserName == "Opera"){
	version = "n3";
}
function blurLink(theObject){
	if(msie4){
		theObject.blur();
	}
}
function decryptCharcode(n, start, end, offset){
	n = n + offset;
	if(offset > 0 && n > end){
		n = start + (n - end - 1);
	}else if(offset < 0 && n < start){
		n = end - (start - n - 1);
	}
	return String.fromCharCode(n);
}
function decryptString(enc, offset){
	var dec = "";
	var len = enc.length;
	for(var i = 0; i < len; i++){
		var n = enc.charCodeAt(i);
		if(n >= 0x2B && n <= 0x3A){
			dec+= decryptCharcode(n, 0x2B, 0x3A, offset);
		}else if(n >= 0x40 && n <= 0x5A){
			dec+= decryptCharcode(n, 0x40, 0x5A, offset);
		}else if(n >= 0x61 && n <= 0x7A){
			dec+= decryptCharcode(n, 0x61, 0x7A, offset);
		}else{
			dec+= enc.charAt(i);
		}
	}
	return dec;
}
function linkTo_UnCryptMailto(s){
	location.href = decryptString(s, -2);
}


function T3_onloadWrapper(){
	return true;
}

jQuery(function($){
	var descHtml = "<ul class='products-list' style='display:none;'>";
	$(".cat-protein").each(function(index, node){
		descHtml+="<li>";
		descHtml+= "<div class='produkt_image'>";
		descHtml+= "<a href='"+$(node).find(".produkt_image a").attr("href")+"'>";
		descHtml+= "<img src='"+$(node).find(".produkt_image img").attr("src")+"' />";
		descHtml+= "</a>";
		descHtml+= "</div>";
		descHtml+= "<div class='produkt_info'>";
		descHtml+= "<h3>"+$(node).find(".produkt_title").html().replace(/<[^\/>][^>]*><\/[^>]+>/g,"")+"</h3>";
		descHtml+= $(node).find(".produkt_description").html().replace(/<[^\/>][^>]*><\/[^>]+>/g,"");
		descHtml+= "</div>";
		descHtml+= "</li>";
	});
	descHtml+= "</ul>";
	$(".tx-commerce-pi1").html($(".tx-commerce-pi1").html()+ descHtml);

	var tableHtml = "<table class='products-table' width='505' style='display:none;'>";
	$(".cat-protein").each(function(index, node){
		tableHtml+= "<tr>";
		tableHtml+= "<td class='produkt_title'>";
		tableHtml+= "<h3>"+$(node).find(".produkt_title").html().replace(/<[^\/>][^>]*><\/[^>]+>/g,"")+"</h3>";
//		tableHtml+= $(node).find(".produkt_description").html().replace(/<[^\/>][^>]*><\/[^>]+>/g,"");
		tableHtml+= "<ul>";
		tableHtml+= "<li><b>In folgenden Varianten erhältlich:</b><ul>";
		$(node).find(".produkt_images img").each(function(index, img){
			tableHtml+="<li>"+$(img).attr("title")+"</li>";
		});
		tableHtml+= "</ul></li></ul>";
		tableHtml+= "</td>";
		tableHtml+= "<td class='produkt_images'>";
		tableHtml+= "<a href='"+$(node).find(".produkt_image a").attr("href")+"'>";
		tableHtml+= $(node).find(".produkt_images").html();
		tableHtml+= "</a>";
		tableHtml+ "</td>";
		tableHtml+= "</tr>";
	});
	tableHtml+= "</table>";
	$(".tx-commerce-pi1").html($(".tx-commerce-pi1").html() + tableHtml);
	$(".products-table").hide();
	$(".cat-protein .produkt_images").remove();
	$(".cat-protein .produkt_description").remove();
	$(".products-table .produkt_title img").remove();
	$(".products-table tr:last").css("border",0);
	if(!$.browser.msie){
		$(".products-table").css({
			"margin-left":"-20px",
			"margin-top":"-22px",
			"width":"525px"
		});
	}
});
jQuery(function($){
	function updateHeight(){
		var height = 0;
		$("#article-images img").each(function(index, node){
			if(height < $(node).attr("height")){
				height = $(node).attr("height");
			}
		});
		$("#article-images li").css("height", height + 10);
	}
	if($(".article-shot").length){
		$("#main-col").hide();

		var html= "<ul>";
		$(".article-shot").each(function(index, node){
			$(node).parent("div").attr("id", "produkt-index-"+index).addClass("produkt-variante");
			html+= "<li><a href='#' index='"+index+"'>"+$(node).html()+"</a></li>";
		});
		html+="</ul>";
		$("#article-images").html(html);

		var height = 0;
		$(".article-shot").each(function(index, node){
			var tmpHeight = parseInt($(this).find("img:first").attr("height"));
			if(tmpHeight > height){
				height = tmpHeight;
			}
		});
		if(height == 0 ){
			$("#article-images li").css("height", 70);
		}else{
			$("#article-images li").css("height", height + 10);
		}

		$(".produkt-variante").hide();
		$(".produkt-variante:first").show();
		$(".items").css({
			"position": "relative",
			"width": "auto"
		});
		$(".scrollable").css({
			"min-height": "10px",
			"height": "auto",
			"width": "100%"
		});
		$(".items div").css("width","100%");
		if($(".article-shot").length == 1){
			$(".nav").remove();
			$("#article-images").remove();
		}
		$(".article-shot").remove();
		$("#main-col").show();
		var updateIE = false;
		$("#article-images li").mouseover(function(){
/**
			if($.browser.msie && !updateIE){
				updateHeight();
				updateIE = true;
			}
**/
			$(this).addClass("image_list_hover");
		}).mouseout(function(){
			$(this).removeClass("image_list_hover");
		});
		$("#article-images a").click(function(event){
			event.preventDefault();
			$(".produkt-variante").hide();
			$("#produkt-index-"+$(this).attr("index")).show();
			$(".product-shot:first").html($(this).find(".article_detailimage:first").html());
		});
		if($.browser.msie){
			updateHeight();
		}
	}
});
/** **/
jQuery(function($){
	if($("#sidebar").length && $("#history-items").length){
		var html = $("#sidebar").html()+"<ul id='history-items'>";
		html += $("#history-items").html()+"</ul>";
		$("#history-items").remove();
		$("#sidebar").html(html);
//		$("#history-items").hide().fadeIn(1000);
	}
	if(!$("#similar-products li").length){
		$("#similar-products").remove();
	}
/** **/
	if ($.browser.msie){
		$("#history-items .second-cell").css({"width":"125px"});
		$("#history-items .second-cell b").css({
			"position": "",
			"width": "125px",
			"left": "0", 
			"top": "0"
		});
	}
/** **/
});
/** **/
jQuery(function($){
	// zentrieren manuell über margin-left machen, da Firefox bei Pixelrundungen mit der Flash-Überlagerung Probleme hat!
	var content = $("#content"),
		contentWidth = content.width(),
		body = $(document.body);
	function onResize(){
		var l = Math.round((body.width() - contentWidth) / 2);
		content.css("margin-left", Math.max(l, 0));
	}
	onResize();
	$(window).bind("resize", onResize);
});
jQuery(function($){
	if(	$(".tx-commerce-pi1").length && !$(".tx-commerceattrsearch-pi1").length && !$(".product-shot").length){
		$('<div id="produkt-view-list">'
		+'<span id="grid-view" class="aktiv">&nbsp;</span>'
		+'<span id="grid-list">&nbsp;</span>'
		+'<span id="grid-table">&nbsp;</span>'
		+'</div>').insertBefore($('.tx-commerce-pi1'));

		var viewAktiv = {
			list: false,
			grid: true,
			table: false
		};
		$("#grid-view").mouseover(function(){
			$(this).addClass("aktiv");
		}).mouseout(function(){
			if(!viewAktiv.grid){
				$(this).removeClass("aktiv");
			}
		}).click(function(){
			viewAktiv.list = false;
			viewAktiv.table = false;
			viewAktiv.view = true;
			$("#grid-view").addClass("aktiv");
			$("#grid-list").removeClass("aktiv");
			$("#grid-table").removeClass("aktiv");
			$(".products").show();
			$(".products-list").hide();
			$(".products-table").hide();
		});

		$("#grid-list").mouseover(function(){
			$(this).addClass("aktiv");
		}).mouseout(function(){
			if(!viewAktiv.list){
				$(this).removeClass("aktiv");
			}
		}).click(function(){
			$("#grid-view").removeClass("aktiv");
			$("#grid-list").addClass("aktiv");
			$("#grid-table").removeClass("aktiv");
			viewAktiv.view = false;
			viewAktiv.table = false;
			viewAktiv.list = true;
			$(".products").hide();
			$(".products-list").show();
			$(".products-table").hide();
		});

		$("#grid-table").mouseover(function(){
			$(this).addClass("aktiv");
		}).mouseout(function(){
			if(!viewAktiv.table){
				$(this).removeClass("aktiv");
			}
		}).click(function(){
			$("#grid-view").removeClass("aktiv");
			$("#grid-list").removeClass("aktiv");
			$("#grid-table").addClass("aktiv");
			viewAktiv.view = false;
			viewAktiv.table = true;
			viewAktiv.list = false;
			$(".products").hide();
			$(".products-list").hide();
			$(".products-table").show();
		});
	}
});
jQuery(function($){
	var images = {
		'pictogramm_ausdauer_HGgrau.gif': 'Ausdauer',
		'pictogramm_ausdauer_HGweiss.gif': 'Ausdauer',
		'pictogramm_berg_HGgrau.gif': 'Berg',
		'pictogramm_berg_HGweiss.gif': 'Berg',
		'pictogramm_kraft_HGgrau.gif': 'Kraft',
		'pictogramm_kraft_HGweiss.gif': 'Kraft',
		'pictogramm_rad_HGgrau.gif': 'Rad',
		'pictogramm_rad_HGweiss.gif': 'Rad',
		'pictogramm_team_HGgrau.gif': 'Team',
		'pictogramm_team_HGweiss.gif': 'Team',
		'pictogramm_winter_HGgrau.gif': 'Winter',
		'pictogramm_winter_HGweiss.gif': 'Winter',
		'pictogramm_langlauf_HGgrau.gif': 'Langlaufe',
		'pictogramm_langlauf_HGweiss.gif': 'Langlaufe'
	};
	for(var key in images){
		$("img[src$='"+key+"']").attr('title', images[key]).attr('alt', images[key]);
	}
});

/* Shop-Blendin auf den Produkt-Detailseiten */
jQuery(function($){
	
	$(".shopsucher").toggle(function(){
	
	$("#haendler-popup").show('slow');

	//var value = "http://www.xenofit-shop.de/";
	//value+= $("#shoplink").attr("shop");
	//$("#haendler-linke-spalte-inner a:first").attr("href",value);
	$("#rplink").html('<a href="http://www.shop4outdoor-sports.de/shop/marken-brands/xenofit/" target="_blank"><img id="zum-online-shop" src="http://www.xenofit.de/fileadmin/templates/img/zum-online-shop.jpg" alt="zum Online-Shop" /></a>');

	},function(){
		$("#haendler-popup").hide('slow');
	});
	
	$("#haendler-popup #close").click(function(){
		$("#haendler-popup").hide('slow');
	});
});

jQuery(function($){
	// Suchfeld löschen, wenn focus
	var originalValue = $("#sidebar-search input").val();
	$("#sidebar-search input").bind("focus", function(){
		if(this.value == originalValue){
			this.value = "";
		}
	}).bind("blur", function(){
		if(this.value == ""){
			this.value = originalValue;
		}
	});
});

jQuery(function($){
	var dropdowns = $("#nav>li>ul, .filter ul").hide();
	dropdowns.append('<li class="dropdown-highlight"></li>');
	// alle Elemente, die ein Dropdown haben, entsprechend kennzeichnen
	dropdowns.parent().addClass("has-dropdown").hover(function(){
		$(">ul", this).show();
	},function(){
		$(">ul", this).hide();
	});
});

jQuery(function($){
	var unfolds = $("#content-sidebar ul.cross-links ul");
	// alle Elemente, die ein Dropdown haben, entsprechend kennzeichnen
	unfolds.parent().find(">a").bind("click", function(){
		var parent = $(this.parentNode);
		if(parent.hasClass("active")){
			$(">ul", parent.removeClass("active")).hide();
		}else{
			$(">ul", parent.addClass("active")).show();
		}
		this.blur();
		return false;
	});
});





    var favicon = {
     
    change: function(iconURL) {
      if (arguments.length==2) {
        document.title = optionalDocTitle;
      }
      this.addLink(iconURL, "icon");
      this.addLink(iconURL, "shortcut icon");
    },
     
    addLink: function(iconURL, relValue) {
      var link = document.createElement("link");
      link.type = "image/x-icon";
      link.rel = relValue;
      link.href = iconURL;
      this.removeLinkIfExists(relValue);
      this.docHead.appendChild(link);
    },
     
    removeLinkIfExists: function(relValue) {
      var links = this.docHead.getElementsByTagName("link");
      for (var i=0; i<links.length; i++) {
        var link = links[i];
        if (link.type=="image/x-icon" && link.rel==relValue) {
          this.docHead.removeChild(link);
          return; // Assuming only one match at most.
        }
      }
    },
     
    docHead:document.getElementsByTagName("head")[0]
    } 



favicon.change('/favicon.ico');






jQuery(function($){
	if($(".items div").length == 1){
		$(".browse").remove();
	}
	
	var printTag = '<li id="printButton"><a href="javascript:window.print()"><img src="/fileadmin/templates/img/print_icon.png" /></a></li>';
	$('#service-nav').prepend(printTag);
	
	// Googl Maps laden
	if(typeof load == 'function') load();
});

var flashvars = {
	nav_1_link:"index.php?id=282",
	nav_2_link: "index.php?id=284",
	active_section: 0 // 0 (keine), 1 (links) oder 2 (rechts)
};
var params = {
	wmode: "transparent"
};
var attributes = false;
if(swfobject){
	swfobject.embedSWF("http://www.xenofit.de/fileadmin/templates/swf/header.swf", "flashheader", "920", "385", "9.0.0","expressInstall.swf", flashvars, params, attributes);
}
