(function($){

	// this obj is init'd within a doc ready statement
	window.Store = {
		init: function(){
			this.$form = $("#store-product-form form");
			this.$price = this.$form.find("#store-product-price span");
			this.$submit = this.$form.find("input:submit");

			// find the price on the inital page load
			this._calculate();
	
			// and again when a select is changed
			$("#store-product-form select").change(function(){
				Store._calculate();
			});
		},
		
		_calculate: function(){
			var self = this;
			
			this.$price.html('Updating Price...');
		
			$.post('/includes/calculateprice.cfm', self.$form.serialize(), function(price){
				price = $.trim(price);
				var isValidPrice = /\d/.test(price);
			
				self.$price.html( isValidPrice ? price : 'Unknown Price');
			
				// toggle submit state
				self.$submit.attr('disabled', isValidPrice ? '' : 'disabled');
			});
		}
	}

	// other JS in here
	$(function(){
	
		// color box
		$(".slideshow-images a, #store-product-images a").colorbox({
			speed:0,
			transition:'none',
			maxWidth: 800,
			maxHeight:600
		});
		
		$("#check-lead-time").click(function(){
			var href = this.href;
			
			$("<div></div>")
			.appendTo("body")
			.dialog({ title: "Check Lead Time", width:500, height:300, modal:true, buttons:{
				"Close": function(){
					$(this).dialog("close");
				}
			}})
			.load(href, { ajax:true });
			
			return false;
		});
		
	});

})(jQuery);

