/**
 * @author dylan
 */

var shirtPriceShort = "20.00";
var shirtPriceLong = "30.00";
var shirtPriceBaby = "20.00";
var shirtPriceTank = "22.00";
var menuId;

function myOnload() {
	styleMenu();
	if (document.getElementById('slideshow')) {
		startSlideshow();
	}
	//captionImage('frontpageText','slideshow');
	$("a[rel^=lightbox]").lightbox();
}

function startSlideshow(){
	if (document.getElementById('slideshow')) {
		$('#slideshow').cycle({
	        fx: 'fade',
	        pause: 1,
	        timeout: 5000,
	        speed: 1200
	    });
	}
}

function captionImage(textEl,imgEl) {
	imgOffset = $("#"+imgEl).offset();
	$("#"+textEl).css("display","none");
	$("#"+textEl).css("position","absolute");
	$("#"+textEl).css("top",imgOffset.top+"px");
	$("#"+textEl).css("left",imgOffset.left+"px");
	$("#"+textEl).attr("class","captionedText");
	$("#"+textEl).css("width",$("#"+imgEl).width()-14+"px");
	
	myClose = $("<a href='#' class='captionedClose'>close</a>");
	$(myClose).click(function(){
		$("#"+textEl).hide("slide",{direction:"up"},300);
		setTimeout(function(){
			$("#"+textEl).remove();
		},300);
	});
	$(myClose).appendTo("#"+textEl);
	
	setTimeout(function(){
		$("#"+textEl).show("slide",{direction:"up"},1000);
	},2000);
	
	$("#"+imgEl).hover(function(){
		$("#"+textEl).hide("slide",{direction:"up"},600);
	},
	function(){
		$("#"+textEl).show("slide",{direction:"up"},600);
	});
}

function styleMenu() {
	myLi = $("#"+menuId).parent();
	$("#"+menuId).remove();
	$(myLi).attr("id",menuId+"Active");
}

function viewCart() {
	
}

function addToCart(productId) {
	var myForm = eval('document.form_'+productId);
	var productType = myForm.productType.value;
	if (productType=="shirt") {
		var description = myForm.name.value+" - "+myForm.size.value+" "+myForm.color.value+" "+myForm.style.value;
	} else if (productType=="cap") {
		var description = myForm.name.value;
	}
	var amount = myForm.amount.value;
	var quantity = myForm.quantity.value;
	var sendForm = document.sendForm;
	sendForm.item_name.value = description;
	sendForm.quantity.value = quantity;
	sendForm.amount.value = amount;
	sendForm.item_number.value = productId;
	sendForm.submit();
}

function styleChange(productId) {
	var myForm = eval('document.form_'+productId);
	var style=myForm.style.value;
	var priceEl = myForm.productPrice;
	var priceFormEl = myForm.amount;
	if (style=="short sleeve t-shirt") {
		shirtPrice = shirtPriceShort;
	} else if (style=="long sleeve t-shirt") {
		shirtPrice = shirtPriceLong;
	} else if (style=="baby rib tank") {
		shirtPrice = shirtPriceBaby;
	} else if (style=="unisex tank") {
		shirtPrice = shirtPriceTank;
	}
	priceEl.value = "$"+shirtPrice;
	priceFormEl.value=shirtPrice;
}