﻿var item = "";

$(document).ready(init);

function init() {
	$("#top_nav #home_tab").click(function(){window.location="index.php";});
	$("#top_nav #info_tab").click(function(){window.location="info.php";});
	$("#top_nav #login_tab").click(function(){window.location="account.php";});
	$("#top_nav #shop_tab").click(function(){window.location="http://www.gothamcigars.com";});
	$(".logo").click(function(){window.location="http://www.gothamcigars.com";});
	
	$(".bottom_nav li").hover(
		function(){$(this).animate({backgroundPosition: '0px 20px'}, 200);},
		function(){$(this).animate({backgroundPosition: '0px 30px'}, 300);}		
	);
	$("#register_here").hover(
		function(){$(this).animate({top: '-13px'}, 200);},
		function(){$(this).animate({top: '-15px'}, 300);}		
	);	
	
	$(".bottom_nav li").click(showProduct);
	
	$("#home_register_content #submit_btn").click(validate);
	
	startRandom();

}

function showProduct() {
	$("#all_prizes_div").hide();
	$(item).hide();	
	item = "#" + this.id + "_div";
	$(item).fadeIn();
}


function tab_hover(el) {
	
	alert(el.id);
}

function startRandom() {
	
	for(var i = 0; i < 2; i++) {		
		$(".bottom_nav li#grand_prize").animate({backgroundPosition: '0px 20px'}, 400);
		$(".bottom_nav li#grand_prize").animate({backgroundPosition: '0px 30px'}, 200);
		$(".bottom_nav li#second_prize").animate({backgroundPosition: '0px 20px'}, 200);
		$(".bottom_nav li#second_prize").animate({backgroundPosition: '0px 30px'}, 400);
		$(".bottom_nav li#first_prize").animate({backgroundPosition: '0px 20px'}, 300);
		$(".bottom_nav li#first_prize").animate({backgroundPosition: '0px 30px'}, 300);	
	}
	
}

function validate() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if($("#home_register_content #firstname").val()=='')
		alert('First name is required');
	else if($("#home_register_content #lastname").val()=='')
		alert('Last name is required');
	else if($("#home_register_content #address").val()=='')
		alert('Address is required');
	else if($("#home_register_content #city").val()=='')
		alert('City is required');
	else if($("#home_register_content #state").val()=='')
		alert('State is required');
	else if($("#home_register_content #zip").val()=='')
		alert('ZIP is required');
	else if($("#home_register_content #email").val()=='')
		alert('Email is required');
	else if(!reg.test($("#home_register_content #email").val()))
		alert('Email is invalid');
	else if($("#home_register_content #password").val()=='')
		alert('Password is required');
	else if($("#home_register_content #password").val()!=$("#home_register_content #password2").val())
		alert('Passwords do not match');
	else if(!$("#home_register_content #agree")[0].checked)
		alert('You must agree to the Gotham Cigars Summer Sweepstakes rules');
	else {
		$("#home_register_content #submit_btn").hide();
	}
}









