/**
 * @author jkl
 */
jQuery().ready(function(){
	togle_searchin();

	if(jQuery('#kws_input').attr('value') == '') {
		jQuery('#kws_input').attr('value', ' ');
	}

	jQuery('#kws_input').focus(function(){
		if(jQuery(this).attr('value') == ' ') {
			jQuery(this).attr('value', '');
		}
	});

	jQuery('#kws_input').blur(function(){
		if(jQuery(this).attr('value') == '') {
			jQuery(this).attr('value', ' ');
		}
	});

	jQuery('#kws_form').submit(function(){
		if(jQuery('#kws_input').attr('value') == ' ') {
			jQuery('#head_submit').blur();
			return false;
		}
	});

	jQuery('.gtooltip').bind('mouseover', function(){
		// grafische Tooltips anzeigen
		var sItemText = "";
		sItemText = jQuery(this).attr('id').split("_")[1]; //e.g. help_cart --> cart
		if (sItemText != ""){
			var sDisplayTooltip = "#tooltip_" + sItemText;
			showTooltip(sDisplayTooltip, 1);
		}
	});

	jQuery('.gtooltip').bind('mouseout', function(){
		// grafische Tooltips verbergen
		var sItemText = "";
		sItemText = jQuery(this).attr('id').split("_")[1]; //e.g. help_cart --> cart
		if (sItemText != ""){
			var sDisplayTooltip = "#tooltip_" + sItemText;
			showTooltip(sDisplayTooltip, 0);
		}
	});

// Listener fuer die Tab-Navigation
	jQuery('#content_4tabs li a').click(function(){
		jQuery('#content_4tabs li').each(function() {
			jQuery(this).removeClass('active');
		});

		jQuery('#stage_content .reiter').each(function() {
			jQuery(this).removeClass('off');
			jQuery(this).addClass('off');
		});

		if(jQuery(this.parentNode).hasClass('r_01')) {
			jQuery('#stage_main1').removeClass('off');
		}

		if(jQuery(this.parentNode).hasClass('r_02')) {
			jQuery('#stage_main2.reiter').removeClass('off');
		}

		if(jQuery(this.parentNode).hasClass('r_03')) {
			jQuery('#stage_main3.reiter').removeClass('off');
		}

		if(jQuery(this.parentNode).hasClass('r_04')) {
			jQuery('#stage_main4.reiter').removeClass('off');
		}

		jQuery(this.parentNode).addClass('active');
		jQuery(this).blur();
	});

	
	function fixThumbnailImage() {
		var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
		if (badBrowser) {
		 jQuery('.thumbnail').each(function() {
			   if (!this.complete) {
				 this.onload = function() { fixPng(this) };
			   } else {
				 fixPng(this);
			   }
			 });
		}
	 }
	
	/**
	 * Listener fuer die whishlist:
	 */
	jQuery('.stage_wishlist').click(function() {
		jQuery('#popup_wishlist_con').fadeIn(950, function() {
		   // apply the fix only on the product image shown in the wishlist popup	
			fixThumbnailImage();
			jQuery('#popup_wishlist_con').fadeIn(950);
			jQuery('#close_pw').click(function() {
				jQuery('#popup_wishlist_con').fadeOut(750);
			});
			window.setTimeout(function() {
				jQuery('#popup_wishlist_con').fadeOut(950);
			}, 3000);
		});
	});
	
	/**
	 * LISTENER FUER DIE HOVER-BILDER
	 *
	 * @usage
	 * 1. <img src="dir/img.bla" class="img_over" alt="neu" />
	 * 2. im Verzeichnis dir muss ein bild namens img_hover.bla liegen
	 */
	var myAppend = '_over';
	var myOldSrc = '';
	var myNewSrc = '';
	jQuery('.img_over').hover(function() {
		myOldSrc = jQuery(this).attr('src');
		if(jQuery(this.parentNode.parentNode.parentNode).hasClass('open')) {return false;}
		myOldSrc = jQuery(this).attr('src');
		myNewSrc = myOldSrc.replace(/^((.+)([\/]+))+([^.\/]+)([.a-z]+)/, "$1$4"+myAppend+"$5");
		jQuery(this).attr('src', myNewSrc);
	}, function() {
		jQuery(this).attr('src', myOldSrc);
		if(jQuery(this.parentNode.parentNode.parentNode).hasClass('open')) {return false;}
		myOldSrc = '';
		myNewSrc = '';
	});

	function togle_searchin() {
		var i_myWidth = document.width;
		if(i_myWidth < 965) {
			jQuery('#h_search').attr('style', 'display: none;');
		} else {
			jQuery('#h_search').attr('style', 'display: block;');
		}
	}

	function showTooltip(sDisplayTooltip, onoff) {
		if (onoff == 1) {
			jQuery(sDisplayTooltip).show();
		}
		else {
			jQuery(sDisplayTooltip).hide();
		}
	}


	/* Avoid dotted lines on links when clicked */
	var badBrowser = (/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");
		if (badBrowser) { ;} // nichts machen im IE6, dieser kann Blur nicht
		else { // Listener auf Links setzen
			jQuery('a').click(function () {
				if (jQuery(this).blur)
					jQuery(this).blur();
			});
		};
	
	
	function togle_searchin() {
		var i_myWidth = document.width;
		if(i_myWidth < 965) {
			jQuery('#h_search').attr('style', 'display: none;');
		} else {
			jQuery('#h_search').attr('style', 'display: block;');
		}
	}

	function showTooltip(sDisplayTooltip, onoff) {
		if (onoff == 1) {
			jQuery(sDisplayTooltip).show();
		}
		else {
			jQuery(sDisplayTooltip).hide();
		}
	}


	/* Avoid dotted lines on links when clicked */
	var badBrowser = (/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32");
		if (badBrowser) { ;} // nichts machen im IE6, dieser kann Blur nicht
		else { // Listener auf Links setzen
			jQuery('a').click(function () {
				if (jQuery(this).blur)
					jQuery(this).blur();
			});
		}
});
