$(document).ready(function(){
	if(document.getElementById('statsRotator') != null) {
		rotateStats();
	}

  // Increase Font Size
  $("#enlargeText").click(function(){
    var currentFontSize = $('#centerColumn').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
	if(currentFontSizeNum < 16.8) {
		var newFontSize = currentFontSizeNum+2;
		$('#centerColumn #secondLevelNav').css('font-size', 13);
		$('#centerColumn').css('font-size', newFontSize);
		return false;
	}
  });
  // Decrease Font Size
  $("#decreaseText").click(function(){
    var currentFontSize = $('#centerColumn').css('font-size');
	var currentFontSizeNum = parseFloat(currentFontSize, 10);
	if(currentFontSizeNum > 11) {
		var newFontSize = currentFontSizeNum-2;
		$('#centerColumn #secondLevelNav').css('font-size', 13)
		$('#centerColumn').css('font-size', newFontSize);
		return false;
	}
  });
  
  $("#search-text").click(function() {
	if(this.value == "Search") {
		this.value = "";
	}
  });
  $("#search-text").blur(function() {
	if(this.value == "") {
		this.value = "Search";
	}
  });
  
	$("#search").submit(function() {
		if(document.search.searchTxt.value == "Search" || document.search.searchTxt.value == "") {
			alert("Please enter a valid search term.");
			return false;
		}
	});

  $("#ParamKeyword").click(function() {
	if(this.value == "search with keywords") {
		this.value = "";
	}
  });
  $("#ParamKeyword").blur(function() {
	if(this.value == "") {
		this.value = "search with keywords";
	}
  });

  
  //displays content on the homepage
  $(".homeTabs #secondLevelNav a").click(function() {
		var clickedTab = this;
		var clickedTabLink = this.href;
		var tabToShow = clickedTabLink.split("#").pop();
		$(".homeTabs #secondLevelNav a").each(function () {
			if(this != clickedTab) {
				$(this).removeClass('active');
			}
			else {
				$(this).addClass('active');
			}
	  	});
		$(".homeContent div").each(function () {
			if(this.id == tabToShow) {
				$(this).show();
			}
			else {
				$(this).hide();
			}
	  	});
  });
  
  
  //Donation forms - displays extra fields based on selection
  $("input.honoreeTypeRadio").click(function() {
	var clicked = this.value;
	if (clicked != 'neither') {
		$("#honorInfo").show();
		if(clicked == "inHonorOf") {
			$("#nameOf").html('honoree');
			$("#addressOf").html("honoree's");
		}
		else if(clicked == "inMemoryOf") {
			$("#nameOf").html('decedent');
			$("#addressOf").html("decedent's");
		}
	}
	else {
		$("#honorInfo").hide();
	}
  });
 
  $("input.fromCorporationRadio").click(function() {
	var clicked = this.value;
	if (clicked == 'true') {
		$("#companyInfo").show();
	}
	else {
		$("#companyInfo").hide();
		$("#companyName").html("");
	}
  });
  
  $("input.matchingEmployerRadio").click(function() {
		var clicked = this.value;
		if (clicked == 'true') {
			$("#matchingEmployerInfo").show();
		}
		else {
			$("#matchingEmployerInfo").hide();
			$("#matchingEmployerName").html("");
			$("#matchingEmployerPhone").html("");
			$("#matchingEmployerMail").html("");
		}
  });
  
  $("#donationOpportunitySelect").change(function() {
		var selected = this.value;
		if (selected == 'designatedGift') {
			$("#designatedGiftInfo").show();
		}
		else {
			$("#designatedGiftInfo").hide();
		}
  });
  
  //Displays/Shrinks event detail
  $(".expandEvent").click(function() {
	var clickedEvent = this.className.split(" ").pop();
	$(".shortEvent").each(function () {	
		var shortId = this.className.split(" ").pop();
		if(shortId == clickedEvent) {
			$(this).hide();
		}
	  });
	$(".fullEvent").each(function () {	
		var fullId = this.className.split(" ").pop();
		if(fullId == clickedEvent) {
			$(this).show();
		}
	  });
  });
  $(".shrinkEvent").click(function() {
	var clickedEvent = this.className.split(" ").pop();
	$(".fullEvent").each(function () {	
		var fullId = this.className.split(" ").pop();
		if(fullId == clickedEvent) {
			$(this).hide();
		}
	  });
	$(".shortEvent").each(function () {	
		var shortId = this.className.split(" ").pop();
		if(shortId == clickedEvent) {
			$(this).show();
		}
	  });
  });
  
	$('.displayJob').click(function(){
		var jobID = this.className.split(" ").pop();
		doAjax($(this).attr('href'), jobID);
		return false;
	});
	function doAjax(url, jobID){
		$('#jobDetail' + jobID).load(url + ' .jobDetail', function(response, status, xhr) {
			if (status == "error") {
				alert("Sorry but there was an error processing this request: " + xhr.statusText);
			}
		});
	}
	var sloganWidth = $('.pageSlogan').width();
	
	if(sloganWidth > 240) {
		$('.pageSlogan').addClass('wideSlogan');
	}
	
});


function showApplication(applicationID) {
	$("#" + applicationID).show();
}


var statCounter = 0;
	
function rotateStats() {
	statCounter++;
	var statObj = document.getElementById('statsRotator');
	statItems = statObj.getElementsByTagName('div');
	totalStas = statItems.length;
	if(statCounter > totalStas) {
		statCounter = 1;
	}
	$("#stat-" + statCounter).fadeIn(1000);
	setTimeout('fadeStat(statCounter);', 5000);
}
	
function fadeStat(statCounter) {
	$("#stat-" + statCounter).fadeOut(1000, rotateStats);
}

function showOverlay() {
	var docHeight = $(document).height() - 14;
	var docWidth = $(document).width() -14;
	$('#homeOverlay').css({'height': docHeight, 'width': docWidth, 'display': 'block'});
}

function hideOverlay() {
	$('#homeOverlay').hide();
	$('#home #wrapper').show();
}
