(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
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;
}

function showProduct(no)
{
	//alert(no);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	$("#overlay").css("height", arrayPageSize[1] + "px");
	$("#overlay").show();

	$("#productoverlaycontainer").html($("#product_" + no).html());
	$("#productoverlaycontainer").show();
	$('#productoverlaycontainer .productimage').cycle();
}
function hideProduct(no)
{
	$("#overlay").hide()
	$("#productoverlaycontainer").hide();
}

function validateForm(formObj)
{
	if(!formObj)
		return false;
		
	var isValid = true;
	for (var i=0;i<formObj.length;i++)
	{
		className = formObj[i].getAttribute('className');
		if(!className) className = formObj[i].getAttribute('class');
		if(className == "required")
		{
			type = formObj[i].type;
			if(type == "select-one")
			{
				if(formObj[i].selectedIndex == 0)
					isValid = false;
			}
			else
			{
				if(formObj[i].value == "")
					isValid = false;
			}
		}
	}
	if(!isValid)
		alert("You must complete the required fields marked with a star");
		
	return isValid;
}

function selectPattern(optionId, value, id)
{
	$("#productoverlaycontainer .pattern").removeClass("selectedpattern");
	$("#productoverlaycontainer #" + optionId).val(value);
	$("#productoverlaycontainer #" + optionId + "_" + id).addClass("selectedpattern");
}

$(document).ready(function(){
	$("#navigation ul li img").hover(function() {
		$(this).attr("src",$(this).attr("src").replace("off", "selected"));
	}, function() {
		if(!$(this).hasClass("active"))
			$(this).attr("src",$(this).attr("src").replace("selected", "off"));
	});
});