var inputWdith = '200px';
var inputWdithReturn = '140px';
jQuery(document).ready(function() {
	jQuery('#searchForm input').focus(function(){
		//clear the text in the box.
		jQuery(this).val(function() {
		jQuery(this).val('');
	});
	//animate the box
	jQuery(this).animate({
		width: inputWdith
		}, 500 )
	});
	jQuery('nav #searchForm input').blur(function(){
		jQuery(this).val('suchen...');
		jQuery(this).animate({
		width: inputWdithReturn
		}, 800 )
	});
	jQuery('#openLogin.closed').live("click",function(e) {
		e.preventDefault();
		jQuery('#minibasket').hide();
		jQuery('#openEnquiryList').removeClass('open');
		jQuery('#openEnquiryList').addClass('closed');
		jQuery('#loginform').slideDown("fast", function() {
			jQuery('#openLogin').removeClass('closed');
			jQuery('#openLogin').addClass('open');
		});
	});
	
	jQuery('#openLogin.open, #closeLoginForm').live("click",function(e) {
		e.preventDefault();
		jQuery('#loginform').slideUp("slow", function() {		
			jQuery('#openLogin').removeClass('open');
			jQuery('#openLogin').addClass('closed');
		});
	});
	
	jQuery(document).ready(function(){
		jQuery('#mainmenu li.parent').hover(
			function() { jQuery('ul', this).css('display', 'block'); },
			function() { jQuery('ul', this).css('display', 'none'); });
	});
	
	jQuery(document).ready(function(){
		jQuery('#footerNav li.parent').hover(
			function() { 
				jQuery('ul', this).css('display', 'block'); 
				jQuery('#newsletterSignup').css('margin-top','120px');
				jQuery("html,body").animate({ scrollTop: jQuery('body').css('height') }, 0);
			},
			function() { 
				jQuery('ul', this).css('display', 'none'); 
				jQuery('#newsletterSignup').css('margin-top','0');
			});
	});
	
	jQuery('#openEnquiryList.closed').live("click",function(e) {
		e.preventDefault();
		jQuery('#loginform').hide();
		jQuery('#openLogin').removeClass('open');
		jQuery('#openLogin').addClass('closed');
		jQuery('#minibasket').slideDown("fast", function() {
			jQuery('#openEnquiryList').removeClass('closed');
			jQuery('#openEnquiryList').addClass('open');
		});
	});
		
	jQuery('#openEnquiryList.open, #closeCart').live("click",function(e) {
		e.preventDefault();
		jQuery('#minibasket').slideUp("slow", function() {		
			jQuery('#openEnquiryList').removeClass('open');
			jQuery('#openEnquiryList').addClass('closed');
		});
	});
	
	jQuery('#changeLanguage.closed').live("click",function(e) {
		e.preventDefault();
		jQuery('#chooseLanguage').slideDown("fast", function() {
			jQuery('#changeLanguage').removeClass('closed');
			jQuery('#changeLanguage').addClass('open');
		});
	});
	jQuery('#changeLanguage.open').live("click",function(e) {
		e.preventDefault();
		jQuery('#chooseLanguage').slideUp("normal", function() {		
			jQuery('#changeLanguage').removeClass('open');
			jQuery('#changeLanguage').addClass('closed');
		});
	});
	jQuery(function() {
        jQuery("#tabs").tabs();
    });
    jQuery(function() {
    	jQuery(".sorter select").sb();
    	
    });
    jQuery(function() {
    	jQuery("#frontCarousel").jCarouselLite({
    		 btnNext: "#next",
        	btnPrev: "#prev",
        	visible: 4,
        	scroll:1,
        	auto: 2500,
        	speed:600
    	});
    	jQuery("#carouselContainer").mouseover(function() {
    		jQuery("#prev,#next").show();
    	}).mouseleave(function () {
    		jQuery("#prev,#next").hide();
    	});
    });
     jQuery(function() {
        jQuery(".product-options select option").each(function() {
            var option = jQuery(this).text();
            jQuery(this).text(option.replace(/\+\u20AC\d[\d\,\.]+/,""));
        });
    });
    
    jQuery(function() {
		var container = jQuery('div.sliderGallery');
            var ul = jQuery('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            
            jQuery('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                step: 9,
                handle: '.handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
	});
	jQuery(function() {
		jQuery("#checkoutSteps").accordion({
			autoHeight: false
		});
	});
	jQuery("#feedback").mouseover(function() {
		jQuery(this).css("left","5px");
	}).mouseout(function() {
		jQuery(this).css("left","0");
	});
	jQuery("#catalogButton").mouseover(function() {
		jQuery(this).css("left","5px");
	}).mouseout(function() {
		jQuery(this).css("left","0");
	});
	
	jQuery(function() {
		if(jQuery("#tagFilter input:checked").length != 0) {
			jQuery("li.item").hide();
			jQuery("#tagFilter input:checked").each(function() {
				var tag = "."+jQuery(this).attr("value");
			
				jQuery(".products-list "+tag).fadeIn();
				if(jQuery(tag).length ==0) {
					jQuery(".products-list").append('<li class="grid_12 error"><p>No products were found</p></li>');
				}
			});
		}
	});
	jQuery(function() {
		jQuery("#tagFilter input").change(function(){
			jQuery("li.item").hide();
			jQuery(".error").remove();
			if(jQuery(this).attr("checked")){
				jQuery("#tagFilter "+"."+jQuery(this).attr("value")).attr("checked","checked");
			} else {
				jQuery("#tagFilter "+"."+jQuery(this).attr("value")).removeAttr("checked");
			}
			jQuery("#tagFilter input:checked").each(function() {
				var tag = "."+jQuery(this).attr("value");
				jQuery(".products-list "+tag).fadeIn();
				
				if(jQuery(".products-list "+tag).length ==0) {
					jQuery(".products-list").append('<li class="grid_12 error"><p>No products were found</p></li>');
				}
			});

		
			if(jQuery("#tagFilter input:checked").length == 0) {
				jQuery("li.item").fadeIn();
			}
		 
		});
	});
	
	jQuery(function() {
		jQuery("#zenFeedback").bind("click",function() {
			jQuery("#feedbackOverlay,#transparentOverlay").show();
			return false;
		});
	});
	jQuery(function() {
		jQuery("#closeOverlay, #transparentOverlay").bind("click",function() {
			jQuery("#feedbackOverlay,#transparentOverlay").hide();
			return false;
		});
	});
	jQuery(".messages").bind("click", function() {
		jQuery(".messages").hide();
	});
	jQuery(function() {
		if(jQuery(".messages .success-msg, .messages .error-msg ").length >0) {
			jQuery(".messages").show();
		}
	});

	jQuery(function() {
		jQuery(".product-options select option").each(function() {
			var option = jQuery(this).text();
			jQuery(this).text(option.replace(/\+\u20AC\d[\d\,\.]+/,""));
			jQuery(this).text(option.replace(/\+<span class=\"price\">\d[\d\,\.]+\s\u20AC<\/span>/,""));
		});
	});
	
	
	jQuery(function() {
			jQuery("#contactForm").validate({
				rules: {
					fbname: "required",
					fbcompany: "required",
					fbphone: "required",
					fbcountry: "required",
					fbemail: {
					required: true,
					email: true
					},
					fbsubject: "required",
					fbmessage: "required"
				},
				messages: {
					fbname: "Pflichtfeld",
					fbcompany: "Pflichtfeld",
					fbphone: "Pflichtfeld",
					fbemail: "Korrekte Emailadresse",
					fbcountry: "Pflichtfeld",
					fbsubject: "Pflichtfeld",
					fbmessage: "Pflichtfeld"
				},
				submitHandler: function() {
				
					var dataString = 'name='+ jQuery("input#fbname").val() + '&email=' + jQuery("input#fbemail").val() + '&company=' + jQuery("input#fbcompany").val() + '&phone=' + jQuery("input#fbphone").val()+ '&country=' + jQuery("input#fbcountry").val() + '&subject=' + jQuery("input#fbsubject").val() + '&message=' + jQuery("textarea#fbmessage").val();
   					
   					jQuery.ajax({
      					type: "POST",
      					url: "/de/libraries/feedback/bin/process.php",
      					data: dataString,
      					success: function() {
        					jQuery('#feedbackOverlay .moduletable').html("<div id='status'></div>");
        					jQuery('#status').html("<h2>Ihre Feedback wurde versendet!</h2>")
        					.append("<p>Sie erhalten eine Ticketnr. unseres Ticketsystems. Wir werden uns schnellst m&ouml;glich mit Ihnen in Verbindung setzen.</p>")
      					}
     				});
    				return false;
				}

			});
			
	});
});
