/* Filtering */
function initMenus() {
	$('dl.accordion-filter dd .acc-content').hide();
	$.each($('dl.accordion-filter'), function(){
		$('.acc-content:first').show();
		$('dl.accordion-filter dd a:first').find("span").addClass("open");
	});
	var checkedElements = new Array();
	var i = 0;
	$("input[type=checkbox][checked]").each(function () {
		checkedElements[i] = this;
		i++;
	});
	for(var i = 0; i < checkedElements.length; i++){
		$(checkedElements[i]).parents(".acc-content").show();
	}
	$('.accordion-filter > dd > a').click( function() {
		var checkElement = $(this).next();
		if ( ( checkElement.is('div.acc-content')) && (checkElement.is(':visible') ) )
		{
			return false;
		}
		if ( ( checkElement.is('div.acc-content') ) && ( !checkElement.is(':visible') ) )
		{
	 		excludedSlideUpDivs = new Array();
	 		var i = 0;
			$("input[type=checkbox][checked]").each(function () {
				var filterId = $(this).attr('id');
				var firstIndexOfUnderline = filterId.indexOf("_") + 1;
				var lastIndexOfUnderline = filterId.lastIndexOf("_");
				excludedSlideUpDivs[i] = filterId.substr(firstIndexOfUnderline, lastIndexOfUnderline - firstIndexOfUnderline);
				i++;
			});
			$('dl.accordion-filter div.acc-content:visible').hide();
			var filterElements = document.getElementById("accordion-filter-list");
			for(var i = 0; i < excludedSlideUpDivs.length; i++){
				$(filterElements.children[parseInt(excludedSlideUpDivs[i])-1]).find(".acc-content").show();
			}
			checkElement.slideDown('normal');
			$("dl.accordion-filter dd a span").removeClass("open");
			$(this).find("span").addClass("open");
			return false;
		}
	});
	$('.accordion-filter input').click(function(){
		window.location = $(this).next('label').children('a').attr('href');
	});
};

function doSliderFilterRequest(linkElement, sliderValues){
		var filterURL = $(linkElement).attr('href');
		var lastIndexOfAnd = filterURL.lastIndexOf("&");
		var newFilterURL = filterURL.substr(0, lastIndexOfAnd);
		var filterParam = filterURL.substr(lastIndexOfAnd + 1, filterURL.length);
		var indexOfEqualSign = filterParam.lastIndexOf("=");
		var filterParamKey = filterParam.substr(0, indexOfEqualSign);
		var newMinValue = $(sliderValues).find('.newFilterValueMin').html();
		var newMaxValue = $(sliderValues).find('.newFilterValueMax').html();
		newFilterURL = newFilterURL + "&" + filterParamKey + "=" + newMinValue + "+-+" + newMaxValue;
		window.location.href = newFilterURL;	
}
/* /Filtering */

$(document).ready(function(){
	$('body').removeClass('fontsize').removeClass('nojs');
	
	var resizeWin = function resizeWindow() {
		var winWidth = $(window).width();
		var isIESeven = false;

		if($.browser.msie) {
			if($.browser.version == "7.0") {
				isIESeven = true;
			}
		}
		
		if (isIESeven) {
			if ( winWidth > 990 )
			{
				$('html').css('overflow-x', 'hidden');
				$('html').css('overflow-y', 'scroll');
				$('body').css('position', 'relative');
			}
			else 
			{
				$('html').css('overflow-x', 'scroll');
				$('html').css('overflow-y', 'scroll');
				$('body').css('position', 'relative');
			}
		} else {
			if ( winWidth < 1024 && winWidth > 1000 )
			{
				$('body').addClass('noscroll');
			}
			else 
			{
				$('body').removeClass('noscroll');
			}
		}
	}
	
	$(window).bind("resize", resizeWin);
	$(window).bind("load", resizeWin);

	
	
	initMenus();

/*----------- Cufon font Class ---------------------------------------*/
/* Helvetica Neue LT Std */
Cufon.replace('.classname', { fontFamily: 'Helvetica Neue LT Std' , hover: true });
/* Helvetica Neue LT StdMcn */
Cufon.replace('.cart_gallery .title, .newsletter_box .newsletter_login, .checkout_head li, .action, .post_title, .product_grid .title, .addedvalues li, .category_banner h1 , .sicher_content h3 , .filiale_content .to_store a, .filiale_content .change_store a, .widecolumn .pageHead, .categoryhead_content h1 , .product_list h3, .pro_categorylist li span, .topsite_list li, #mainnavigation a.main , .online_shopbtn , .searchBox label , #miniBasket .detail .name , .search_btn ', { fontFamily: 'Helvetica Neue LT StdMcn', hover: true });
/* Helvetica Neue LT StdCn */
Cufon.replace('.error_404 p, .tagitem_200, .tagitem_300, .tagitem_400, .tagitem_500, .tab_content .detail_content h3, .hreview .rating_topic, .downloads .desc, .downloads a, #categories_flyout .inner ul li a.topic, #teaser .pagenum, .product_listing .title, .inhalt_box label, #catSlider .label , .tablist li a' , { fontFamily: 'Helvetica Neue LT StdCn', hover: true });
/* Helvetica Neue LT Stdrmn */
Cufon.replace('.featured_product h2 .light ', { fontFamily: 'Helvetica Neue LT Stdrmn' , hover: true });
/* Helvetica Neue LT Stdbd */
Cufon.replace('.product_detail h1.pro_name strong, .featured_product h2 strong, .action .actionprice,', { fontFamily: 'Helvetica Neue LT Stdbd' , hover: true });
/* Helvetica Neue LT Stdddcn */
Cufon.replace('.error_title, .post_title strong ,.tag .percent, .white_btn , .white_btnsmall , .black_btn , input.black_btn , .grey_btn, .weiter , .contact_info .phone  , .filiale_content .store , .comparison_box .pro_name h4', { fontFamily: 'Helvetica Neue LT Stdddcn' , hover: true });
/* Helvetica Neue LT Std hv */
Cufon.replace('.error_404 p strong, .tagitem_100, .price_content .price', { fontFamily: 'Helvetica Neue LT Std hv' , hover: true });
/* Helvetica Neue LT Std lightcn */
Cufon.replace('.account_title .title , .formdetail_list h3 , .accountpage_popup h3 , .checkout_title, .login_title, .product_detail .pro_name , .shopping_cart th, .head_cart, .voucher_search label, .compare tr.head, .ppt', { fontFamily: 'Helvetica Neue LT Std lightcn' , hover: true });
/* Helvetica LT Std */
Cufon.replace('.footer_services h3 ,.contact_info .nor', { fontFamily: 'Helvetica LT Std' , hover: true });	
/*----------- / Cufon font Class ---------------------------------------*/

});

// popup
$(document).ready(function()
{
	// When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click( function() {
		var popID = $(this).attr('rel'); // Get Popup Name
		var popURL = $(this).attr('href'); // Get Popup href to define size
				
		// 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="close">Schliessen</a>');
		
		// Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + 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
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=70)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
	});
	
	// Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
		}); //fade them both out
		
		return false;
	});
	
	// PrettyPhoto
	$("a[rel^='prettyPhoto'], a.prettyPhoto").prettyPhoto({
		social_tools: false,
		show_title: true,
		opacity: 0.8,
		theme: 'hellweg',
		markup: '<div class="pp_pic_holder"> \
					<div class="pp_content_container"> \
						<div class="pp_content"> \
							<div class="pp_details"> \
								<span class="ppt"></span> \
								<a class="pp_close" href="#">schlie&szlig;en</a> \
							</div> \
							<div class="pp_loaderIcon"></div> \
							<div class="pp_fade"> \
								<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
								<div class="pp_hoverContainer"> \
									<a class="pp_next" href="#">next</a> \
									<a class="pp_previous" href="#">previous</a> \
								</div> \
								<div id="pp_full_res"></div> \
							</div> \
						</div> \
					</div> \
				</div> \
				<div class="pp_overlay"></div>',
		gallery_markup:'<div class="pp_gallery"><a href="#" class="pp_arrow_previous">Previous</a><div><ul>{gallery}</ul></div><a href="#" class="pp_arrow_next">Next</a></div>',
		show_title: false,
		changepicturecallback: function(){
			$('.ppt').html( $('#tab1 h3').html() );
		},
		default_width: 800,
		default_height: 400,
		iframe_markup: '<iframe src="{path}?&iframe=true" width="{width}" height="{height}" frameborder="no"></iframe>',
		deeplinking: false
	});
	
	if ( $('#slideshow').size() > 0 )
	{
		$('#slideshow').cycle({
			speed:  1000, 
			timeout: 0, 
			pager:  '#slideshow_pager', 
			pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return '#slideshow_pager li:eq(' + idx + ') a'; 
			}
		});
	}
	
	if ( $('.marken_box').size() > 0 ) 
	{
		$('.marken_box ul').cycle();
	}
	
	$('body.prettyPhoto a.back_link').click(function(e){
		e.preventDefault();

		$.prettyPhoto.close();
	});
});



/* TABS */
$(function(){
	// On Click Event
	$("ul.tabs li").click(function(e) {
		e.preventDefault();

		var activeTab = $('.tab_content').eq( $('ul.tabs li').index( $(this) ) );
		if ( activeTab .is(':hidden') )
		{
			$('.tab_container').height( activeTab.outerHeight() );
			$( activeTab ).children('.manufacturer').children('img').load(function(){
				$('.tab_container').height( activeTab.outerHeight() );
			});
			$('.tab_content').stop();
			activeTab .fadeIn('fast').siblings('.tab_content').fadeOut('fast');
			$("ul.tabs li").removeClass("active");
			$(this).addClass("active");  
			Cufon.replace('.tablist li a', { fontFamily: 'Helvetica Neue LT StdCn', hover: true });
		}
		else {
			
		}
		
		return false;
	});
	

	$(".tab_content").hide(); 
	$("ul.tabs li:first").trigger('click');
	$("ul.tabs li:last").addClass("noborder");

	// Klick bei Kurzbeschreibung
	$('.zurbtn').click(function(e){
		e.preventDefault()
		$('ul.tabs li:first').click();
		location.hash = 'tabs';
		
		return false;
	});
	
	$('.zurbtn2').click(function(e){
		e.preventDefault()
		$('ul.tabs li:eq(1)').click();
		location.hash = 'tabs';
		
		return false;
	});
	
	// Klick auf Versandkostenlink bei Preisangabe
	$('#shipping_link').click(function(e){
		e.preventDefault();
		$('ul.tabs li a.shipping_link').click();
		location.hash = 'tabs';
		
		return false;
	});
});
/* /TABS */

jQuery(document).ready(function()
{
	$(".jgd-dropdown").live('mouseenter mouseleave',function(event){
		if (event.type == 'mouseenter') 
		{
			$(this).addClass('selectActive');
			$(".container").addClass('dropmenuActive');
			if( 200 < $(this).find("ul").height() )
			{
				$(this).addClass("dropdownScroll");
			}
		}
		if (event.type == 'mouseleave') 
		{
			if($(this).find("ul").css('display') == 'none') {
				$(this).removeClass('selectActive');
				$(".container").removeClass('dropmenuActive');
				$(this).children('ul').hide();
			}
		}
	});
});


/* Sliders */
$(document).ready(function()
{
	if ( $('#teaser').size() > 0 )
	{
		// Startseite
		$('#teaser').tinycarousel({ pager: true, interval: true, intervaltime: 5000, infinite: true });
	}
	
	if ( $('#catSlider').size() > 0 )
	{
		// Unterkategorien
		$('#catSlider').tinycarousel({});
	}
	
	if ( $('#productSlider').size() > 0 )
	{
		// Artikeldetailseite: Artikel aus gleicher Unterkategorie
		var start = $('#productSlider li').index( $('#productSlider a.active').parent('li') )-2;
		$('#productSlider').tinycarousel({start: start});
	}
	
	if ( $('#logoSlider').size() > 0 )
	{
		// Artikeldetailseite: hinzugefügte Logos
		$('#logoSlider').tinycarousel({axis: 'y'}); // axis y bug?
	}
	
	if ( $('#cartgallery').size() > 0 )
	{
		// Startseite
		$('#cartgallery').tinycarousel({ pager: true, interval: true });
	}
});


$(document).ready(function()
{
	/* DropDowns */
	//$("select").jgdDropdown();
	if ( !$('body').hasClass('blauarbeit') )
	{
		$("select").each(function(){
			if(jQuery(this).children('option:selected'))
			{
				$(this).jgdDropdown({initTitle:jQuery(this).children('option:selected').html()});
			}
			else
			{
				$(this).jgdDropdown({initTitle:jQuery(this).children('option').eq(0).html()});
			}
		});
		$('.dropdown').click(function(){
			$(this).children('ul').stop().show();
		});
		$('.dropdown').hover(
			function(){
				$(this).css({cursor: 'hand'});
			},
			function(){
				$(this).children('ul').stop().hide();
			}
		);
	}
});

/* Categories Flyout */
$(document).ready(function()
{
	$('.online_shopbtn').hoverIntent(
		function(){
			$('#categories_flyout').fadeIn('fast');
		},
		function(){
			
		},
		500
	);
	$('#mainnavigation').siblings('.clearfix').mouseleave(function(){
		$('#categories_flyout').fadeOut('fast');
	});
});
	
/* Forms */
$(document).ready(function()
{
	// Wenn in einem label doch mal ein input stecken sollte...
	$('label[for=loginPwd], label[for=newUser], label[for=noReg]').click(function(){
		var radio = $(this).children('input[type=radio]');
		radio.attr('checked',true);
		
		if ( radio.val() == 'knownCustomer' ){
			$('#openUserLink').hide();
			$('#loginButton').show();
			$('#openAccountLink').hide();
		}
		else if( radio.val() == 'newUser'){
			$('#openUserLink').hide();
			$('#loginButton').hide();
			$('#openAccountLink').show();
		}
		else {
			$('#openUserLink').show();
			$('#loginButton').hide();
			$('#openAccountLink').hide();
		}
	});
	$('input#loginUser').focus(function() {
		$('input[value=knownCustomer]').attr('checked', true);
		$('#openUserLink').hide();
		$('#loginButton').show();
		$('#openAccountLink').hide();
	});
	$(".oxValidate").oxInputValidator();
	
	$( '#reviewRating' ).oxRating({openReviewForm: false, hideReviewButton: false});
	
	$('form#rating').bind( "submit", function() {
		if($('input#productRating').length > 0)
		{
			if($('input#productRating').val() > 0)
			{
				return true;
			}
			else
			{
				$('li.rating').addClass('oxInValid');
				return false;
			}
		}
		else
		{
			return true;
		}
	});
});

/* FAQ */
$(document).ready(function()
{
	$('.faq dt').click(function(){
		$(this).next().slideDown().addClass('active').siblings('.active').slideUp().removeClass('.active');
	})
});
/* / FAQ  */

/* Filialauswahl Paymentseite */
function checksStore(item) {
	var shippingtype = $(item).parents("#jgd_dd_sStore").siblings('div.select_point').children("input#stores");
	if(shippingtype)
	{
		shippingtype.attr("checked","checked");
	}
	var storeid = $(item).children('span.value').html();
	//alert(storeid);
	var filltarget = $('#smSelectedStore');
	var baseUrl = '/index.php?';
	var url = baseUrl + 'cl=payment&fnc=getselectedstoredata&sStoreId=' + storeid + '&JSON=1';
	//alert(filltarget.html());
	$.getJSON(url, function(data)
	{
		if(!data.SMID)
		{
			filltarget.html("");
		}
		else
		{
			filltarget.html("<p>"+data.SMCOMPANY+"<br/>"+data.SMSTORENAME+"<br/>"+data.SMSTREET+" "+data.SMSTREETNUMBER+"<br/>"+data.SMZIPCODE+" "+data.SMCITY+"</p>");
			
		}
	});
}
$(document).ready(function(){
	$('#jgd_dd_sStore dd ul li a').click(function(){checksStore(this); })
	$('#stores').click(function(){ 
		checksStore($('#jgd_dd_sStore dt a')); 
	})
});


/* / Filialauswahl Paymentseite */
/* Aktionscode einlösen leer machen */
$(document).ready(function()
{
	$('input#voucherNr').focus(function()
	{
		if ($(this).val() == $('input#defaultVoucherNr').val())
		{
			$(this).val("");
		}
	});
	$('input#voucherNr').blur(function(){
		if ($(this).val() == "")
		{
			$(this).val($('input#defaultVoucherNr').val());
		}
	});
});
/*/ Aktionscode einlösen leer machen */
/* Startseite Filialauswahl Verlinkung zum Filiallink */

$(document).ready(function()
{
	$('#jgd_dd_sStoreStart dd ul li a').click(function()
	{
		var storeid = $(this).children('span.value').html();
		//$("#list option[value='2']").text()
		var link = $("#sStoreStart option[value='"+storeid+"']").attr("rel");
		if(link)
		{
			window.location.href = link;
		}
	})
	$('#jgd_dd_VariantSelect dd ul li a').click(function()
	{
		
		//alert("drin");
		$(this).parents('#jgd_dd_VariantSelect').siblings('input[type=hidden]').val($(this).children('span.value').html());
		//alert("test");
		$("form.oxProductForm input[name='fnc']").val("");
		//alert("test2");
		var form = $(this).closest("form");
		//$("form.oxproductForm").submit();
		$( ".oxProductForm input[name=anid]" ).attr( "value", $( ".oxProductForm input[name=parentid]" ).attr( "value" ) );
		form.submit();
	    return false;
	})
	$('#jgd_dd_similarproducts dd ul li a').click(function()
	{
		location.href = $(this).children('span.value').html();
		return false;
	})
});
/*/ Startseite Filialauswahl Verlinkung zum Filiallink */

/*  Thankyou Print Order*/
$(document).ready(function()
{
	$('span#terms').click(function()
	{
		if($('#additionalterms').css('display') === 'none')
		{
			$('#additionalterms').show();
		}
		else
		{
			$('#additionalterms').hide();
		}
	})
});
function printIt(printThis)
{
	var win=null;
	win = window.open();
	win.document.open();
	win.document.write(printThis);
	win.document.close();
	win.print();
	win.close();
}
				
/*  / Thankyou Print Order*/

/* */

/* TOP 5 Marken Slider */
$(document).ready(function() {
	if ( $('#product_slide').size() > 0 )
	{
		$('#product_slide').cycle({
	    	fx:      'fade',
	    	timeout:  4000
		});
	}
});
/* Zahlarten */
$(document).ready(function() {
    $('input[name=paymentid]').click(function(){
    	$('.select_point').find('dd.paymenttypes').removeClass('activePayment');
    	$(this).parent().siblings('dd').addClass('activePayment');
     });
});
/*/ Zahlarten*/

/* Produktvergleich */
$(document).ready(function(){
	var cntCompareItems = $('.comparison_box .photo').size();
	var activeCompareItem = 1;
	var maxVisibleCompareItems = 3;
	
	if ( cntCompareItems > maxVisibleCompareItems )
	{
		$('.comparison_box a.next').removeClass('disabled');
	}

	$('.comparison_box a.next, .comparison_box a.prev').click(function(e){
		e.preventDefault();
		
		if ( $(this).hasClass('next') ) 
		{
			if ( activeCompareItem <= cntCompareItems-maxVisibleCompareItems ) 
			{
				show = activeCompareItem+maxVisibleCompareItems;
				hide = activeCompareItem;
				activeCompareItem++;
			}
		}
		else 
		{
			if ( activeCompareItem > 1 ) 
			{
				show = activeCompareItem-1;
				hide = activeCompareItem+maxVisibleCompareItems-1;
				activeCompareItem--;
			}
		}

		// Produkt anzeigen 
		$('.comparison_box .product_'+show).show();
		$('.comparison_box .product_'+hide).hide();
		
		// Divider anzeigen (immer nur zwischen den angezeigten Produkte)
		$('.comparison_box .divider').hide();
		$('.comparison_box .product_'+activeCompareItem).next('.divider').show();
		$('.comparison_box .product_'+(activeCompareItem+1)).next('.divider').show();
		
		if ( activeCompareItem == 1 ) 
		{
			$('.comparison_box a.prev').addClass('disabled');
			$('.comparison_box a.next').removeClass('disabled');
		}
		else if ( (activeCompareItem+maxVisibleCompareItems-1) == cntCompareItems )
		{
			$('.comparison_box a.prev').removeClass('disabled');
			$('.comparison_box a.next').addClass('disabled');
		}
		else {
			$('.comparison_box a.prev').removeClass('disabled');
			$('.comparison_box a.next').removeClass('disabled');
		}
		
		return false;
	})
	
});
/*/Produktvergleich */


/* Bestellabschluss */
$(document).ready(function(e){
	$('#checkout button').click(function(e){
		if ( $('#voucherNr').val() != $('#defaultVoucherNr').val() )
		{
			e.preventDefault();
			$('form[name=voucher]').submit();
			
			
			return false;
		}
	});
});
/* /Bestellabschluss */

/* Expressversand-Zusatztext einblenden*/
$(document).ready(function(e){
	$('#jgd_dd_changepayment dd ul li a').click(function()
	{
		$('#Warnung').stop();
		if($(this).children('span.value').html()== 'mosDHLExpress')
		{
			$('#Warnung').slideDown('normal');
		}
		else
		{
			$('#Warnung').slideUp('normal');
		}/*
		$(this).parents('#jgd_dd_VariantSelect').siblings('input[type=hidden]').val($(this).children('span.value').html());
		//alert("test");
		$("form.oxProductForm input[name='fnc']").val("");
		//alert("test2");
		var form = $(this).closest("form");
		//$("form.oxproductForm").submit();
		$( ".oxProductForm input[name=anid]" ).attr( "value", $( ".oxProductForm input[name=parentid]" ).attr( "value" ) );
		form.submit();
	    return false;*/
	})
});

/*/ Expressversand-Zusatztext einblenden*/
