// JavaScript Document
// +++ update_176 ---
$(document).ready(function(){	
	// +++ update_176 +++
	// Hauptmenu
	$(".scrollerBox div.scrollable").scrollable({
		size: 1,  
		hoverClass: 'hover',
		clickable: false
	}).navigator(".navi").mousewheel();
	// --- update_176 ---


	// +++ update_135 +++
	//////////////////////////////
	// Warenkorb Slider
	//////////////////////////////
	// +++ update_181 +++
	$(".slider-box .inner").scrollable({
		size: 7
	});
	// ---update_181 ---
	
	var cartOpen = false;												 
	var btnCart = true;												 
	var btnWish = false;
	
	sliderClose = function(){
		if (cartOpen == true){
			$('#cartSlider').animate({"bottom": "-=100px"}, "slow");
			$('.btnSlider').css('background-position','0 0')
			cartOpen = false;
		}
	}

	sliderOpen = function(setTimer){
		if (cartOpen == false && setTimer == 'timer'){
			$('#cartSlider').animate({"bottom": "+=100px"}, "slow", function(){setTimeout("sliderClose()", 1000);});
			$('.btnSlider').css('background-position','0 -30px');
			cartOpen = true;
		}else	if (cartOpen == false){
			$('#cartSlider').animate({"bottom": "+=100px"}, "slow");
			$('.btnSlider').css('background-position','0 -30px');
			cartOpen = true;
		}
	}
	
	// Auf- / Zuslider
	$(".btnSlider").click(function () {
		if (cartOpen == true){
			$('#cartSlider').animate({"bottom": "-=100px"}, "slow");
			$(this).css('background-position','0 0')
			cartOpen = false;
		}else{
			$('#cartSlider').animate({"bottom": "+=100px"}, "slow");
			$(this).css('background-position','0 -30px')
			cartOpen = true;
		}
	});

// Button für Wishlist
	$(".btnWish").click(function () {
		if (btnCart == true){
			$('#slider-wish').addClass('activ');
			$('#slider-cart').removeClass('activ');
			btnCart = false;
			btnWish = true;
		}
		sliderOpen();
	});
	
	// Button für Warenkorb
	$(".btnCart").click(function () {
		if (btnWish == true){
			$('#slider-cart').addClass('activ');
			$('#slider-wish').removeClass('activ');
			btnCart = true;
			btnWish = false;
		}
		sliderOpen();
	});
	
	//Aus Warenkorb löschen
	$('.delete').click(function (id) {
					
		// +++ update_140 +++		
		// Enthält Zieladresse für Ajax-Funktion inkl. Variablen
		action = $(this).attr('title');
		
		// Löschen per Ajax aufrufen
		$.post(action, function(data){
			reloadCart();			
		});	
		// --- update_140 ---
								 
		$(this).parent().animate({
			marginTop: "150px",
			opacity: 0
		}, "slow", "swing", function(){
			$(this).remove();
		});
		
		setTimeout("sliderClose()", 500);
	});

	deleteCartItem = function() {
		$('.delete').click(function (id) {
									 
			// +++ update_140 +++		
			// Enthält Zieladresse für Ajax-Funktion inkl. Variablen
			action = $(this).attr('title');
			
			// Löschen per Ajax aufrufen
			$.post(action, function(data){
				reloadCart();									
			});	
			// --- update_140 ---
									 
			$(this).parent().animate({
				marginTop: "150px",
				opacity: 0
			}, "slow", "swing", function(){
				$(this).remove();
			});
			api.reload().prev();
			
			setTimeout("sliderClose()", 500);
		});
	}
	
	/////////////////////////////
	// END: Warenkorb Slider
	//////////////////////////////
	// --- update_135 ---

	// Dropdown-Menu
//	$(".dropDown a").click(function() {
//		$(this).next().slideToggle('normal');
//		if (this.flip==1) {
//			$(this).css('background-position','3px 9px');
//			this.flip = 0;
//		} else {
//			$(this).css('background-position','3px -21px');
//			this.flip = 1;
//		}
//	}).next().hide();

	// +++ update_201 +++
	// Navi
	// original
	/*
	$('#navi ul li').hover(function(){
		n = $(this).find('div');
		n.css('display','none');
		t = setTimeout("naviDown(n)", 500);
	},
	function () {
  	clearTimeout(t); 
		$(this).find('div').css('display','none');
	});
	
	naviDown = function(){
		n.css('display','block');
	}
	*/
	
	// +++ update_135 +++
	// NAVI TIMEOUT
	
	// +++ update_365 +++
	var x = 0;
	// --- update_365 ---
	
	$('#navi ul li[class^="nav"]').hover(function(){
		tab = $(this).find('a:first');
		n = $(this).find('div:first');
		t = setTimeout(function(){naviDown(n,tab);}, 500); 
		clearTimeout(x); 
	
	},function(){
		clearTimeout(t); 
		x = setTimeout(function(){naviUp(n,tab);}, 500); 									
	});

	function naviDown(n,tab){
		$('#navi ul li[class^="nav"]').each(function(){
			$(this).find('div:first').hide();
			if(!$(this).find('a:first').hasClass('active')){
				$(this).find('a:first').css('background-position','0 0');
			}
		});
		tab.css('background-position','0 -54px');
		n.show();
	}
	
	function naviUp(n,tab){
		if(!tab.hasClass('active')){
			tab.css('background-position','0 0');
		}
		n.hide();
	}
	// --- update_135 ---
	///
	
	// --- update_201 ---

	//Formfields
	// +++ update_222 +++
	$("input[type='text'], input[type='password'], textarea").focus(function () {
		$(this).addClass('activ');
	});
	$("input, textarea, select").blur(function () {
		$(this).removeClass('activ');
	});
	// --- update_222 ---

	// Suche
	$(".search02, .search03").hover(function(){
		$(this).find('div:first:hidden').css({visibility: "visible",display: "none"}).show(400);
	},function(){
		$(this).find('div:first').hide('fast');
	});
	
	// NEUE Suche
	// +++ update_274 +++
	$(".search02").click(function(){
		$(this).find('a').toggleClass('active');
		$("#co-search").toggle();
		hideIntelliSearch();
	});
	$(".search03").click(function(){
		$(this).find('a').toggleClass('active');
		$("#th-search").toggle();
		hideIntelliSearch();
	});
	
	$('input[name=keywords]').click(function(){
		$('#intelliSearchResult').show();																		 
	});
	
	hideIntelliSearch = function(){
		if( $(".search02").find('a').hasClass("active") || $(".search03").find('a').hasClass("active") ){
			$('#intelliSearchResult').hide();	
		}else{
			$('#intelliSearchResult').show();	
		}
	};
	// --- update_274 ---
	
	$("#co-search a span.c-hover").click(function() {
		if($(this).hasClass("active") == true ){
			$(this).removeClass("active");
		}else{
			$(this).addClass("active");
		}
	});

	// Accordion
	// +++ update_185 +++
	// +++ update_222 +++
	var myURL = document.location.toString();
	if (myURL.match('#')) { // the URL contains an anchor
	  // click the navigation item corresponding to the anchor
	  var myAnchor = myURL.split('#')[1];
	  myAnchor = myAnchor - 1;
	  //alert(myAnchor);
	 }
	 else {
		var myAnchor = 0;
	 }
	
	$(".showhide h3").eq(0).removeClass("minus");
	$('.boxContentSH').eq(0).hide();
	$(".showhide h3").eq(myAnchor).addClass("minus");
	$('.boxContentSH').eq(myAnchor).show();
	// --- update_222 ---

	$(".showhide h3").click(function() {
		if (this.flip==1 || $(this).hasClass("minus")) {
			$(this.parentNode).find('.boxContentSH').hide();
			$(this).removeClass("minus");
			this.flip = 0;
		} else {
			$(this.parentNode).find('.boxContentSH').show();
			$(this).addClass("minus");
			this.flip = 1;
		}
	});
	// --- update_185 ---
	
	//Farbwähler
	var color;
	$(".btnColor, .cPad a").click(function(){
		$('#colorSelect').slideToggle('normal');
		if (color==1) {
			$('.btnColor').css('background-position','left top');
			color = 0;
		} else {
			$('.btnColor').css('background-position','left -24px');
			color = 1;
		}
	}).next().hide();


	// Farb-Plätchen Austauschen
	$(".cPad a").click(function() {
		var pTitle = $(this).attr("title");
		var pStyle = $(this).find('span').attr("style");
		var pImg = $(this).find('span').html();
		
		$('#color-selected').find('a').attr({
			title: pTitle
		});
		$('#color-selected a span').replaceWith('<span style=" '+ pStyle + '">' + pImg + '</span>');
	});
	
	// Tooltipp
	$(".tt a").hover(function() {
			// Beschreibung der Farbe steht im title-Attribut des a-Tags !!!
			var title = $(this).attr("title");

			if ($.browser.msie) {
				$(this).after('<div class="tooltip"><p>'+title+'</p></div>');
				$(this.parent).find(".tooltip").stop(true, true).show().animate({top: "-33"}, "fast");
			}
			else {
				$(this).after('<div class="tooltip"><p>'+title+'</p></div>');
				$(this.parent).find(".tooltip").stop(true, true).animate({opacity: "show", top: "-33"}, "fast");
			}
		}, 
		function() {
			if ($.browser.msie) {
				$(this.parent).find(".tooltip").remove();
			}
			else {
				$(this.parent).find(".tooltip").remove();
			}
	});		
	

	// TABS 
	$("ul.tabs").tabs("div.panes > div"); 
	$("ul.tabs-search").tabs("div.panes-search"); 		

	// +++ update_190 +++
	openTab = function(tabIndex) {
		var api = $("ul.tabs").tabs();
		api.click(tabIndex);
	}
	// --- update_190 ---


	// +++ update_90 +++
	// Script in js.php des Produktes ausgelagert
	// --- update_90 ---

	// Alle Checkboxen selektieren
	checkAll = (function( id, pID ){
		 $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
	});


	// +++ update_99 +++
	b_changeValue = (function( id ){
		 
		 // Wert lesen
		 val = $("#" + id).val();
		 		 
		 // Setzen
		 if (val == 0)
		 {
			 $("#" + id).val(1);
		 }
		 else
		 {			 
			 $("#" + id).val(0);
		 }
	});
	// --- update_99 ---
});

// +++ update_266 +++
function winOpen (url, w, h) {
	param = 'width='+ w +',height='+h+',status=no,scrollbars=auto,resizable=no';
	fenster = window.open(url, "fenster1", param);
	fenster.focus();
}
// --- update_266 ---