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);
	});
	
	$(".videonavitem").live("mouseenter", function() {
		$(".videothumb", this).stop(true).animate({ opacity: 1.0 }, 200);
		$(".videothumbtext", this).slideDown(200);
	});
	
	$(".videonavitem").live("mouseleave", function() {
		$(".videothumb", this).stop(true).animate({ opacity: 0.7 }, 200);
		$(".videothumbtext", this).slideUp(200);
	});
	
	$(".photosnavitem").live("mouseenter", function() {
		$(".videothumb", this).stop(true).animate({ opacity: 1.0 }, 200);
	});
	
	$(".photosnavitem").live("mouseleave", function() {
		$(".videothumb", this).stop(true).animate({ opacity: 0.7 }, 200);
	});
	
	$("#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 });
	});
	
	$(".videonavitem").live("click", function() {
		var newvideo = $(this).attr("id");
		loadVideo(newvideo, _videoDirectory);
	});
	
	$(".photosnavitem").live("click", function() {
		var newphoto = $(this).attr("id");
		loadPhoto(newphoto);
	});
	
	$("#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);
	});
	
	$("#scorevideolink").click(function() {
		if (_currentVideo != "scoringsuper8") {
			_videoPaused = false;
			_firstVideo = "scoringsuper8";
			$("#" + _currentVideo + " .videothumbtext").css({ display: "none" });
		}
		$(this).css({ cursor: "default" });
		$.bbq.pushState({ url: "video" });
	});
}

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 video = document.getElementsByTagName('video')[0];
	var audio = document.getElementsByTagName('audio')[0];
	var song = document.getElementsByTagName('audio')[1];
	$("#scorevideolink").css({ cursor: "pointer" });
	
	if (_ie == -1) {
		if (_canPlayVideo) {
			if (_currentSection == "videolink") {
				video.pause();
				_videoPaused = true;
			}
	
			if (newSection == "videolink" && _videoPaused) {
				video.play();
				video.poster = "";
				_videoPaused = false;
			}
		}
		
		if (_canPlayAudio) {
			if (_currentSection == "scorelink") {
				audio.pause();
				_audioPaused = true;
			}
			
			if (_currentSection == "songlink") {
				song.pause();
				_songPaused = true;
			}
	
			if (newSection == "scorelink" && _audioPaused) {
				audio.play();
				_audioPaused = false;
			} else if (newSection == "scorelink" && !_audioPaused) {
				$("li.track").eq(0).click();
			}
	
			if (newSection == "songlink") {
				song.play();
				_songPaused = false;
			}
		} else {
			if (newSection == "scorelink" && !_audioPaused)
				$("li.track").eq(0).click();
			if (newSection == "songlink" && !_songPaused)
				showQTSong();
		}
	} else {
		if (newSection == "scorelink" && !_audioPaused)
			$("li.track").eq(0).click();
		if (newSection == "songlink" && !_songPaused)
			showQTSong();
	}
		
	_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 loadPhoto(newphoto) {
	var slidekey = newphoto - 1;
	$("#photosslideshow").rsfSlideshow("goToSlide", slidekey);
	$("#" + _currentPhoto).addClass("photosnavitem");
	$("#" + _currentPhoto).mouseleave();
	$("#" + newphoto).removeClass("photosnavitem");
	_currentPhoto = newphoto;
}

function loadVideo(clip, directory) {
	if (_ie == -1) {
		if (_canPlayVideo) {
			if (_currentVideo != clip) {
				$("#video1").attr("poster", "");
				$("#video1").html(
					"<source src=\"" + directory + clip + ".mp4\" type=\"video/mp4\" />" + 
					"<source src=\"" + directory + clip + ".webm\" type=\"video/webm\" />"
				);
				$("#video1").attr("poster", directory + clip + ".jpg");
				
				video = document.getElementsByTagName("video")[0];
				video.load();
			}
		} else {
			$("#videocontainer").html("<div id='quicktimedefault'>We are not able to provide HTML5 video to your browser.<br /><a href='quicktime' target='_blank'>Click here</a> to watch with QuickTime.</div>");
		}
	} else {
		$("#videocontainer").html("<div id='quicktimedefault'>Are you using Internet Explorer?<br /><a href='quicktime' target='_blank'>Click here</a> to view QuickTime videos.</div>");
	}
	
	if (_currentVideo != "begin") {
		$("#" + _currentVideo).addClass("videonavitem");
		$("#" + _currentVideo).mouseleave();
		$("#" + clip).mouseenter();
		$("#" + clip).removeClass("videonavitem");
	} else {
		$("#" + _firstVideo).mouseenter();
		$("#" + _firstVideo).removeClass("videonavitem");
	}	
	
	_currentVideo = clip;
}

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);
}

function preloadLargeImages(movieTitle) {
	numImages = $(".slides li").length;
	for(i = 0; i < numImages; i++) {
		if (i < 9)
			var image = $("<img />").attr("src", "../images/" + movieTitle + "/photos/" + movieTitle + "0" + (i + 1) + ".jpg");
		else
			var image = $("<img />").attr("src", "../images/" + movieTitle + "/photos/" + movieTitle + (i + 1) + ".jpg");
	}	
}




