/*
 * jQuery doTimeout: Like setTimeout, but better! - v0.4 - 7/15/2009
 * http://benalman.com/projects/jquery-dotimeout-plugin/
 * 
 * Copyright (c) 2009 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a={},c="doTimeout",d=Array.prototype.slice;$[c]=function(){return b.apply(window,[0].concat(d.call(arguments)))};$.fn[c]=function(){var e=d.call(arguments),f=b.apply(this,[c+e[0]].concat(e));return typeof e[0]==="number"||typeof e[1]==="number"?this:f};function b(l){var m=this,h,k={},n=arguments,i=4,g=n[1],j=n[2],o=n[3];if(typeof g!=="string"){i--;g=l=0;j=n[1];o=n[2]}if(l){h=m.eq(0);h.data(l,k=h.data(l)||{})}else{if(g){k=a[g]||(a[g]={})}}k.id&&clearTimeout(k.id);delete k.id;function f(){if(l){h.removeData(l)}else{if(g){delete a[g]}}}function e(){k.id=setTimeout(function(){k.fn()},j)}if(o){k.fn=function(p){o.apply(m,d.call(n,i))&&!p?e():f()};e()}else{if(k.fn){j===undefined?f():k.fn(j===false);return true}else{f()}}}})(jQuery);

function processSlideshow(elem,imageList,imageDuration,fadeSpeed,current){var listSize=imageList.length;if(!current||current>=listSize)current=0;if(!imageDuration)imageDuration=2000;if(!fadeSpeed)fadeSpeed=1000;$(elem+" img").attr("src",imageList[current]);if(current==(listSize-1)){$(elem).css("background","transparent url("+imageList[0]+") no-repeat")}else{$(elem).css("background","transparent url("+imageList[current+1]+") no-repeat")}$(elem+" img").animate({opacity:"1"},imageDuration).animate({opacity:"0.01"},fadeSpeed,function(){$(this).css("opacity","1");processSlideshow(elem,imageList,imageDuration,fadeSpeed,current+1)})}

$(document).ready(function(){


 	
/*Keep divs at equal heights */ 
	function equalizeHeight(theseDivs){
		var maxHeight = 0;

		$(theseDivs).each(function(){
		   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
		});

		$(theseDivs).height(maxHeight);
	}
	
	equalizeHeight('.thirds');
	equalizeHeight('#home .boxes div');
	equalizeHeight('.halves');
	

/* Show Table Sponsor Form */

	$('#tablesponsor form').hide();
	$('.yes_sponsor').html('<a href="#" class="button">Yes, I Would Like To Sponsor</a>').toggle(function(){
		$('#tablesponsor form').slideDown();
	},function(){
		$('#tablesponsor form').slideUp();
	});
	
/* Show Ticket Total */

function callAjax(){
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "/register/ajax_tickets",	
			
			//GET method is used
			type: "POST",

			//pass the data			
			data: ({
				qty: $('input[name=Tickets]').val(),
				}),
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				
				$('#drawing_tickets .ajax_total').html('$'+html);
			}
		});
	}
	
	$('input[name=Tickets]').keyup(callAjax);


/* BETA */	
/* ON REGISTRATION FORM: Click to use same address as last registrant */

	$('#register2 input#Last').after('<div><a href="#" id="load_addr">Click Here To Use The Same Address</a></div>');
	$('#register2 input[name=Address],#register2 input[name=State],#register2 input[name=Zip],#register2 input[name=City]').val('');
	
	$('#load_addr').click(function(){
	
		$('#load_addr').parent().html('LOADING . . . <img src="/icons/loading.gif" class="loading" />');
	
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "/register/load_address/",	
			type: "POST",
			data: ({
				qty: $('input[name=Tickets]').val(),
				}),
			cache: false,
			dataType: "json",
			
			//success
			success: function (data) {				
				
				$('#Address').val(data.Address);
				$('#City').val(data.City);
				$('#State').val(data.State);
				$('#Zip').val(data.Zip);
				$('img.loading').parent().remove();
			}
		});
		
		return false;
	});
	
/* End Beta */

	$('.show_load').click(function(e){
		$('body').append('<p id="loading">Loading... </p>');
		$("#loading").css({
		    top: (e.pageY + 15) + "px",
		    left: (e.pageX + 15) + "px"
		});
		$(document).mousemove(function(e){
		$("#loading").css({
		    top: (e.pageY + 15) + "px",
		    left: (e.pageX + 15) + "px"
		});
	    });
	});
	
});
