var cartValidator = {
	
	init: function() {
		if($('#userInfo').length > 0) {	
			this.initEvents();
		}		
	},
	initEvents: function() {
		$('#userInfo').submit(function() {
			var valid = true;
			$('#userInfo .jsReq').each(function() {
				var el = $(this);
				if(el.val().length < 1) {
					valid = false;
				}
			});			
			if(valid == false) {
				alert('Please complete all fields with the asterisk next to the title in order to process your order.');
				return false
			}
		});
   		return true;
	}
}

var storeGallery = {

	init: function() {
		if($('#stateSelector').length > 0) {	
			this.initEvents();
		}
	},
	initEvents: function() {
		$('#stateSelector').bind("change", function(e){
			storeGallery.updateImages();
		});
	},
	updateImages: function() {
		var val = $('#stateSelector').val();
		if(val == 'all') {
			$('#storesTable td').each(function(){
				$(this).fadeTo("normal", 1)
			});
		} else {
			$('#storesTable td:not(.' + val + ')').each(function(){
				$(this).fadeTo("normal", 0.2)
			});
			$('td.' + val ).each(function(){
				$(this).fadeTo("normal", 1)
			});			
		}

	}
	
}


$(document).ready(function(){	
	storeGallery.init();
	cartValidator.init();
});
