/***
	@author:		Thomas Evan Lecklider
	@client:		American Martyrs
	@date:			24 March 2009
	
	Dependencies:
		* jQuery library http://jquery.com
		* jQuery Cycle plugin
		* jQuery Tooltip plugin
	Notes:
		* None as of yet
***/

$(document).ready(function(){
	// Directory styling
	$("table.directory tr:odd").addClass("odd");
	$("table.directory tr tr.odd").removeClass("odd");
	
	//// Image slideshow
	if ($("#main_img").children("#slideshow").length > 0) { // Validates need for slideshow
		var speedo;
		
		if ($.browser.msie && ($.browser.version == 6)) { speedo = 0 } else { speedo = 2500 }
		
		$("#main_img #slideshow").cycle({ // Actual slideshow function with options
			fx:			"fade",
			speed:		speedo,
			timeout:	7000
		});
	}
	
	//// Tooltips for the left navigation
	if ($("#sidebar").children("#leftnav").length > 0) {
		$("#sidebar #leftnav li a").tooltip({
			track:		true,
			delay:		0,
			showURL:	false,
			fade:		250
		});
	}
	
	var leftnav = $("#leftnav");
	$("li ul", leftnav).hide().each(function(){
		$(this).parent("li").children("a").click(function(event){
			event.preventDefault();
			$(this).parent("li").children("ul").slideToggle("fast");
		});
	});
	
	if ($("#main_text").children("#right_column").length > 0) {
		$("#center_column").css({ width: 487 });
		if ($.browser.msie && ($.browser.version == 6)) {
			$("#center_column").css({ width: 475 });
		}
	}
	
	// So we can display a word for the weekday
	var weekday = new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";

	// So we can display a word for the month	
	var monthname = new Array(12);
	monthname[0] = "January";
	monthname[1] = "February";
	monthname[2] = "March";
	monthname[3] = "April";
	monthname[4] = "May";
	monthname[5] = "June";
	monthname[6] = "July";
	monthname[7] = "August";
	monthname[8] = "September";
	monthname[9] = "October";
	monthname[10] = "November";
	monthname[11] = "December";
	
	var today = new Date();
	var day = today.getDay();
	var date = today.getDate();
	var month = today.getMonth();
	var year = today.getFullYear();
	// Display
	$("#date").html(weekday[day] + ", " + monthname[month] + " " + date + ", " + year);
	
	//// Main navigation current page setting
	// Check the URL for the current link
	var path = window.location.href;
	var caught_a_link = false;
	var href = $("#mainnav ul li a").each(function() {
		var href = $(this).attr("href");
		if(path.match(href) == href) {
			$(this).addClass("current");
			caught_a_link = true;
		}
	});
	
	// If nothing was caught we are going to check to see if it's the home page
	if (caught_a_link == true) { /* do nothing */ }
	else if (path.match("/") && (path.lastIndexOf("/") == 0)) {
		$("#mainnav ul li a:first").addClass("current");
	} else { /* do nothing */ }
	
	// FAQ style dropdowns
	$("dl.dropdown").each(function(){
		var dt = $("dt", this);
		var dd = $("dd", this);
		dd.hide();
		dt.css({ cursor: "pointer" }).click(function(){
			$(this).next("dd").slideToggle("fast");
		});
	});
});
