/*** NATIVE *******************************************************************/
/***Clearing for Inputs***/
function clearInput(obj, cpValue) {
	if(obj.value == cpValue) { obj.value = ''; }
}
/***Clearing for TextAreas***/
function clearTextArea(obj, cpValue) {
	if(obj.innerHTML == cpValue) { obj.innerHTML = ''; }
}

/*** JQUERY *******************************************************************/
/**
 * this function is for simulation the bind() function like in mootools
 */
jQuery.extend({
	  shove: function(fn, object) {
	    return function() {
	      return fn.apply(object, arguments);
	    }
	  }
});
/**
 * function for slideable login header
 * @author			Markus Brunner
 */
function displaySlidableLogin(initialHeight,layerOpacity) {
	if(initialHeight == '') {initialHeight = '-118px';}
	if(layerOpacity == '') {layerOpacity = '1.0';}

	/* initial positioning */
	jQuery('#login-layer').show().css({'top':initialHeight});

	/* initial opcity: opacity:0.9;filter:alpha(opacity=90); */
	/*jQuery("#top-login-div").show().css({'opacity':layerOpacity});*/

	/* click-action for open-button */
	jQuery("#login-button").click(
		function(){
			/* std: jQuery('#top-login-div').slideToggle("slow");*/
			if(jQuery('#login-layer').css('top') == initialHeight) {
				jQuery('#login-layer').animate(
					{top: '0px'},500,'swing'
				);
			} else {
				jQuery('#login-layer').animate(
					{top: initialHeight},500,'swing'
				);
			}
		}
	);

	/* click-action for close-button */
	jQuery("#close-login-div").click(
		function(){
			/* std: jQuery('#top-login-div').slideUp("slow");*/
			jQuery('#login-layer').animate(
				{top: initialHeight},500,'swing'
			);
		}
	);

	/* special selectbox selection */
	jQuery('.special-select').mouseover(function()
	{
		jQuery('.special-select-sublist').show();
		jQuery('.special-select').find('.jScrollPaneContainer').show();
	});
	jQuery('.special-select').mouseout(function()
	{
		jQuery('.special-select-sublist').hide();
		jQuery('.special-select').find('.jScrollPaneContainer').hide();
	});
}
/**
 * Open link functions
 */
var openLinkStatus = 0;
function openLinkUrl(linkUrl) {
	if(linkUrl != '/' && openLinkStatus == 0) {
		openLinkStatus = 1;
		window.location = linkUrl;
		openLinkStatus = 0;
	}
}
/***jQuery product-box-link initialization***/
function initProductBoxLinks() {
	jQuery('.product-box:not(.openpopup)').each(function(index,elem){
		jQuery(elem).click(function() {
			boxLink = jQuery(elem).find('a').attr('href');
			openLinkUrl(boxLink);
		});
	});
}
/**
 * Open Pop-Up-Functions
 */
var websiteWidth = 980;
var popupid = 'popup';
var popuplayerid = 'popuplayer';
var popupcontentid = 'popupcontent';
var closePopupClass = 'closepopup';
var enablePopupCloseButton = true;
function openPopUpByAjaxContent(url) {
	jQuery.ajax({
		url:url,
		success:function(data) {
			openPopUp(data);
		},
		dataType:'html'
	});
}
function openPopUpByAttributeForBigImage(elem,dataAttribute) {
	var content = '<div class="align-center"><img src="'+jQuery(elem).attr(dataAttribute)+'" alt="" class="displayinline" /></div>';
	openPopUp(content);
}
function openPopUpByContentId(contentSelector) {
	openPopUp(jQuery(contentSelector).html());
}
function openPopUp(content) {
	var content;
	if(enablePopupCloseButton) {
		content = content+'<div class="'+closePopupClass+'">&nbsp;</div>';
	}
	if(jQuery('#'+popupid).length > 0) {
		jQuery('#'+popupcontentid).html(content);
	} else {
		content = '<div id="'+popupid+'" style="display:none"><div id="'+popuplayerid+'" class="'+closePopupClass+'">&nbsp;</div><div id="'+popupcontentid+'">'+content+'</div></div>';
		jQuery('body').append(content);
	}
	var leftMargin = (jQuery('body').innerWidth() - websiteWidth) / 2;
	/*var topMargin = (jQuery('body').innerHeight() - jQuery('#'+popupcontentid).innerHeight()) / 5;*/
	var topMargin = 128;
	jQuery('#'+popuplayerid).css({'backgroundColor':'white','opacity':'0.5'});
	jQuery('#'+popupcontentid).css({'left':leftMargin+'px','top':topMargin+'px'});
	jQuery('#'+popupid).fadeIn();
}
function closePopUp() {
	jQuery('#'+popupid).fadeOut('slow');
	jQuery('#'+popupcontentid).html('');
}
/***jQuery product-variation initialization***/
function initProductVariations() {
	jQuery('.product-image-wrapper').each(function(index,elem){
		jQuery(elem).find('.product-image > a').each(function(index,elem){
			if(index != 0) {
				jQuery(elem).css({'display':'none','visibility':'hidden'});
			}
		});
		jQuery(elem).find('.product-image-variants > li > img').each(function(index,elem){
			jQuery(elem).mouseover(jQuery.shove(function(innerElem){
				var productImageLinks = jQuery(this.outerElem).parents('.product-image-wrapper').find('.product-image > a');
				jQuery(productImageLinks).css({'display':'none','visibility':'hidden'});
				var visibleImage = jQuery(productImageLinks)[this.outerIndex];
				jQuery(visibleImage).css({'display':'inline-block','visibility':'visible'});
			},{outerIndex:index,outerElem:elem}));
		});
	});
}
/***jQuery initialization***/
google.setOnLoadCallback(function() {
	/* jQuery - Broken Image Handling */
	(function($) {
		$(document).ready(function(){
			/***error handling for not found images***/
			$("img").error(function(){
				$(this).hide();
			});
			/***slideable login***/
			login_initialHeight = '-118px';
			login_layerOpacity = '1.0';
			displaySlidableLogin(login_initialHeight,login_layerOpacity);
			/***close popup***/
			$('.'+closePopupClass).live('click', function(ev) {
				ev.preventDefault();
				closePopUp();
			});
			/***jqzoom***/
			var jQZoomOptions = {
				zoomWidth: 300,
				zoomHeight: 250,
				xOffset: 10,
				yOffset: 0,
				position: "right",
				title: false
			};
			$('.jqzoom').jqzoom(jQZoomOptions);
			$('.jqzoom:first').css({'visibility':'visible'});
			/***product-image-variations***/
			initProductVariations();
			/***product-box-links***/
			initProductBoxLinks();
			/***jScrollPane***/
			$('.product-sublist').jScrollPane({showArrows:false,scrollbarWidth:22});
			$('.jScrollPaneContainer').hide();
		});
	})(jQuery);
});

