$(document).ready(function(){
	//set up the main banner tabs
	$('#panel_tabs a').click(function(event){
		div = $(this).parent();
		$('#panel_tabs li').removeClass('selected');
		div.addClass('selected');
		matches = div.attr('id').match(/tab_(\d+)/);
		if (matches) {
			id = matches[1] - 1;
			$('#panels').animate({left: (id * -898) + 'px'}, 500); 
		}
		event.preventDefault();
	});

	//set up the next button in the main banner
/*
	$('a.next_btn').mouseover(function(event){
		$(this).css('background-position', '0px -34px');
	});
	$('a.next_btn').mouseout(function(){
		$(this).css('background-position', '0px 0px');
	});
	$('a.next_btn').mousedown(function(){
		$(this).css('background-position', '0px -68px');
	});
	$('a.next_btn').mouseup(function(){
		$(this).css('background-position', '0px 0px');
	});
*/
	$('a.next_btn').click(function(event){
		matches = $(this).parent().attr('id').match(/panel_(\d+)/);
		if (matches) {
			next_id = parseInt(matches[1]) + 1;
			$('#panel_tabs li').removeClass('selected');
			$('#tab_'+ next_id).addClass('selected');
			$('#panels').animate({left: ((next_id - 1) * -898) + 'px'}, 500); 
		}
		event.preventDefault();
	});

	$('a.xbig_button').mouseover(function(event){
		$(this).css('background-position', '0px -46px');
	});
	$('a.xbig_button').mouseout(function(){
		$(this).css('background-position', '0px 0px');
	});
	$('a.xbig_button').mousedown(function(){
		$(this).css('background-position', '0px -92px');
	});
	$('a.huge_button').mouseover(function(event){
		$(this).css('background-position', '0px -56px');
	});
	$('a.huge_button').mouseout(function(){
		$(this).css('background-position', '0px 0px');
	});
	$('a.huge_button').mousedown(function(){
		$(this).css('background-position', '0px -112px');
	});
	$('a.button').mouseover(function(event){
		$(this).css('background-position', '0px -34px');
	});
	$('a.button').mouseout(function(){
		$(this).css('background-position', '0px 0px');
	});
	$('a.button').mousedown(function(){
		$(this).css('background-position', '0px -68px');
	});
	$('a.button').mouseup(function(){
		$(this).css('background-position', '0px 0px');
	});

	$('#sign_up_form a.submit').click(function(event){
		event.preventDefault();
		first_name_valid = email_valid = false;

		first_name = $('input[name=first_name]');
		if (first_name.val() == '')
		{
			first_name.addClass('error');
		}
		else
		{
			first_name_valid = true;
			first_name.removeClass('error');
		}

		email = $('input[name=email]');
		if (email.val() == '')
		{
			email.addClass('error');
		}
		else
		{
			email_valid = true;
			email.removeClass('error');
		}

		if (first_name_valid && email_valid) {
			form = $(this).closest('form');
			form.submit();
		}

		if (!first_name_valid && !email_valid) alert('Please enter your FIRST NAME and EMAIL');
		else if (!first_name_valid) alert('Please enter your FIRST NAME below');
		else if (!email_valid) alert('Please enter your EMAIL ADDRESS below');
	});

	$('input.init').focus(function(event){
		input = $(this);
		if (input.hasClass('init'))
		{
			input.val('');
			input.removeClass('init');
		}
	});

	$('input.init').keyup(function(event){
		if (event.which == 13)
		{
			form = $(this).closest('form');
			form_elem = form.get(0);	
			if (typeof form_elem.onsubmit == "function")
			{
				form_elem.onsubmit();
			}
			form.submit();
		}
	});

/*
	$('a.start_trial').click(function(event){
		$(this).closest('form').submit();	
		event.preventDefault();
	});
*/

	$('form.auto_submit').each(function(){
		$(this).submit();
	});

 });
