// jquery ready event
$(document).ready(function(){
		embedSWF();
		revealNavigation();
		writeDate();
		prepareBios();
	}
);


// EMBED SWF
function embedSWF() {
	swfobject.embedSWF("sepg2009_headerB.swf", "flashcontent", "609", "131", "9.0.0", "expressInstall.swf");
}

// PREPARE HEADER NAV
function revealNavigation() {
	$("#attendeeNavigation>ul>li").hover(
		function() {
			$(this).addClass("show");
		},
		function() {
			$(this).removeClass("show");
		}
	);
}

// SET DATE COUNTER
function dateCounter() {

	/* Set variables */
	var today = new Date();
	var futuredate = new Date();
	
	/* Set up future date | year, month (0-11), date (1-31) */
	futuredate.setFullYear(2009, 4, 15);		
	
	/* Find milliseconds passed since Jan. 1, 1970 */
	today = today.getTime();
	
	/* Find milliseconds passed since Jan. 1, 1970 when futuredate occurs */
	futuredate = futuredate.getTime();	
	
	/* Convert milliseconds to days */
	today = MillisToDays(today);
	futuredate = MillisToDays(futuredate);
	
	/* Compare today's date with future date */
	difference = futuredate - today;
	
	if (difference == 0) {
		difference = "0";
	}

	return difference;

}

function MillisToDays(milliseconds) {
	var days = Math.ceil( milliseconds / (1000 * 60 * 60 * 24) );
	return days;
}

function writeDate() {
	$("#sidebar .module h5").html(dateCounter());
}

function prepareBios() {
	// Hide all bios on page load
	$(".speaker .bio").hide();

	// Show bio on clicking "view bio"
	$(".speaker .view-bio").toggle(
		function () {
			var grandparent_el = $(this).parents().get(1);
			var selector = "#" + grandparent_el.id + " .bio";
			$(selector).slideDown("slow");
			$(this).text("Hide bio");
			return false;
		},
		function () {
			var grandparent_el = $(this).parents().get(1);
			var selector = "#" + grandparent_el.id + " .bio";
			$(selector).slideUp("slow");
			$(this).text("View bio");
			return false;
		}
	);
}
