/* ------------------------------------------------------------------------------------------------- #
*
* Suche Focus State
*
*/

(function($){
	$(function() {
		var valold = $("#keyword").val();
		$("#keyword").focus(function() {
			if(this.value==valold) this.value=''
		}).blur(function(){
			if(this.value=='')this.value=valold
		});
	});

	$(document).ready(function() {

		//When page loads...
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab

		$(".tab_content:first").show(); //Show first tab content
		logo = $.data($(".tab_content:first"),"logo");
		$("#tabs_logo").animate({ backgroundPosition:"100% center"},1000);

		var posLeft=0;
		var posRight=0;
		$("ul.tabs li").each(function(index,item){

			posRight+= $(item).attr("scrollWidth");
			$(item).data("posRight",posRight);
			$(item).data("posLeft",posLeft);
			posLeft+= $(item).attr("scrollWidth");

		});


		$(".tabs-holder").animate({ scrollLeft: "0"}, 500);

		var activeItemInd = 0;
		var countItems = $("ul.tabs li").length;

		$(".tabs-holder div").css("width",$(".tabs").attr("scrollWidth"));

		$("ul.tabs li:first").addClass('active');
		activeItem = $($("ul.tabs li:first"));

		$(".tabs-menu a.tabs-menu-next").click(function(event){
			$("ul.tabs li.active").next("li").click();
			event.preventDefault();
		});

		$(".tabs-menu a.tabs-menu-back").click(function(event){
			$("ul.tabs li.active").prev("li").click();
			event.preventDefault();

		});

		$("ul.tabs li a").click(function(event){ event.preventDefault(); });

		//On Click Event
		$("ul.tabs li").click(function(){

			$("ul.tabs li.active").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content

			activeItem = $(this);
			$(".tabs-holder").animate({ scrollLeft: ""+$(activeItem).data("posLeft")});

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content

			logo = $(activeTab).data("logo");
			$("#tabs_logo").animate({ backgroundPosition:"200% center"},1000,function(){
				$("#tabs_logo").css("background-image","url("+logo+")");
				$("#tabs_logo").animate({ backgroundPosition:"100% center"},1000);
			});



			$(activeTab).fadeIn(); //Fade in the active ID content
			return false;
		});

	});




	/* ------------------------------------------------------------------------------------------------- #
	*
	* External Links (rel="external")
	*
	*/

	function externalLinks() {
		if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external")
				anchor.target = "_blank";
		}
	}
	window.onload = externalLinks;

	/* falls mehrere Tags vorhanden */
	function externalLinks() {
		if (!document.getElementsByTagName) {
			return;
		}
		var anchors = document.getElementsByTagName("a");
		for (var i = 0; i < anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("rel")) {
				var rel = anchor.getAttribute("rel");
				var external = false;
				if (rel.indexOf(" ") > 0) {
					while (rel.indexOf(" ") > 0 && external == false) {
						if (rel.substr(0, rel.indexOf(" ")) == "external") {
							external = true;
						}
						rel = rel.substr(rel.indexOf(" ") + 1, rel.length - rel.indexOf(" ") + 1);
					}
				}
				if (rel == "external") {
					external = true;
				}
				if (anchor.getAttribute("href") && external == true) {
					anchor.target = "_blank";
				}
			}
		}
		return;
	}




	$.fn.hoverClass = function(c) {
		return this.each(function(){
			$(this).hover(
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
			);
		});
	};


	function MM_openBrWindow(theURL,winName,features) { //v2.0
		window.open(theURL,winName,features);
	}

	function popup(URL,width,height) {
		if (!width) {
			width = 600;
		}
		if (!height) {
			height = 600;
		}
		MM_openBrWindow(URL,'','scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=yes,left='+((screen.width-width) / 2)+',top='+((screen.height-height) / 2)+',width=' + width + ',height=' + height);
		return false;
	}



	var browserType;

	if (document.layers) {browserType = "nn4"}
	if (document.all) {browserType = "ie"}
	if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

	function hide() {
		for (var i = 0; i < hide.arguments.length; ++i) {
			if (browserType == "gecko" )
				document.poppedLayer = document.getElementById(hide.arguments[i]);
			else if (browserType == "ie")
				document.poppedLayer = document.all[hide.arguments[i]];
			else
				document.poppedLayer = document.layers[hide.arguments[i]];
			document.poppedLayer.style.visibility = "hidden";
			document.poppedLayer.style.display = "none";
		}
	}

	function show() {
		for (var i = 0; i < show.arguments.length; ++i) {
			if (browserType == "gecko" )
				document.poppedLayer = document.getElementById(show.arguments[i]);
			else if (browserType == "ie")
				document.poppedLayer = document.all[show.arguments[i]];
			else
				document.poppedLayer = document.layers[show.arguments[i]];

			document.poppedLayer.style.visibility = "visible";
			document.poppedLayer.style.display = "block";
		}
	}
})(jQuery);


