/*$(function() {

	// if the function argument is given to overlay,
	// it is assumed to be the onBeforeLoad event listener
	$("a[rel]").overlay({

		mask: '#ddc2b3',
		effect: 'apple',
		oneInstance: 'false',

		onBeforeLoad: function() {

			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");

			// load the page specified in the trigger
			wrap.load(this.getTrigger().attr("href"));
		}

	});
});*/

$().ready(function() {
 	$(".addcart290").click(function(){
      this.style.backgroundPosition = "0px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "0px -20px";
    });
});

$().ready(function() {
 	$(".addcart350").click(function(){
      this.style.backgroundPosition = "0px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "0px -20px";
    });
});

$().ready(function() {
 	$(".addcart390").click(function(){
      this.style.backgroundPosition = "-130px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "-130px -20px";
    });
});

$().ready(function() {
 	$(".addcart490").click(function(){
      this.style.backgroundPosition = "-260px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "-260px -20px";
    });
});

$().ready(function() {
 	$(".addcart590").click(function(){
      this.style.backgroundPosition = "-390px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "-390px -20px";
    });
});

$().ready(function() {
 	$(".addcart690").click(function(){
      this.style.backgroundPosition = "0px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "0px -20px";
    });
});

$().ready(function() {
 	$(".addcart890").click(function(){
      this.style.backgroundPosition = "0px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "0px -20px";
    });
});

$().ready(function() {
 	$(".addcart1500").click(function(){
      this.style.backgroundPosition = "0px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "0px -20px";
    });
});

$().ready(function() {
 	$(".info").click(function(){
      this.style.backgroundPosition = "-130px 0px";
    }).mousedown(function(){
      this.style.backgroundPosition = "-130px -20px";
    });
});



	
$(document).ready(function(){

	//$("ul.subsort").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subsort
	
	$("ul.topsort li div").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subsort itself (moving subsort up and down)
		$(this).parent().find("ul.subsort").slideDown('fast').show(); //Drop down the subsort on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subsort").slideUp('slow'); //When the mouse hovers out of the subsort, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	$("ul.topsort li span").hover(function() { //When trigger is clicked...
		
		//Following events are applied to the subsort itself (moving subsort up and down)
		$(this).parent().find("ul.subsort").slideDown('fast').show(); //Drop down the subsort on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subsort").slideUp('slow'); //When the mouse hovers out of the subsort, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});

var productList;
var timer;
var textbox;
var search = '';

function focusTyping(ctrl)
{
	if (ctrl.value != search)
		stopTyping();
}

function startTyping(ctrl)
{
	if (timer == null)
		textbox = ctrl;
	else
		clearTimeout(timer);
	timer = setTimeout("stopTyping()", 500);
}

function stopTyping()
{
	search = textbox.value;
	updateList("search", search);
}

function updateList(action, value)
{
	$.ajax({
		cache	: false,
		url		: "productlist.php?action=" + action + "&value=" + value,
		success	: function(data) {
					$("#productList").html(data);
					tb_init('a.thickbox.purchasethumb, area.thickbox.purchasethumb, input.thickbox.purchasethumb');
					/*productList = data;
					$("#productList").fadeOut('fast');
					setTimeout('$("#productList").html(productList).fadeIn(\'fast\')', 200);*/
				},
		error	: function (xhr, ajaxOptions, thrownError){
                    alert(xhr.responseText);
                }
	});
}

