// by spencer
$(document).ready(function(){
		// hide txt fields
		$("#recognizing").hide();
		$("#tax").hide();
		// build buttons
		$("#donationTypeButton").click(function(){
			$("#donationType").show("slow");
			$("#recognizing").hide();
			$("#tax").hide();
			return false;
		});
		$("#recognizingButton").click(function(){
			$("#donationType").hide();
			$("#recognizing").show("slow");
			$("#tax").hide();
			return false;
		});
		$("#taxButton").click(function(){
			$("#donationType").hide();
			$("#recognizing").hide();
			$("#tax").show("slow");
			return false;
		});
		// hide sponsor button, create fade in + out for sponsor button
		$(".contribute").hide();
		$(".item").hover(
		function() {
			$(this).find("li.contribute").show("slow");
		},
		function(){
			$(this).find("li.contribute").hide();
		});
		// cutesy page transition
		$("a.nav").click(function(){
			$("#container").animate({
				opacity: 0,
				bottom: '+=700'
			  }, 300);
			var hr = this.href;
			setTimeout('window.location = "'+hr+'"' ,420);
			return false;
		});

	$(function(){
		
		$("#dialog-form").dialog({
			autoOpen: false,
			height: 350,
			width: 560,
			modal: true
		});	
		// contribute dialogue text 
		// updates Google Checkout form elements
		$('li.contribute').click(function() {
			$('#dialogTxt').empty();
			var dialogueTxt = "<strong>sponsor<strong/> " + $(this).parents(".item").children("h2").text();
			$('#dialogTxt').prepend(dialogueTxt + ":  <strong class='cost'>$"+ $(this).parents(".itemBar").children(".cost").text() + "<strong/>");
			$('#dialog-form').dialog('open');
			$('[name=item_name_1]').val($(this).parents(".item").children("h2").text());
			$('[name=item_price_1]').val($(this).parents(".itemBar").children(".cost").text().replace(/[^\d.]/g, ""));
			$('[name=item_price_1]').keyup(function () {
				$('#dialogTxt').empty();
				var value = $(this).val().replace(/[^\d.]/g, "");
				$('[name=item_price_1]').val(value);		
				$("#dialogTxt").prepend(dialogueTxt + ":  <strong class='cost'>$" + value + "<strong/>");
			}).keyup();
		});
		// general contribution dialogue text
		$("#btn_sponsor").click(function() {
			$('#dialog-form').dialog('open');
			$('[name=item_price_1]').keyup(function () {
				$('#dialogTxt').empty();
				var value = $(this).val().replace(/[^\d.]/g, "");
				$('[name=item_price_1]').val(value);		
				$("#dialogTxt").prepend('General Contribution: $'+value);
			}).keyup();
		});
	});
});

