
/* Resize the window height when window is loaded and resized
 * Changed by Bikmaz 01.10.2008 
 */
$(window).load(function(){
  if ($(document).height() < getPageSize()[1]) setHeight();
}).resize(function(){
  if ($(document).height() < getPageSize()[1]) setHeight();
});


$(document).ready(function(){
	// dw to load the first image when opening detail view
	$('.article .image .picture ._pic .cont_img').children('img').attr("src",athl_img[1]);
	$('.article .image .lupe').children('a').attr("href",athl_img[2]);
	
	$('.article .icon').mouseover( function(){
		showAvailability($(this).parent().children('.availability'));
	});
	$('.article .icon').mouseout( function(){
		hideAvailability($('.availability'));
	});
	$('.article .availability').mouseover( function(){
		doShowAvailability = true;
	});
	$('.article .availability').mouseout( function(){
		hideAvailability($('.availability'));
	});
	
	$('#sort  a').mouseover( function(){
		$(this).children('img').attr("src",$(this).children('img').attr("src").replace(/red.gif/,'white.gif'));
	});	
	$('#sort  a').mouseout( function(){
		$(this).children('img').attr("src",$(this).children('img').attr("src").replace(/white.gif/,'red.gif'));
	});
	
	$('.arrows.active a').mouseover( function(){
		$(this).children('img').attr("src",$(this).children('img').attr("src").replace(/.gif/,'_on.gif'));
	});
	$('.arrows.active a').mouseout( function(){
		$(this).children('img').attr("src",$(this).children('img').attr("src").replace(/_on.gif/,'.gif'));
	});
		
	$('.colors img').click( function(){
		var pos = $(this).attr("id");
		$('.article .image .picture ._pic .cont_img').children('img').attr("src",athl_img[pos*3+1]);
		$('.article .image .picture ._pic .cont_img').children('img').attr("id",pos);
		$('.article .image .lupe').children('a').attr("href",athl_img[pos*3+2]);
	});
	

	// Basket-Hover
	$('.basket_inactiv_layer').each(function(){
		if($(this).hasClass('choose')){
			$(this).hover(
				function(){
					$(this).animate( { opacity: "0"} , 500);
					$(".chooseBgLayer").animate({backgroundColor:"#d70029"},500);
					$('.variant .tocart .cartnotice').fadeIn("slow");
				},
				function(){
					$(this).animate( { opacity: "0.6"} , 500);
					$(".chooseBgLayer").animate({backgroundColor:"#F2F2F2"},500);
					$('.variant .tocart .cartnotice').fadeOut("slow");
				}
			);
		}else if($(this).hasClass('notAvailable')){
			$(this).hover(
				function(){
					$(this).animate( { opacity: "0"} , 500);
					$("#infoBgLayer").animate({backgroundColor:"#d70029"},500);
					$('.variant .tocart .cartnotice').fadeIn("slow");
				},
				function(){
					$(this).animate( { opacity: "0.6"} , 500);
					$("#infoBgLayer").animate({backgroundColor:"#ffffff"},500);
					$('.variant .tocart .cartnotice').fadeOut("slow");
				}
			);
		}
	});
	
	
//Ich hab diese Flash statements herausgenommen, weil diese in 
//einem JSP-File sein müssen, damit ich den Pfad richtig angeben kann.
//jweiss, 12.3.2008
	
//	var so = new SWFObject("../flash/small_turntable.swf", "small_turntable", "175", "64", "8", "#420000");
//	so.addVariable("moviename", "");
//	so.write("flashcontent");
										   
//	var so = new SWFObject("../flash/big_turntable.swf", "big_turntable", "585", "300", "8", "#500001");
//	so.addVariable("baseUrl", "../flash/");
//	so.write("big_turntable");

	
	$(".resetfilter").click( function(){
		//alert("Filter: " + document.getElementById("id_productfilterselection_"+$(this).attr("id")).selectedIndex);
		document.getElementById("id_productfilterselection_"+$(this).attr("id")).selectedIndex=0;
		document.getElementById("productfilterForm").submit();
	});	
	
	/* rzg 03.02.2008 start */
	$('#tshirtprint').mouseover( function () {
		$(this).addClass('over');
		return false 
	}).mouseout	( function () {
		$(this).removeClass('over');
		return false 
	});
	$("#tshirtprint").click(function () { 
		//url des links auslesen und link ausführen 
		window.location=$(this).find("a").attr("href"); 
		return false 
	}); 
/* rzg 03.02.2008 end */	
	
	
});



function setHeight() {
	headerheight = $("#nav_sub").height() + $("#header").height() + $("#footer").height();
	var browserHeight = getPageSize()[1];
	var restHeight = browserHeight - headerheight;
	//index
	if ($("#overview").height() <=  restHeight ) {
		totalHeight = restHeight
		$("#overview").height(totalHeight);		
	}
	//$("#overview").height(getPageSize()[1]-headerheight);
	//login
	$("#MyAthleticum .formwrapper").height(getPageSize()[1]-headerheight);
	//detail
	$("#detail .articlewrapper").height(getPageSize()[1]-(headerheight+20));
	//kasse
	$("#wk #tablewrapper").height(getPageSize()[1]-(headerheight+68));
	//MyAthleticum
	$("#ml #tablewrapper").height(getPageSize()[1]-(headerheight+30));
	//bezahlen, versand
	$("#wk .formwrapper").height(getPageSize()[1]-(headerheight+68));
	//kontrolle, bestellen
	$("#wk #tableoverview").height(getPageSize()[1]-(headerheight+113));
}

var doShowAvailability = false;
function showAvailability(div) {
	doShowAvailability = true;
	window.setTimeout(function(){
		showShowAvailability(div)
	},300);
}
function showShowAvailability(div) {
	if (doShowAvailability) {
		$(div).show();
	}
}
function hideAvailability(div) {
	doShowAvailability = false;
	window.setTimeout(function(){
		hideHideAvailability(div)
	},300);
}
function hideHideAvailability(div) {
	if (!doShowAvailability) {
		$(div).hide();
	}
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	//var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

	return arrayPageSize;
}


