function initHoverStates() {   
	$("#titleslinkcontainer1 a, #titleslinkcontainer2 a, #sectionmenucontainer a").hover(function() {
		$(this).stop(true).animate({ color: "#46688E" }, 250);
	},
	function() {
		$(this).stop(true).animate({ color: "#FFF" }, 250);
	});

	$("#sectionmenucontainer li.linked").live("mouseenter", function() {
		$(this).stop(true).animate({ color: "#FFF" }, 250);
	});
	
	$("#sectionmenucontainer li.linked").live("mouseleave", function() {
		$(this).stop(true).animate({ color: "#9CC4E4" }, 250);
	});
	
	$("#contact a").hover(function() {
		$(this).stop(true).animate({ color: "#FFF" }, 250);
	},
	function() {
		$(this).stop(true).animate({ color: "#9CC4E4" }, 250);
	});
	
	$("#screenings .openscreening").hover(function() {
		$("div", this).stop(true).animate({ color: "#9CC4E4" }, 250);
	},
	function() {
		$("div", this).stop(true).animate({ color: "#FFF" }, 250);
	});
	
	$("#screenings .closedscreening").hover(function() {
		$("div", this).stop().animate({ "top": "-22px" }, 250);
	},
	function() {
		$("div", this).stop().animate({ "top": "0px" }, 250);
	});	
}

function initClickEvents() {
	$("#sectionmenucontainer li.linked").live("click", function() {
		var href = $(this).attr("id");
    	var linkedSection = href.substring(0, href.length - 4);
		$.bbq.pushState({ url: linkedSection });
	});
	
	$("#screenings .openscreening").click(function() {
		showForm($(this).attr("id"), _filmID);
	});
	
	$("li.track").live("click", function() {
		$("li.playing").removeClass("playing");
		$(this).addClass("playing");
		loadTrack($("span.tracktitle", this).text(), $("span.trackartist", this).text(), $(this).index() + 1);
	});
}

function fadeSection(theSection) {
	var linkedSection = _currentSection.substring(0, _currentSection.length - 4);	
	
	if (_currentSection != "begin") {
		$("#" + linkedSection + "tab").fadeOut(_fadeOutSpeed, function(){showSection(theSection);});
		$("#sectionmenucontainer li[id|=" + _currentSection + "]").animate({ color: "#9CC4E4" }, 250);
		$("#sectionmenucontainer li[id|=" + _currentSection + "]").addClass("linked");
		$("#sectionmenucontainer li[id|=" + theSection + "]").unbind();
		$("#sectionmenucontainer li[id|=" + theSection + "]").removeClass("linked");
		$("#sectionmenucontainer li[id|=" + theSection + "]").animate({ color: "#FFF" }, 250);
		$("#footer").animate({ opacity: 0.0 }, _fadeOutSpeed).delay(400).animate({ opacity: 1.0 }, _fadeInSpeed);
	} else {
		showSection(_firstSection);
		$("#sectionmenucontainer li[id|=" + _firstSection + "]").animate({ color: "#FFF" }, 250);
		$("#sectionmenucontainer li[id|=" + _firstSection + "]").unbind();
		$("#sectionmenucontainer li[id|=" + _firstSection + "]").removeClass("linked");
		$("#footer").delay(400).animate({ opacity: 1.0 }, _fadeInSpeed);
	}	
	$("body").css("background-color", "#000");
}
			
function showSection(newSection) {	
	var linkedSection = newSection.substring(0, newSection.length - 4);	
	var audio = document.getElementsByTagName('audio')[0];
	var song = document.getElementsByTagName('audio')[1];
	
	if (_ie == -1) {
		if (_canPlayAudio) {
			if (_currentSection == "scorelink") {
				audio.pause();
				_audioPaused = true;
			}
			if (newSection == "scorelink" && _audioPaused) {
				audio.play();
				_audioPaused = false;
			} else if (newSection == "scorelink" && !_audioPaused) {
				$("li.track").eq(0).click();
			}
		} else {
			if (newSection == "scorelink" && !_audioPaused)
				$("li.track").eq(0).click();
		}
	} else {
		if (newSection == "scorelink" && !_audioPaused)
			$("li.track").eq(0).click();
	}
		
	_currentSection = newSection;
	
	$("#" + linkedSection + "tab").delay(400).fadeIn(_fadeInSpeed);
	$("#sectioncontainer").css({ "height": $("#" + linkedSection + "tab").height() + "px" });
	
	var sectionContainerHeight = $("#sectioncontainer").height();
	if (sectionContainerHeight < 290)
		$("#sectioncontainer").css({ "height": "290px" });	
	$("#sectioncontainer").css({ overflow: "visible" });
}

function loadTrack(trackTitle, composer, trackNumber) {	
	if (_ie == -1) {
		if (_canPlayAudio) {
			if (_currentTrack != trackNumber) {
				_currentTrack = trackNumber;
			
				$("#songtitle").html(trackTitle);
				$("#songartist").html(composer);
			
				$("#audio1").html(
					"<source src=\"" + _audioPath + trackNumber + ".mp3\" type=\"audio/mpeg\" />" + 
					"<source src=\"" + _audioPath + trackNumber + ".ogg\" type=\"audio/ogg\" />"
				);
			
				var audio = document.getElementsByTagName("audio")[0];
				audio.load();
				audio.play();
				audio.addEventListener("ended", playNextTrack);
			}
		} else {
			$("#audiocontainer").css({ height: "190px" });
			$(".tracklist").css({ display: "none" });
			$("#audiocontainer").html("<div id='quicktimedefault'>We are not able to provide HTML5 audio to your browser.<br /><a href='quicktime/audio' target='_blank'>Click here</a> to listen with QuickTime.</div>");
		}
	} else {		
		$("#audiocontainer").css({ height: "190px" });
		$(".tracklist").css({ display: "none" });
		$("#audiocontainer").html("<div id='quicktimedefault'>Are you using Internet Explorer?<br /><a href='quicktime/audio' target='_blank'>Click here</a> to listen with QuickTime.</div>");
	}
}

function playNextTrack() {
	var numSongs = $("li.track").length;
	
	if (_currentTrack == numSongs)
		$("li.track").eq(0).click();
	else
		$("li.track").eq(_currentTrack).click();
}

function showQTSong() {
	$("#songcontainer").css({ height: "190px" });
	if (_ie == -1)
		$("#songcontainer").html("<div id='quicktimedefault'>We are not able to provide HTML5 audio to your browser.<br /><a href='quicktime/audio/song' target='_blank'>Click here</a> to listen with QuickTime.</div>");
	else
		$("#songcontainer").html("<div id='quicktimedefault'>Are you using Internet Explorer?<br /><a href='quicktime/audio/song' target='_blank'>Click here</a> to listen with QuickTime.</div>");
}

function showForm(screeningID, filmID) {
	scrollTop = $(window).scrollTop();
	if (scrollTop > 500)
		scrollTop = 500;
	$("#rsvpcontainer").css({ "margin-top": scrollTop + 230 + "px" });
	$("#rsvpframe").attr("src", "../rsvp.php?screeningid=" + screeningID + "&filmID=" + filmID);
	$("#overlay").css("visibility", "visible");
}

function hideForm() {
	$("#overlay").css("visibility", "hidden");
	$("#rsvpframe").attr("src", "../blankrsvp.php");
	$("#rsvpcontainer").css({ "margin-top": "230px" });
}

function sizeWindow() {
	width = $(window).width();
	height = $(window).height();
	
	if (width < 1260)
		$(".sectionimage").stop().animate({ opacity: 0.0 }, _fadeOutSpeed);
	else
		$(".sectionimage").stop().animate({ opacity: 1.0 }, _fadeInSpeed);
}




