// JavaScript Document

function removeCartItem(id) {
	if(id) {
		$('#cartItem').val(id);
		$('#cartAction').val('REMOVE');
		$('#cartBtn').click();
	}
}

function updateCartItem(id) {
	if(id) {
		$('#cartItem').val(id);
		$('#cartAction').val('UPDATE');
		$('#cartBtn').click();
	}
}

$(document).ready(function() {													 
	
	var v0 = $("#address_form").validate();
	var v1 = $("#credit_form").validate();
	
	$(".dealThumb").click(function() {
		$(".dealMain").hide();
		parts = $(this).attr('id').split("_");
		id = parts[1];
		$("#main_"+id).fadeIn("fast");
	});
	
	$(".dealThumb").mouseover(function() {
		$(".dealMain").hide();
		parts = $(this).attr('id').split("_");
		id = parts[1];
		$("#main_"+id).fadeIn("fast");
	});
	
	$(".optionThumb").mouseover(function() {
		$(".dealMain").hide();
		parts = $(this).attr('id').split("_");
		id = parts[1];
		$("#main_thumb_"+id).fadeIn("fast");
	});
	
	$("#option_value").change(function() {
		$("#option_name").val($('#option_value :selected').text());															 
	});
	
	/** Set height of main image so that it's set to the height
	of the largest image **/
	var height = 0;
	$("#bigImages img").each(function() {
		if($(this).height()>height)
			height = $(this).height();
	});
	
	if(height>0)
		$("#bigImages").height(height);
	
	$('#privacy_policy').click(function() {
			var dialogOpts = {
				modal: true,
				bgiframe: true,
				autoOpen: false,
				height: 400,
				width: 700,
				draggable: true,
				resizeable: true,
				open: function() {
					$("#privacy_policy_container").load("privacy2.php");
				}
			};
			
			$("#privacy_policy_container").dialog(dialogOpts);	
			$("#privacy_policy_container").dialog("open");
			return false;
	});
	
	$('#return_policy').click(function() {
			var dialogOpts = {
				modal: true,
				bgiframe: true,
				autoOpen: false,
				height: 500,
				width: 700,
				draggable: true,
				resizeable: true,
				open: function() {
					$("#return_policy_container").load("returns.php");
				}
			};
			
			$("#return_policy_container").dialog(dialogOpts);	
			$("#return_policy_container").dialog("open");
			return false;
	});
	
	$('#signinBtn').click(function() {
		
		$("#signinFormContainer").dialog({
			bgiframe: true,
			height: 300,
			modal: true,
			buttons: { "Cancel": function() { $(this).dialog("close"); }, "Signin": function() { $("#signinForm").submit(); }  }
		});
															 
	});
});

function toggleBilling(condition) {
if(condition)
	$('#billingInfo').hide();
else
	$('#billingInfo').show();
}

