﻿$(document).ready(function() {
	$('.clickPrice').click(
		function() {
			$('.clickPrice, .viewPrice').hide();
			$('.hideprice').show().css('display', 'inline');
		}
	);
	$('.hover').hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace('.jpg', '_hover.jpg').replace('.gif', '_hover.gif'));
		},
		function() {
			$(this).attr('src', $(this).attr('src').replace('_hover.jpg', '.jpg').replace('_hover.gif', '.gif'));
		}
	);
	$('.tbLabel, .enteremail').focus(function(){
		if ($(this).val()==$(this).attr("title"))
		{
			$(this).val('').css('color', '#000');
		}
	}).blur(function(){
		if ($(this).val()=='')
		{
			$(this).val($(this).attr("title")).css('color', '#666');
		}
	});
	$('#Searchtb').focus(function(){
		if ($(this).val()=="Enter Search Terms")
		{
			$(this).val('').css('color', '#000');
		}
	}).blur(function(){
		if ($(this).val()=='')
		{
			$(this).val("Enter Search Terms").css('color', '#666');
		}
	}).keydown(function(e) {
		if(e.keyCode == 13) {
			doSearch();
			return false;
		}
	});
	$('.searchSubmit').click(doSearch);
	$('.prodThumb').click(function(){
		$('img.mainProdImg').attr('src', $(this).attr('src').replace('/thumb/', '/large/'));
	});
	$('.whatBlem').click(function(){
		$.prompt($('.blemsContent').html());
	});
});

function doSearch()
{
	if ($('#Searchtb').val()!=="Enter Search Terms")
	{
		window.location=BaseUrl+"/search.aspx?searchstr=" + $('#Searchtb').val();
	}
	else
	{
		window.location=BaseUrl+"/search.aspx"
	}
};

// Added For Wait Processing
function HideTip( elemID ){$('#' + elemID).hide();};
function ShowWait( elemID ){$('#' + elemID).show(); window.setTimeout('ShowProgressImg()',100);};
function ShowProgressImg(){$('.imgProcessDisplay').attr('src',$('.imgProcessDisplay').attr('src'));};

/*Shoe Size Selector*/
var sizeList = readCookie("ShoeSizeList");
sizeList = (sizeList==null)?'':sizeList;
var widthList = readCookie("ShoeWidthList");
widthList = (widthList==null)?'':widthList;
$(document).ready(function() {
	$('#WidthSelect div, #SizeSelect div, #SizeSelectEcco div').hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);
	$('#SizeSelect div').click(
		function() {
			if ($(this).hasClass("disabled"))
			{
				return;
			}
			$('#GalleryItemsDisplay').fadeTo(250,.01);
			var sizes = this.id.split('-')[1].split('_');
			for (var x=0; x<sizes.length; x++)
			{
				if ($(this).hasClass("active"))
				{
					sizeList = sizeList.replace(sizes[x]+',', '');
				}
				else
				{
					sizeList += sizes[x]+',';
				}
			}
			$(this).toggleClass("active");
			$.get(BaseUrl+"/ShoesGet.aspx?"+$('#QSParamList').val(), {sz:sizeList,w:widthList,gt:$('#GalleryTitle').text()}, shoegetCallback);
			createCookie("ShoeSizeList",sizeList,30);
		}
	);
	$('#WidthSelect div').click(
		function() {
			if ($(this).hasClass("disabled"))
			{
				return;
			}
			$('#GalleryItemsDisplay').fadeTo(250,.01);
			if ($(this).hasClass("active"))
			{
				widthList = widthList.replace(this.id.split('-')[1]+',', '');
			}
			else
			{
				widthList += this.id.split('-')[1]+',';
			}
			$(this).toggleClass("active");
			$.get(BaseUrl+"/ShoesGet.aspx?"+$('#QSParamList').val(), {sz:sizeList,w:widthList,gt:$('#GalleryTitle').text()}, shoegetCallback);
			createCookie("ShoeWidthList",widthList,30);
		}
	);
	$('.pagenum').click(pagenumClick);
});
function shoegetCallback(data)
{
	$('#GalleryItemsDisplay').html(data);
	$('#GalleryItemsDisplay').fadeTo(250,1);
	$('.pagenum').click(pagenumClick);
};
function pagenumClick()
{
	$('#GalleryItemsDisplay').fadeTo(250,.01);
	$.get($(this).attr("href").replace("shoes.aspx", "shoesget.aspx"), shoegetCallback);
	return false;
};
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; domain=golfshoesonly.com; path=/";
};
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};
function eraseCookie(name) {
	createCookie(name,"",-1);
};