//Jquery Code

var $j = jQuery.noConflict();

$j(document).ready(function () {
	
	// Hide form boxes, except for defaulted open one when page loads
	
	//$j("div.items_form_row h3 a").addClass("closed");
	//$j("div.items_form_row div.item_form_box").hide();
	$j("div#default_items_form_row div.item_form_box").show(300);
	$j("div#default_items_form_row h3 a").removeClass("closed");
	// Hide Image on home page for people with JavaScript
	$j(".home_main_image").hide();
	
	
	// Group Items List Row QTY Fill for Click on Emptpy
	
	$j("dd.purchase button").click(function (event) {
		event.preventDefault();
		var $dd = $j(this).parent();
		var $input = $dd.children("input");
		if(!$input.val().length > 0){
			$input.val("1");
			$j(this).parents("form").submit();
		}
		else
		{
			$j(this).parents("form").submit();
		}
	});
	
	
	// Mixed Group List QTY Fill for Click on Emptpy
	
	$j("div.list_button button").click(function (event) {
		event.preventDefault();
		var $sharedParent = $j(this).parent().parent();
		var $input = $sharedParent.children("div").children("input");
		if(!$input.val()){
			$input.val("1");
			$j(this).parents("form").submit();
		}
		else
		{
			$j(this).parents("form").submit();
		}
	});
	
	
	// Show/Hide Item Form Boxes when link is clicked
	
	$j("div.items_form_row h3 a").click(function (event) {
		event.preventDefault();
		var $toggleBox = $j(this).parent().parent().children(".item_form_box");
		if($j(this).hasClass("closed")){
			$toggleBox.show(300);
			$j(this).removeClass("closed");
		}else{
			$toggleBox.hide(300);
			$j(this).addClass("closed");
		}
	});
	
	
	// Input Values - Item Form
	
	/* Removed per customer request
	
	$j("dd.purchase input").click(function (event) {
		event.preventDefault();
		if(!$j(this).val()){
			$j(this).val("1");
		}
		$j(this).select();
	});
	*/
	
	
	// Validator function Group Form Before Submitting
	
	$j("form.validate_me").submit(function (event) {
		
		correct = 0;
		
		$j("input").each(function()
		{
			if($j(this).val().length > 0 && $j(this).attr('type') != 'hidden')
			{
				correct ++;
			}
		});
		
		if(correct == 0)
		{
			event.preventDefault();
			alert("Please type a quantity next the item/items you'd like to purchase.")
		}
	});
	
	
	// Validate Items Form Before Allowing Submit
	// Removed - doesn't work that well
/*
	$j("form.items_form button").click(function (event) {
		if(!$j("dd.purchase input").val()) {
			event.preventDefault();
			alert("Please type a quantity next the the item/items you'd like to purchase.")
		}
	})
*/
	
	
	// Lightbox Function
	
	$j(function() {
		$j('a.lightbox').lightBox({fixedNavigation:true}); // Select all links with lightbox class
	});

	
	
});