window.addEvent('domready', function() {

	toggleSize(true);
	calculateShipping();

	var items = $$("fieldset .hider");

	items.each(function(element) {
		var fx = new Fx.Styles(element, {duration:300, wait:false});
	 
		element.addEvent('mousedown', function(){
			fx.start({
				'height': '120px'
			});
		});
	 
	});

});

function toggleaddress2() { 
if (document.getElementById) { 
if (document.getElementById("diff-address").checked == true) { 
document.getElementById("address2").style.display = "block"; 
} else { 
document.getElementById("address2").style.display = "none";
document.orderform.shipping_addr_1.value = "";
document.orderform.shipping_addr_2.value = ""; 
} 
} 
}

function toggleCustomDescription() { 
if (document.getElementById) { 
if (document.getElementById("custom-description").checked == true) { 
document.getElementById("custom-description-field").style.display = "block"; 
} else { 
document.getElementById("custom-description-field").style.display = "none";
document.orderform.custom_description.value = "";
} 
} 
}

function toggleCustomTop() { 
if (document.getElementById) { 
if (document.getElementById("custom_top").checked == true) { 
document.getElementById("custom_top_field").style.display = "block"; 
} else { 
document.getElementById("custom_top_field").style.display = "none";
document.orderform.custom_top_line.value = "";
} 
}
calculateShipping();
}

function toggleCustomBottom() { 
if (document.getElementById) { 
if (document.getElementById("custom_bottom").checked == true) { 
document.getElementById("custom_bottom_field").style.display = "block"; 
} else { 
document.getElementById("custom_bottom_field").style.display = "none";
document.orderform.custom_bottom_line.value = "";
} 
} 
calculateShipping();
} 

function togglePaypal() { 
if (document.getElementById) { 
if (document.getElementById("paypal").checked == true) { 
document.getElementById("phone-button").style.display = "block"; 
} else { 
document.getElementById("phone-button").style.display = "none"; 
} 
} 
}

function togglePhone() { 
if (document.getElementById) { 
if (document.getElementById("phone").checked || document.getElementById("paypal").checked == true) { 
document.getElementById("payment").style.display = "block"; 
} else { 
document.getElementById("payment").style.display = "none"; 
} 
} 
}


function calculateShipping() {
	var quantity = document.orderform.quantity.value; 
	var rate = 0;
	
	if (quantity < 2) {rate = "10.00";}
	if (quantity == 2) {rate = "15.00";}
	if (quantity > 2) {rate = "20.00";}
	
	var shipping = document.orderform.shipping; 
	shipping.value = rate;
	calculateTotal();
}

function calculateTotal() {
	
	var customTop = 0;
	var customBottom = 0;
	var floridaTax = 1;
	
	if (document.getElementById("custom_top").checked == true) {customTop = 2.5;}
	if (document.getElementById("custom_bottom").checked == true) {customBottom = 2.5;}
	if (document.getElementById("florida_resident").checked == true) {floridaTax = 1.07;}
	
	var framesize = document.orderform.framesize.value; 
	var itemcost = 1;
	
	itemcost = "35";
	
	if (framesize == "7 x 24") {itemcost = "30";}
	if (framesize == "7 x 28") {itemcost = "40";}
	if (framesize == "11 x 24") {itemcost = "45";}
	if (framesize == "11 x 28") {itemcost = "50";}
	if (framesize == "16 x 20") {itemcost = "50";}

	var quantity = document.orderform.quantity.value; 
	var shipping = document.orderform.shipping.value;
	
	var subtotal = parseInt(itemcost) * parseInt(quantity) + customTop + customBottom;
	
	var sum = subtotal * floridaTax + parseInt(shipping);
	
	var sumround = Math.round(sum*100)/100;
	
	var total = document.orderform.total; 
	total.value = sumround;

	setHiddens();
}

function setHiddens() {
	document.getElementById('total_h').value = document.orderform.total.value;
	document.getElementById('shipping_h').value = document.orderform.shipping.value;
	document.getElementById('framesize_h').value = document.orderform.framesize.value;
}

function toggleSizeColor(state) {
	document.orderform.framesize.disabled = state;
	document.orderform.framecolor.disabled = state;
}

function toggleSize(state) {
	document.orderform.framesize.disabled = state;
}

mattearr=new Array()
mattearr[1]="7 x 24"
mattearr[2]="11 x 24"
mattearr[3]="11 x 24"
mattearr[4]="11 x 24"
mattearr[5]="7 x 24"
mattearr[6]="11 x 24"
mattearr[7]="7 x 24"
mattearr[8]="11 x 24"
mattearr[9]="11 x 24"
mattearr[10]="11 x 24"
mattearr[11]="11 x 24"
mattearr[12]="7 x 24"
mattearr[13]="7 x 24"
mattearr[14]="11 x 24"
mattearr[15]="7 x 28"
mattearr[16]="11 x 28"
mattearr[17]="11 x 24"
mattearr[18]="7 x 24"
mattearr[19]="11 x 24"
mattearr[20]="7 x 24"
mattearr[21]="7 x 24"
mattearr[22]="7 x 24"
mattearr[23]="7 x 24"
mattearr[24]="11 x 24"

mattearr[25]="11 x 24"
mattearr[26]="11 x 24"
mattearr[27]="11 x 24"
mattearr[28]="11 x 24"
mattearr[29]="11 x 24"

mattearr[30]="11 x 24"
mattearr[31]="11 x 24"
mattearr[32]="11 x 24"
mattearr[33]="11 x 24"

mattearr[34]="11 x 24"
mattearr[35]="11 x 24"
mattearr[36]="11 x 24"
mattearr[37]="11 x 24"

mattearr[38]="7 x 28"
mattearr[39]="11 x 28"
mattearr[40]="7 x 24"
mattearr[41]="7 x 24"
mattearr[42]="7 x 24"
mattearr[43]="7 x 24"
mattearr[44]="7 x 24"
mattearr[45]="7 x 24"
mattearr[46]="7 x 24"
mattearr[47]="7 x 24"
mattearr[48]="11 x 24"
mattearr[49]="7 x 24"
mattearr[50]="7 x 24"
mattearr[51]="7 x 24"
mattearr[52]="7 x 24"

mattearr[53]="7 x 28"
mattearr[54]="7 x 24"
mattearr[55]="7 x 28"
mattearr[56]="7 x 24"

mattearr[57]="7 x 24"
mattearr[58]="7 x 28"
mattearr[59]="11 x 24"
mattearr[60]="7 x 24"
mattearr[61]="7 x 24"
mattearr[62]="7 x 24"
mattearr[63]="7 x 24"
mattearr[64]="7 x 24"
mattearr[65]="7 x 24";

function matteSwitch() {
	var objval;
	objval = document.orderform.premade_matte.options[document.orderform.premade_matte.selectedIndex].value;
	document.getElementById('framesize').value=mattearr[objval];
	
	calculateShipping();
}

function paypal() {
	document.orderform.action='https://www.paypal.com/cgi-bin/webscr';
	document.orderform.submit();
}
