(function($){
	$(function(){
		
		$('#brandSelect').change(function(){
			if($(this).val() != '')$('#brandJump')[0].submit();
		})
		
		$('.arrows').html('<img src="/common/images/btn-uparrow.gif" width="13" height="7" style="padding-bottom:3px;" class="upArrow" ><br /><img src="/common/images/btn-downarrow.gif" width="13" height="7"class="downArrow" >');
		
		var timers = {};
		
		$('.upArrow').click(function(){
			var val = 1 * $(this).parent('td').prev().children('input')[0].value;
			var valID = $(this).parent('td').prev().children('input')[0].name;
			if(timers[valID]) {clearTimeout(timers[valID])}
			timers[valID] = setTimeout("updateQty('"+valID+"','"+(val+1)+"')",600);
			$(this).parent('td').prev().children('input')[0].value = val + 1;
		});
		
		$('.downArrow').click(function(){
			var val = 1 * $(this).parent('td').prev().children('input')[0].value;
			var valID = $(this).parent('td').prev().children('input')[0].name;
			if(val  > 0) {
				if(timers[valID]) {clearTimeout(timers[valID])}
				timers[valID] = setTimeout("updateQty('"+valID+"','"+(val-1)+"')",600);
				$(this).parent('td').prev().children('input')[0].value = val - 1;
			}
		});
		
		
		$('.qty').change(function(){
			if(!isNaN(this.value)) {
				updateQty(this.name,this.value);
			}
		});
		
		
		$('.buyButton').click(function(){
			var tempName = $(this)[0].name.substring(3,$(this)[0].name.length);
			var tempQty = $('*[name=qty'+tempName+']').attr('value')*1.0;
			var tempString = "";
			if(isNaN(tempQty)) {
				tempQty = 1;
			} else {
				tempQty++;
			}
			 $('*[name=qty'+tempName+']').attr('value',tempQty);
			updateQty('qty'+tempName,tempQty);
			return false;
		});
		
		$('.photoPopUpLink').each(function(){
			var tempID = this.id.replace(/pop1Link|pop2Link/g,'');
			$('a[id$=Link'+tempID+']').lightBox();
		});
	})
})(jQuery)

		function updateQty(item,val) {
			var tempName = item.substring(3,item.length);
			var tempQty = (val == 0)?"":val;
			$('*[name=sub'+tempName+']')
				.css('display','none')
				.prev('img')
				.css('display','block').show('fast',function() {
					var tempString = (tempQty > 0)
						?"Item(s) Added to your cart" 
						:"Item Removed From your cart";
					$(this)
						.parents('*[class^=seriesWrapper]')
						.children('.updateFlashWrapper')
						.addClass('wrapperOpen');
				
					$('.updateFlashWrapper').not('.wrapperOpen').hide();
					$('.wrapperOpen').removeClass('wrapperOpen');
					$.getJSON("/index.cfm?fa=cart.actUpdateAjax&"+item+"="+val, function(json) {
						$('#cartCounter').html(json.count);
						$('*[name=sub'+tempName+']').css('display','').prev('img').css('display','none')
							.parents('*[class^=seriesWrapper]')
							.children('.updateFlashWrapper')
							.find('.updateFlashCount')
								.html(tempQty)
							.end()
							.find('.updateFlashString')
								.html(tempString)
							.end()
							.show().fadeTo("fast", 0.0).fadeTo("fast", 0.7).fadeTo("fast", 0.3).fadeTo("fast", 1)
					});
				});
			
		}

		