document.documentElement.className = 'js';



/*
 * jQuery doTimeout: Like setTimeout, but better! - v1.0 - 3/3/2010
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var f=d.call(arguments),e=b.apply(this,[c+f[0]].concat(f));return typeof f[0]==="number"||typeof f[1]==="number"?this:e};function b(l){var m=this,h,k={},g=l?$.fn:$,n=arguments,i=4,f=n[1],j=n[2],p=n[3];if(typeof f!=="string"){i--;f=l=0;j=n[1];p=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(f){k=a[f]||(a[f]={})}}k.id&&clearTimeout(k.id);delete k.id;function e(){if(l){h.removeData(l)}else{if(f){delete a[f]}}}function o(){k.id=setTimeout(function(){k.fn()},j)}if(p){k.fn=function(q){if(typeof p==="string"){p=g[p]}p.apply(m,d.call(n,i))===true&&!q?o():e()};o()}else{if(k.fn){j===undefined?e():k.fn(j===false);return true}else{e()}}}})(jQuery);



try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


jQuery(document).ready(function($) {
	
	
	
	
	Cufon.replace('.company_sections h1');
	Cufon.replace('.company_sections h2');
	Cufon.replace('.button_wrapper .nav_skin2');
	
	Cufon.replace('.control_1 .title');
	Cufon.replace('.control_1 p');
	Cufon.replace('.control_2 p');
	Cufon.replace('#intro .lk a');
	Cufon.replace('.control_3 dt');
	
	
	Cufon.replace('p#welcome span');
	Cufon.replace('#products_nav > ul > li > a', {hover: true});
	Cufon.replace('#steps span');
	Cufon.replace('.steps_nav a.nav');
	Cufon.replace('.choose_prize');
	Cufon.replace('.button_skin1 span');
	Cufon.replace('.product_list .quickview');
	Cufon.replace('.search_results .back');
	
	
	Cufon.replace('.outfit_slider .details');
	Cufon.replace('.button_skin2');
	Cufon.replace('.cart_lk');
	
	
	function disabledValueSelect (parent) {
		var select_item = parent.find('select');
		if(!select_item.length) {return false}
		for(i=0; i<select_item.length; i++) {
			var this_select = $(select_item[i]);
			var this_options = this_select.find('option');
			
			var selected = false;
			
			for(x=0; x<this_options.length; x++) { 
				if($(this_options[x]).attr('selected')) {
					selected = true;
				}
			}
			
			if(selected==false) {
			
				for(x=0; x<this_options.length; x++) {
					if(!$(this_options[x]).attr('disabled')) {
						this_select.val($(this_options[x]).val());
						break;
					}
				}
			
			}
			
			
		}
		
	}
	
	disabledValueSelect ($('body'));
	
	
	
	
	
	
	$('.replaceSelects').sSelect({ddMaxHeight: '190px'});

	$('input.replaceCheckbox').checkBox({addVisualElement: false});
	
	function categoryMenuFix () {
		var categoryMenu = $('.category_menu');
		if(!categoryMenu.length) {return false}
		var categoryMenuLks = $('.category_menu a');
		var categoryMenuImg = $('.category_menu img');
		var categoryMenuStr = $('.category_menu strong');
		var categoryMenuSpn = $('.category_menu span');
		 
		for(i=0; i<categoryMenuLks.length; i++) {
			
//			var off = (102-$(categoryMenuImg[i]).width())/2;
//			$(categoryMenuImg[i]).css('float','none');
//			$(categoryMenuImg[i]).css('margin-left',off);
			$(categoryMenuLks[i]).click(
				function(event) {
					window.location.href = $(this).attr('href');
				}							
			);
		}
		
		categoryMenu.css('visibility','visible');
		
	}
	
	categoryMenuFix();
	
	$(".category_menu a").click(function() {
	    window.location=$(this).attr("href"); return false;
    });
	
	function colorSelect () {
		
		var colorSelect = $('.FarbeSelect');
		if(colorSelect.length <= 0) {return false}
		colorSelect = $(colorSelect[0]);
		var colorSelectLi = colorSelect.find('li');
		$(colorSelectLi[0]).css('display','none');
		
		var colorSelectLk = colorSelect.find('a'); 
		var colorSelectOp = colorSelect.find('option');
		
		for(i=0; i<colorSelectLk.length; i++) {
			if( $(colorSelectOp[i]).attr('title') != 'Farbe' ){
				if( $(colorSelectOp[i]).attr('title') && $(colorSelectLk[i]) ) {
					$(colorSelectLk[i]).css('background-image', 'url(/templates/99/de/media/images/colors/' + $(colorSelectOp[i]).attr('title') + '.gif)');
				}
				if( $(colorSelectOp[i]).attr('class') && $(colorSelectLk[i]) ) {
					$(colorSelectLi[i]).addClass( $(colorSelectOp[i]).attr('class') );
				}
				if( $(colorSelectLk[i]).text() == $('.FarbeSelect .selectedTxt').text() ){
					var colornr = $(colorSelectOp[i]).attr('title');
					var colorname = colornr.replace(/9/g,"t&uuml;rkis").replace(/8/g,"schwarz").replace(/7/g,"braun").replace(/6/g,"blau").replace(/5/g,"rosa").replace(/4/g,"rot").replace(/3/g,"gr&uuml;n").replace(/2/g,"orange").replace(/1/g,"gelb").replace(/0/g,"weiss").replace(/gemustert/g,"gemust..");
					$('.FarbeSelect .selectedTxt').html('<div class="selectedColor" style="background-image:url(/templates/99/de/media/images/colors/' + $(colorSelectOp[i]).attr('title') + '.gif)"></div>' + colorname);
				}
			}
			
		}
		
	}
	
	colorSelect();
	
	
	
	function introSlider () {
		
		var intro = $('#intro');
		var introamount = $('#intro .slide').length;
		if(!intro.length) {return false}

		if ( introamount > 1 )
		{
			$.featureList(
				null,
				$("#intro .slide"), {
					nav_event: 'mouseover',
					pause_on_hover: true,
					transition_interval: 7000
				}
			);
		}
		
		var controls = $('#intro .controls');
		
		$('body').mousemove(function(event) {
 			$(controls[0]).fadeIn(2000);
		});
	}
	
	introSlider();
	
	
	
	
	
	
	function categoryMenuHover () {
		var category_menu_li = $('#products_nav > ul > li');
		
		if(!category_menu_li.length) {return false}
		
		category_menu_li.each(
		 	function( intIndex ){
		 			$( this ).bind (
						"mouseenter",
						function(){
							$(this).closest('#products_nav').find('.category_menu').css('visibility','hidden');
							$(this).find('.category_menu').css({'visibility':'visible', 'margin': 0});
							$.doTimeout('qw');
						}
					);
					
					$( this ).bind (
						"mouseleave",
						function(){
							var this_li = $(this);
							$.doTimeout('qw', 1000, function(){
								this_li.find('.category_menu').css({'visibility':'hidden'});									  
							});
						}
					);
		 
				}
		 
		);
		
		
	}
	
	categoryMenuHover();
	
	
	function linkOutfitSliderImages () {
		
		var outfitslider = $('#outfit_slider');
		if(!outfitslider.length) {return false}
		var outfitslider_img = outfitslider.find('img');
		
		outfitslider_img.css('cursor','pointer');
		for(i=0; i<outfitslider_img.length; i++) {
			$(outfitslider_img[i]).click(
				function () {
					var redirect = $(this).closest('li').find('a').attr('href');
					window.location.href = redirect;
				}					   
			);	
		}
	}
	
	linkOutfitSliderImages();
	
	
	function outfitGal () {
		var outfit_gallery = $('#outfit_gallery');
		if(!outfit_gallery.length) {return false}
		
		$.featureList(
			$("#outfit_thumbnails a"),
			$("#outfit_contents .outfit_content"), {
				auto_play : 'no',
				nav_event: 'click',
				after_transition: function(nr) {
					var sVariant = $('#outfit_thumbnails li').eq(nr).children('a').attr('rel');
					$('select#sAdd option[value='+sVariant+']').attr('selected','selected');
					$('.replaceSelects').resetSS();
				}
			}
		);
		
	}
	
	outfitGal();
	
	
	function tabs (parent) {
		var tabs_wrapper =  parent.find('.tabs_wrapper');
		if(!tabs_wrapper.length) {return false}
		var tabs_lk = parent.find('.tabs_nav a');
		
		
		
		
		tabs_lk.click(
			function(event) {
				$(this).closest('.tabs_nav').find('a').removeClass('selected');	
				$(this).closest('.tabs_wrapper').find('.tab_section').removeClass('selected_tab_section');
				$(this).addClass('selected');
				var target = $(this).attr('href');
				target = target.substr(target.indexOf('#')+1);
				$('#'+target).addClass('selected_tab_section');
				return false;
			}				  	
		);
		
		
		var moreLks = parent.find('.more');
		if(moreLks.length) {
		
			moreLks.click (
				function (event) {
					this_target = $(this).attr('href');
					for(i=0; i<tabs_lk.length; i++) {
						if($(tabs_lk[i]).attr('href')==this_target) {
							$(tabs_lk[i]).click();		
						}
					}
					return false;
				}			   
			)
		}
		
		
		
		var inlineLks = $('.tab_section a');
		if(inlineLks.length) {
		
			inlineLks.click (
				function (event) {
					this_target = $(this).attr('href');
					for(i=0; i<tabs_lk.length; i++) {
						if($(tabs_lk[i]).attr('href')==this_target) {
							$(this).addClass('inlineTabLk');
							$(tabs_lk[i]).click();		
						}
					}
					
					if($(this).hasClass('inlineTabLk')) {
						//$('body,html').scrollTop(0);
						$('body,html').animate({scrollTop: 0}, 500); 
						return false;
					}
				}			   
			)
		}
		
		
		
	}
	
	tabs ($('body'));
	
	function fixDiscount () {
		var discount = $('.discount');
		if(!discount.length) {return false}
		
		for(i=0; i<discount.length; i++) {
			$(discount[i]).css('width',$(discount[i]).width());	
		}
	}
	
	fixDiscount();
	
	
	
	window.updateThickbox = function () {
		
		disabledValueSelect ($('#TB_window'));
		function centerPreviewModule () {
			var ajax_preview_module = $('#TB_window .preview_module');
			if(ajax_preview_module.length) {
				$('#TB_window').css('top',$(window).scrollTop());		
			}
			
			var ajax_reserved_articles = $('#TB_window .reserved_articles');
			if(ajax_reserved_articles.length) {
				$('#TB_window').css('top',$(window).scrollTop());		
			}
		}
		
		centerPreviewModule ();
		
		
		Cufon.replace('#ajax_content .steps_nav a.nav');
		Cufon.replace('#ajax_content .button_wrapper .nav_skin2');
		fixDiscount();
		Cufon.replace('#ajax_content .cart_lk');
		$('#ajax_content .replaceSelects').sSelect({ddMaxHeight: '190px'});
		tabs ($('#ajax_content'));
		
		
		var newLists = $('#ajax_content .newList');
		newLists.css('height','');
		for(i=0; i<newLists.length; i++) {
			$(newLists[i]).css('height',$(newLists[i]).height());
		}
		
	}
	
	
	
	
	
	
	function defaultValues () {
		var inputs = $('#search_form input:text, #newsletter_form input:text, #Gift-Box input:text');
		if(!inputs.length) {return false}
		
		inputs.focus(
			function () {	
				if($(this).val()==$(this).attr('defaultValue') && !$(this).attr("readonly")) { $(this).val('');}	
			}
		);
		
		inputs.blur(
			function () {			
				if($(this).val()=='' && !$(this).attr("readonly")) { $(this).val($(this).attr('defaultValue'));}	
			}
		);
	}
	
	defaultValues();
	
	
	function accesDataHideInputs () {
		var trigger = $('.access_data input:checkbox');
		if(!trigger.length) {return false}
		if(trigger.attr('checked')) {
			$('.access_data .passwords').css('visibility','hidden');
		}
		trigger.change(
			function (event) {
				if($(this).attr('checked')) {
					$('.access_data .passwords').css('visibility','hidden');
				} else {
					$('.access_data .passwords').css('visibility','visible');
				}

			}			   
		)
	}
	
	accesDataHideInputs ();
	
	
	function couponModuleOptions () {
		var inputOptions =  $('.login_area .coupon_module input:radio');
		if(!inputOptions.length) {return false}
		
		$('#'+$('input[type=radio]:checked').attr('class')).css('display','block');
		
		inputOptions.change (
			function (event) {
				$('.login_area .coupon_module .credit_type').css('display','none');
				$('#'+$(this).attr('class')).css('display','block');
			}					 
		);
		
	}
	
	
	couponModuleOptions();
	
	
	function promoSlider () {
		
		var slider = $('#promos_wrapper ul');
		if(!slider.length) {return false}
		
		function nav_initCallback(carousel) {
			var this_carousel = carousel;
			
			carousel.buttonPrev.appendTo($('#promo'));
			carousel.buttonNext.appendTo($('#promo'));

		};
		
	
		$('#promos_wrapper ul').jcarousel({
					scroll: 1,
					initCallback: nav_initCallback
		});
	}
	
	promoSlider ();
	
	
	function outfitSlider () {

		var o_slider = $('#outfit_slider ul');
		if(!o_slider.length) {return false}
		
		function nav_initCallback(carousel) {
			var this_carousel = carousel;
			
			carousel.buttonPrev.appendTo($('#outfit_slider'));
			carousel.buttonNext.appendTo($('#outfit_slider'));
		};

		$('#outfit_slider ul').jcarousel({
			scroll: 1,
			visible: 1,
			initCallback: nav_initCallback
		});
	}
	
	outfitSlider ();
	
	

	$('.product_care a').click(function(){
		$('.carelabels').show();
	});
	
	$('.carelabels a').click(function(){
		$('.carelabels').hide();
	});
	
	
	// Category filters
	function updateCategoryList(url) {
		
		// find category, if false - get current top category
		var category = $('.category_sort .ui-radio-checked').prev().attr('value');
		if(typeof(category) == "undefined") category = $('#current_top_cat').attr('value');
		
		// gat farbe if set
		var currentOption = $('.FarbeSelect a.hiLite');
		var color = $('.FarbeSelect a').index(currentOption);
		if(color <= 0) {
			color = false;
		} else {
			color = $('.FarbeSelect option:eq(' + color + ')').attr('value');			
		}
		if(!color) color = '';
		
		// gat form if set
		var currentOption = $('.FormSelect a.hiLite');
		var form = $('.FormSelect a').index(currentOption);
		if(form <= 0) {
			form = false;
		} else {
			form = $('.FormSelect option:eq(' + form + ')').attr('value');
		}
		if(!form) form = '';
		
		// gat form if set
		var currentOption = $('.GroesseSelect a.hiLite');
		var size = $('.GroesseSelect a').index(currentOption);
		if(size <= 0) {
			size = false;
		} else {
			size = $('.GroesseSelect option:eq(' + size + ')').attr('value');
		}
		if(!size){
			size = '';
		}else{
			size = '&size=' + size;
		}
		
		if(url == '-size'){
			size = '&size=-1';
			url = ''
		}
		
		var reset = '';
		if(!color && !form && !size) reset = '-1'
			
		if(!url){
			url = '/shopware.php?sViewport=cat&sCategory=' + category + '&sFilterProperties=' + color + form + reset + size;
		}else{
			if(color || form){
				url = url + '?sFilterProperties=' + color + form + size;
			}
		}
		
		window.location.href = url;
		
		/*
		$.get(url, function(data){
			$(".product_list").html(data);
		});
		*/
		
	}
	
	function checkColorList(){
		var farbSelectOpt = $('.FarbeSelect').find('option');
		if(farbSelectOpt.length > 1) {return false}
		$('.FarbeSelect').hide();
	}
	checkColorList();
	$('.FarbeSelect .removeProperties').attr('title', 'Auswahl aufheben');
	$('.FormSelect .removeProperties').attr('title', 'Auswahl aufheben');
	$('.GroesseSelect .removeProperties').attr('title', 'Auswahl aufheben');
	
	
	if($('.FarbeSelect div.removeProperties')){
		$('.FarbeSelect div.removeProperties div').unbind();
		$('.FarbeSelect div.removeProperties .selectedTxt').css('background', 'url(/templates/99/de/media/images/removeProperties.gif) no-repeat right -1px transparent');
		$('.FarbeSelect div.removeProperties div').click(function() {
			updateCategoryList($('.FarbeSelect option.removeProperties').attr('value'));
		});
	}
	
	if($('.FormSelect div.removeProperties')){
		$('.FormSelect div.removeProperties div').unbind();
		$('.FormSelect div.removeProperties .selectedTxt').css('background', 'url(/templates/99/de/media/images/removeProperties.gif) no-repeat right -1px transparent');
		$('.FormSelect div.removeProperties div').click(function() {
			updateCategoryList($('.FormSelect option.removeProperties').attr('value'));
		});
	}
	
	if($('.GroesseSelect div.removeProperties')){
		$('.GroesseSelect div.removeProperties div').unbind();
		$('.GroesseSelect div.removeProperties .selectedTxt').css('background', 'url(/templates/99/de/media/images/removeProperties.gif) no-repeat right -1px transparent');
		$('.GroesseSelect div.removeProperties div').click(function() {
			updateCategoryList('-size');
		});
	}
	
	$('.category_sort label, .FarbeSelect a, .FormSelect a, .GroesseSelect a').click(function() {
		var url = '';
		if($(this).find('a').length > 0){
			url = $(this).find('a').attr("href");
		}
		updateCategoryList(url);
	});
	

	$('.inputs input, .inputs select').focus(function(){
		if ( $(this).parent('span').siblings('div.speechbubble').size() > 0 ) {
			$(this).parent('span').siblings('div.speechbubble').fadeIn();
		} 
	});
	$('.inputs input, .inputs select').blur(function(){
		if ( $(this).parent('span').siblings('div.speechbubble').size() > 0 ) {
			$(this).parent('span').siblings('div.speechbubble').fadeOut();
		} 
	});

	$('img.speechbubble').hover(function(){
		if ( $(this).siblings('div.speechbubble').size() > 0 ) {
			$(this).siblings('div.speechbubble').fadeIn();
		}
	},
	function(){
		if ( $(this).siblings('div.speechbubble').size() > 0 ) {
			$(this).siblings('div.speechbubble').fadeOut();
		} 
	});
	
	$('#chkmail').change(function(){
		if ( $(this).val() == '-1' )
		{
			$('#dpacheckboxdiv').slideUp();
		}
		else if ( $('#dpacheckboxdiv:hidden') ) 
		{
			$('#dpacheckboxdiv').slideDown();
		}
	});
});
