$(document).ready(function(){ 
	
	var config = {    
		over: makeTall, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: makeShort // function = onMouseOut callback (REQUIRED)    
	};
	
	function makeTall() {
		$(this).find("a:first").addClass("hover");
		$(this).find(".submenu").fadeIn('slow');
	}
	
	function makeShort() {
		$(this).find("a:first").removeClass("hover");
		$(this).find(".submenu").fadeOut('fast');
	}
	
	$("#mainNavigation li").hoverIntent( config );
	
	$("#loginpoplink").hover(function(){
		$(this).find("a:first").addClass("active");
		$(".loginpop").show();
	},function(){
		if ( !$(this).hasClass('active') )
		{
			$(this).find("a:first").removeClass("active");
			$(".loginpop").hide();
			$('#err_wishlist_noacc').hide();
		}
	});
	$('#loginpoplink a:first').click(function(e){
		e.preventDefault();
		
		if($('#wishlistproduct').length > 0) {
			$('#wishlistproduct').remove();
		}
		
		if ( $(this).parent().hasClass('active') )
		{
			$(this).parent().removeClass('active');
			$(".loginpop").hide();
			$('#err_wishlist_noacc').hide();
		}
		else {
			$(this).parent().addClass('active');
			$(".loginpop").show();
		}
	});
	
	$('#login input').focus(function(e){
		$('#loginpoplink').addClass('active');
	});
	
	// Wishlist while not logged in
	$('#wishlist_noacc').click(function(e){
		e.preventDefault();
		
		$('#err_wishlist_noacc').show();
		
		return false;
	});
	
	$('#OpenLoginToWish').click(function(e){
		e.preventDefault();
		
		// Variant ID
		var variantId = $('#jgd_dd_variantdropdown dt a').children('span.value').html();
		
		// Set Wishlist Item to Login
		if($('#wishlistproduct').length > 0) {
			$('#wishlistproduct').val(variantId);
		} else {
			var wishlistproduct = "<input type='hidden' name='wishlistproduct' value='" + variantId + "' id='wishlistproduct' />";
			$('#login').prepend(wishlistproduct);
		}
		
		// show Login-Popup
		$('#loginpoplink').addClass('active');
		$('#loginpoplink a:first').addClass('active');
		$(".loginpop").show();
	});
	/*
	 $(".shop_cantrol a.shop").click(function(e){
		 e.preventDefault();
	 });
	 */
	if($('.pro_vrgallery_start').length > 0) { 
		$('.pro_vrgallery_start').tinycarousel();
	}
	$(".shopcantrol").hover(function(){
         $(this).find(".shoppingcart").show();
		 $('.shoppro_gallery').tinycarousel({ axis: 'y' });
		 $(this).find(".shopdetail").addClass("shopdetailover")
		
		 },function(){
		 $(this).find(".shoppingcart").hide();
		 $(this).find(".shopdetail").removeClass("shopdetailover")
	});	 	 
	 
	$(".passend_gallery ul").hover(function(){
		 $(this).parents(".pro_vrgallery").addClass("glindex");
		
		 },function(){
		 $(this).parents(".pro_vrgallery").removeClass("glindex");
	});
	 
	 
	/* ------------ Startseite Slider ------------ */
    $('#home_slider li:first').fadeIn(1000, function() {
   	 var cyclenav = "<div id='cyclenav' class='cyclenav'></div>";
   	 $('#home_slider').append(cyclenav);
        $('#home_slider ul').cycle({
       	 timeout: 6000, 
       	 pauseOnPagerHover: 1, 
       	 pager: '#cyclenav',
       	 pagerAnchorBuilder: function(idx, slide) { 
       		 return '<a id=' + idx + ' href="#">&nbsp;</a>'; 
       	    }	 
        });
    });

	/* ------------ Revival Slider ------------ */
	$('#revival_slider li:first').fadeIn(1000, function() {
		var cyclenav = "<div id='cyclenav' class='pager'></div>";
		$('#revival_slider').append(cyclenav);
		$('#revival_slider ul').cycle({
			timeout: 6000,
			pauseOnPagerHover: 1,
			pager: '#cyclenav',
			pagerAnchorBuilder: function(idx, slide) {
				return '<a id=' + idx + ' href="#">'+$('#revival_slider ul li').eq(idx).children('h3').html()+'</a>';
			}
		});
	});

	 
	 /* ------------ Product Detail - Groessenberater ---------------- */
	 /* cupdrag bustdrag waistdrag hipdrag kidsdrag  */
	 	$('#cupdrag').hover(function(){
			$('.brustum-line').addClass('active');
			$('.unterbrust-line').removeClass('active');
			$('.tailienum-line').removeClass('active');
			$('.hueft-line').removeClass('active');
			$('.bodyheight-line').removeClass('active');
		});
		$('#bustdrag').hover(function(){
			$('.brustum-line').removeClass('active');
			$('.unterbrust-line').addClass('active');
			$('.tailienum-line').removeClass('active');
			$('.hueft-line').removeClass('active');
			$('.bodyheight-line').removeClass('active');
		});
		$('#waistdrag').hover(function(){
			$('.brustum-line').removeClass('active');
			$('.unterbrust-line').removeClass('active');
			$('.tailienum-line').addClass('active');
			$('.hueft-line').removeClass('active');
			$('.bodyheight-line').removeClass('active');
		});
		$('#hipdrag').hover(function(){
			$('.brustum-line').removeClass('active');
			$('.unterbrust-line').removeClass('active');
			$('.tailienum-line').removeClass('active');
			$('.hueft-line').addClass('active');
			$('.bodyheight-line').removeClass('active');
		});
		$('#kidsdrag').hover(function(){
			$('.brustum-line').removeClass('active');
			$('.unterbrust-line').removeClass('active');
			$('.tailienum-line').removeClass('active');
			$('.hueft-line').removeClass('active');
			$('.bodyheight-line').addClass('active');
		});
		
		$('.popup_menu span').click(function() {
			var elementid = $(this).attr('id');
			$('.popup_menu span').removeClass('active');
			$(this).addClass('active');
			
			$('.pro_img div').hide();
			
			if(elementid == "K") {
				$('.smsf-kid').show();
				
				$('.women').hide();
				$('.womenmen').hide();
				$('.men').hide();
				$('.kids').show();
				
			} else if(elementid == "H") {
				$('.smsf-male').show();
								
				$('.women').hide();
				$('.womenmen').show();
				$('.men').show();
				$('.kids').hide();
				
				
				
			} else {
				$('.smsf-female').show();
				
				$('.women').show();
				$('.womenmen').show();
				$('.men').hide();
				$('.kids').hide();
				
			}
		});
		/* ------------ Product Detail - Groessenberater ---------------- */
	 

/*
* ATTRIBUTFILTERUNG
* */
	$('.refinesearch li a').click(function(e) {
		e.preventDefault();
		var checkElement = $(this).next('div.option_popup');

		if ( !$(this).hasClass('active') )
		{
			$('.refinesearch li a').removeClass('active');
			$('.option_popup').removeClass('show-popup');
			$(this).addClass('active');
			checkElement.addClass('show-popup');
			Cufon.refresh();
		}
		else
		{
			$(this).removeClass('active');
			checkElement.removeClass('show-popup');
		}
		return false;
	});

	
    // Attributes Single Value
    $(".refinesearch .groselist ul li a").click(function() {
        var attriId = $(this).attr('rel');
        var attriValue = $(this).html();
        $('<input type="hidden" value="' + attriValue + '" name="' + attriId + '" />').appendTo('form#filterList');
        $(this).parents("#filterList").submit();
        return false;
    });

    // Form Attributes Submit
    $(".refinesearch #btnsubmitFilter").click(function() {
        $("#filterList").submit();
        return false;
    });

    $(".pro_vrgallery .overview li").hover(function(){
		 $(this).find(".proname").show();
		},function(){
		 $(this).find(".proname").hide();
	 });
	 
	  $(".refinesearch").hover(function(){
		 
		 $(this).prev(".pro_gallery").find("a").removeClass("pro_img");
		}, function(){
			
		});
	 
	  $(".mainkonto").hover(function(){
		 $('.shopdetail').addClass("minusindex")
		 },function(){
		 $('.shopdetail').removeClass("minusindex")
	  });
	  
	  function getParameter(paramName) {
		  var searchString = window.location.search.substring(1),
		      i, val, params = searchString.split("&");

		  for (i=0;i<params.length;i++) {
		    val = params[i].split("=");
		    if (val[0] == paramName) {
		      return unescape(val[1]);
		    }
		  }
		  return null;
	  }
	  
	// FAQ Help Main , CMS: 'oxhelpdefault'
	if($('#hilfe_content').length > 0) {
		
		$('.help_content .suggestion').hide(); //Hide/close all containers
		
		var gotoparam = getParameter('scrollto');//"help_shipping";
		if(gotoparam != "" && gotoparam != null) {
			// Open 'var gotoparam'
		 	$('.help_content li#'+ gotoparam).find('h4:first').addClass('active').next().show();
			// Scroll to 'var gotoparam'
		 	$('html, body').animate({ scrollTop: $("#" + gotoparam).offset().top }, 500);
		} else {
			$('.help_content li h4:first').addClass('active').next().show(); 
			//Add "active" class to first trigger, then show/open the immediate next container
		}
			
		//On Click
		$('.help_content h4').click(function(){
			if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
				$('.help_content h4').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
				$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
			}
			return false; //Prevent the browser jump to the link anchor
		});
	}
	
	// Product Detail - scroll to moreinfo
	$('.gotomoreinfo').click(function(e){
		e.preventDefault();
		$('html, body').animate({ scrollTop: $("#moreinfo").offset().top }, 500);
		return false; //Prevent the browser jump to the link anchor
	});
	
	
	$(".registration_page .form_detail input.tip").focus( function(e){
		var offset = $(this).offset();
		var inwidth = $(this).width();
		var tipheight = $(".formtooltip").height();
		var tiptopposition = tipheight / 2;
		$(".formtooltip").css({'left': offset.left + inwidth + 20, 'top': offset.top - tiptopposition +26 });
		//$(".formtooltip").show();
	});
	$(".registration_page .form_detail input.tip").live("focus blur", function(e) {
		var el = $(".formtooltip");
		var tiptext = $(this).attr("title");
		if (tiptext != ""){
			$(".formtooltip").show().find(".tooltip p").text(tiptext);
		}
	});
		
	$(".registration_page .form_detail input.tip").focusout( function(){
		$(".formtooltip").hide();
	});
		
				//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function(e) {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
		
		var mousex = e.pageX + 20; //Get X coodrinates
		var mousey = e.pageY - 200;
		
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="closepop">&nbsp;</a>');
	
		//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
	
		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		if ( $.browser.msie ) {
			if($.browser.version=='6.0'){
				$('#' + popID).css({'top': mousey + popMargTop});
			}
		 } else {
			
		 }
	
	
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
	
		return false;
	});
	
	//Close Popups and Fade Layer
	$('a.closepop, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.closepop').remove();  //fade them both out
		});
		return false;
	});
	
	 $(".pro_vrgallery a.tip").hover( function(e){
		var offset = $(this).offset();
		var inwidth = $(this).width();
		var tipheight = $(".gallerytooltip").height();
		var tiptopposition = tipheight / 2;
		$(".gallerytooltip").css({'left': offset.left + inwidth + -220, 'top': offset.top - tiptopposition +26 });
		
		$(".gallerytooltip").show();
		});
		$(".pro_vrgallery a.tip").live("hover blur", function(e) {
				var el = $(".formtooltip");
				var tiptext = $(this).attr("title");
				$(".gallerytooltip").show().find(".tooltip p").text(tiptext);
			});
		
		$(".pro_vrgallery a.tip").hover( function(){
			$(".gallerytooltip").hide();
		});
	

		$(".pflegehinweise a").click(function(e){
			e.preventDefault();
			return false;
		});
	$(".pflegehinweise a, .farben a").hover(function(){
		$(this).css('cursor','default').children('img').attr('title','').attr('alt','');
        tip = $(this).find('.tip');
        tip.show(); //Show tooltip
	}, function() {
		tip.hide(); //Hide tooltip
	}).mousemove(function(e) {
		var offset = $(this).offset();
		var mousex = e.pageX - offset.left + 20; //Get X coodrinates
		var mousey = e.pageY - offset.top  + 20; //Get Y coordinates
		var tipWidth = tip.width(); //Find width of tooltip
		var tipHeight = tip.height(); //Find height of tooltip

		/*
		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight + 30;
		}
		*/

		// Absolute position the tooltip according to mouse position
		tip.css({  top: mousey, left: mousex });
	});

        /*-----------------------------------------------------    Lieferanschrift auswählen -------------------------------------------*/
        $('#radiobillship').click(function () {
            $('div.form_detail span.val').removeClass("cur");
            $(this).parent().next().addClass("cur");
            //Packstation deakaktivieren
            $('#pack').removeClass("open");
            $('#packstation').slideUp("normal");
            $('#packstation :input').attr('disabled', 'disabled');
            //Lieferadresse deaktivieren
            $('#delivery').removeClass("open");
            $('#shippingform').slideUp("normal");
            $('#shippingform :input').attr('disabled', 'disabled');
        });
        /*------------------------------------------------------------------------------------------------------------------------------*/

        /*-----------------------------------------------------    Seperate Lieferadresse   -------------------------------------------*/
        // Seperate Lieferadresse
        $('#radiodelivery').click(function () {
            $('div.form_detail span.val').removeClass("cur");
            $(this).parent().next().addClass("cur");
            $('#shippingform :input').removeAttr('disabled');
            //Lieferadresse einblenden
            $('#delivery').addClass("open");
            $('#shippingform').slideDown("normal");
            //Packstation ausblenden
            $('#pack').removeClass("open");
            $('#packstation').slideUp("normal");
            $('#packstation :input').attr('disabled', 'disabled');
        });
        /*------------------------------------------------------------------------------------------------------------------------------*/

        /*-----------------------------------------------------       Packstation            -------------------------------------------*/
        // Packstation als Lieferadresse
        $('#radiopack').click(function () {
            $('div.form_detail span.val').removeClass("cur");
            $(this).parent().next().addClass("cur");
            $('#packstation :input').removeAttr('disabled');
            //Lieferadresse einblenden
            $('#pack').addClass("open");
            $('#packstation').slideDown("normal");
            //Lieferadresse ausblenden
            $('#delivery').removeClass("open");
            $('#shippingform').slideUp("normal");
            $('#shippingform :input').attr('disabled', 'disabled');
        });
        /*------------------------------------------------------------------------------------------------------------------------------*/
       // Löschen Warenkorb
       $('.carttable .deletecart').click(function () {
           $(this).prev("input").val("1");
       });
       // Checkout Payment absenden
       $('.checkout #paymentNextStepTop').click(function () {
           $("form#payment").submit();
       });
       // Order absenden AGB prüfen
       $('#orderConfirmAgbBottom #btnSubmitOrderBottom').live('click', function () {
           if (!$( '#orderConfirmAgbBottom input[type=checkbox]' ).attr('checked')) {
               $( '#orderConfirmAgbBottom #agbErrorMessage' ).addClass('show');
               return false;
           } else {
        	   if ($( '#orderConfirmAgbBottom input[type=checkbox]' ).attr('checked')) {
                   $( '#orderConfirmAgbBottom #agbErrorMessage' ).removeClass('show');
               }
           }
       });
       /* // Order absenden AGB prüfen
       $('#orderConfirmAgbBottom input[type=radio]').click(function () {
           if ($( '#orderConfirmAgbBottom input[type=checkbox]' ).attr('checked')) {
               $( '#orderConfirmAgbBottom #agbErrorMessage' ).removeClass('show');
           }
       }); */
       
       $(".oxValidate").oxInputValidator();
       
       
       // Sizefinder Menu Hover
       $('.popup_menu.sizefinder span').mouseover(function() {
 		  Cufon(this, {
 			fontFamily: 'BentonSans Bold',
 			color: '#005695'
 		  });
 	  });
 	  $('.popup_menu.sizefinder span').mouseout(function() {
 		  
 		  Cufon(this, {
 				fontFamily: 'BentonSans Bold',
 				color: '#8B929B'
 			 });
 			Cufon('.popup_menu.sizefinder span.active', {
				fontFamily: 'BentonSans Bold',
				color: '#005695'
			 });
 	  });
 	 $('.popup_menu.sizefinder span').live('click', function() {
			 Cufon('.popup_menu.sizefinder span', {
				fontFamily: 'BentonSans Medium',
				color: '#8B929B'
			 });
			$(this).addClass('active'); 
			Cufon(this, {
				fontFamily: 'BentonSans Bold',
				color: '#005695'
			 });
	  });
 	 
 	
 	 $('#btn_forgotpwd').live('click', function() {
 		$('#forgotpwdform').submit();
 	 });
 	 
 	$("#smvariantselect dt a").click(function(){
 		var element = $(this).parent();
 		var isActive = jQuery(element).hasClass('active');
 		var childDropdown = jQuery('#smvariantselect dd ul').css('display');
 		if(isActive && childDropdown == 'none') {
 			jQuery(element).removeClass("active");
 		} else if(!isActive && childDropdown == 'block') {
 			jQuery(element).addClass("active");
 		}
 		
 	});
 	
 	//Userdata - shop basket
 	if($("#userdataNoRegPlz").length){
 		var defaultCountryVal = $("#invCountrySelect").val();
 		
 		if(defaultCountryVal == 'a7c40f6320aeb2ec2.72885259') //�sterreich
 			$("#userdataNoRegPlz").attr("maylength", "4");
 		else $("#userdataNoRegPlz").attr("maylength", "5"); //sont 5 Stellen bei Plz (Deutschland)
 		
 	}
 	
 	//Cufon.replace('.value_teaser li', { fontFamily: 'Compatil Text LT Pro Italic' });
});
//BEstellübersicht drucken
    function printIt(printThis)
    {
        var win=null;
        win = window.open();
        win.document.open();
        win.document.write(printThis);
        win.document.close();
        win.print();
        win.close();
    }

//Form Attributes Reset
function resetFilter(resetFilterName){
		var delAttr    = $("#filterList").find("input[name='"+resetFilterName+"']").val();
        $('<input type="hidden" value="' + delAttr + '" name="resetFilter" />').appendTo('form#filterList');
        $("#filterList").submit();
        return false;
}     

//Userdata - shop basket - country changed
function editMaxLengthForPostcode(countryId, id){
	var maxPlzInput = "";
	if (countryId == 'a7c40f6320aeb2ec2.72885259') maxPlzInput = "4";
	else maxPlzInput = "5";
	
	$('#' + id).val("");
	$('#' + id).attr("maxlength", maxPlzInput); 		
}

function smChangebasket() {
	$('#tobasketform').submit();
}

/**
 * smShowOverlay function
 * @param string - sTitle Window title
 * @param string - sUrl Url to popUnder content
 * @param int - iWidth Width of popUnder window
 * @param int - iHeight Height of popUnder window
 */
function smShowOverlay(sTitle, sUrl, iWidth, iHeight) {
	var sCookieName = 'smNLOverlay';
	var sCookieValue = document.cookie;
    var sPattern = eval('/'+sCookieName+'=true/i');
    
    if (!sCookieValue.match(sPattern)) {
	    smSetCookie('smNLOverlay', false);
		tb_show(sTitle, sUrl + "&TB_iframe=true&height="+ iHeight +"&width="+iWidth, false);
    }
}

/**
 * smPopUnder function
 * @param string - sUrl Url to popUnder content
 * @param string - sTitle Window title
 * @param int - iWidth Width of popUnder window
 * @param int - iHeight Height of popUnder window
 * @param string - sCookieName Name of reload block cookie
 */
function smPopUnder(sUrl,sTitle,iWidth,iHeight,sCookieName,bSetCookie) {   
    // Get cookie for reload block
    var sCookieValue = document.cookie;
    var sPattern = eval('/'+sCookieName+'=true/i');

    if (!sCookieValue.match(sPattern)) {
        // Set position
    	var iLeft = (screen.width) ? (screen.width-iWidth)/2 : 100;
        var iTop  = (screen.height) ? (screen.height-iHeight)/2 : 100;
        // PopUnder parameter
    	var sParameter = 'width='+iWidth+',height='+iHeight+',top='+iTop+',left='+iLeft+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,dependent=no';

    	if(bSetCookie) {
            // Set cookie for reload block
    		smSetCookie(sCookieName,0);   
    	}

        var objWindow = window.open(sUrl,sTitle,sParameter);
        // Set popUnder in the background 
    	objWindow.blur();
        window.focus();
    }
}

/**
 * smSetCookie function
 * @param string - sCookieName Name of reload block cookie
 */
function smSetCookie(sCookieName,bReNewCookie) {   
    // Get cookie for reload block
    var sCookieValue = document.cookie;
    var sPattern = eval('/'+sCookieName+'=true/i');

    if (!sCookieValue.match(sPattern) || bReNewCookie) {
		// Set cookie for reload block
		var objDate = new Date();
		objDate = new Date(objDate.getTime()+2*86400000); // Reload block for 2 Days
		document.cookie = sCookieName+'=true; expires='+objDate.toGMTString()+';';
    }
}

// Variantendropdown
$(document).ready(function()
{
	jQuery('#selectqty1').jgdDropdown({
		callback: function(){smChangebasket();}
	});
	$('#jgd_dd_variantdropdown dd ul li a').click(function()
	{
		var variantId = $(this).children('span.value').html();
		var price = $("#variantdropdown option[value='"+variantId+"']").attr("rel");
		if(price)
		{
			$('div.price span#pricevalue').html(price);
			Cufon.refresh();
		}
	});
});
