///////////////////////////////////////////////////////////////////////////////////////////////////

//Google Analytics tracking
function trackPage() {
	try {
		//add the account number
		var pageTracker = _gat._getTracker("UA-9359014-1");
		pageTracker._trackPageview();
	} catch(err) {}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function checkClick() {
	//if the checkbox is checked
	if ($(this).is(":checked")) {
		//get the number at the end of the parent element's id
		var imageNum = $(this).parent().parent().attr("id").substr(5,1);
		//get the form data from the matching div 
		var formData = $("#container"+imageNum).html();
		//add the form data to the form
		$(this).parent().parent().find(".file-upload").html(formData);
	} else {
		$(this).parent().parent().find(".file-upload").empty();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

function loadEmpty() {
	if ($(this).find("p.image-label").html() == null) {
		//get the number at the end of the element's id
		var imageNum = $(this).attr("id").substr(5,1);
		//get the form data from the matching div 
		var formData = $("#container"+imageNum).html();
		//add the file upload div to the empty div
		$(this).html("<p class='image-label'><strong>Image #"+imageNum+"</strong></p><div class='file-upload'></div>");
		//add the form data to the form
		$(this).find(".file-upload").html(formData);
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function() {
	//track the page with Google Analytics
	trackPage();
	
	//only run if it's an account page
	if ( $("#account-page").length > 0 ) {
		//show / hide the photo upload if the box is checked
		$(".delete:checkbox").click(checkClick);
		//show the photo upload box for slots with no photos	
		$(".image-container").each(loadEmpty);
	}
	
	if ( $("#home-page").length > 0 ) {
		$("#why").tabs({ selected: 0});
	}
		
});

///////////////////////////////////////////////////////////////////////////////////////////////////