function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function primeVideoPlayer() {	//h-c collage
	//first send the total video count to the Flash player
	var movieCount= $('.video-path a').length;
	getFlashMovie("HCVideo").sendMovieCountToFlash(movieCount);
	
	//next send the array of the path to every video in the playlist to the Flash player	
	var movies = new Array();
	$('.video-path a').each(function (i) {
		movies[i] = $(this).attr("href");
		getFlashMovie("HCVideo").sendMoviePathToFlash(movies[i]);
	});

	//next send the array of the title of every video in the playlist to the Flash player
	var movieTitles = new Array();
	$('.movie-image h5').each(function (i) {
		movieTitles[i] = $(this).text();
		getFlashMovie("HCVideo").sendMovieTitleToFlash(movieTitles[i]);
	});
	//Finally tell Flash to play the first movie and set the scrubber to a specific position
	getFlashMovie("HCVideo").startFirstMovie(5);
}	

$(document).ready(function(){
	//Embed the video player .swf	
	var flashvars = {};
	var params = {
		allowScriptAccess:'sameDomain',
		bgcolor: "#ffffff",
		quality: "high"
	};
	var attributes = {
		id: "HCVideo",
		align: "middle",
		name: "HCVideo"
	};
	swfobject.embedSWF("/flash/video-player/HCvideoPlayer.swf", "replacedContent", "440", "365", "9.0.0", "/flash/video-player/expressInstall.swf", flashvars, params, attributes);
	
	$('#controller div.movie-image').click(function(event) {
		/*When a play list item is clicked the flv path is captured and used in a swfObject call that replaces the current movie,
			the previous current playlist item is unstyled and the new current one styled and made full opacity,
			and the player title and teaser updated  */
		$('#screen').removeClass('initial');
		$('#controller li#current').attr('id', '');
		$(this).parent().attr('id', 'current');
		$(this).parent().find('img').css("opacity", 1.0);
		var titleCopy = $(this).find('h5').html();
		$('#screen h4').html(titleCopy);
		// $("#section-intro").css("display", "none");
		var text = $("#controller div.movie-image").index(this);
		getFlashMovie("HCVideo").sendNewMovieToFlash(text);
	});	
	
		$('#controller li:first').attr('id', 'current'); //style first playlist item as current
		var titleCopy = $('#controller li:first h5').html(); //capture title first playlist item
		$('#screen h4').html(titleCopy);  //set player title

		$('#controller li').hover(
	      function () {
					$(this).addClass('active');	
					$(this).find('img').css("opacity", 0.75);
	      }, 
	      function () {
					$(this).removeClass('active');	
					$(this).find('img').css("opacity", 1.0);
	      }
	    );
		$('#controller ul').jScrollPane({'scrollbarWidth': 23, 'scrollbarMargin': 0, 'showArrows':true});
}
); // document ready

function getImageFromFlash(str) {
	var nextImage = $('.movie-image').find('img').eq(str).attr("src");
	return nextImage;
}

function updatePlaylist(str) {	
	$('#screen').removeClass('initial');
	$('#controller li#current').attr('id', '');
	$('#controller li').eq(str).attr('id', 'current');
	var titleCopy = $('#controller li').eq(str).find('h5').html();
	$('#screen h4').html(titleCopy);
}