$(document).ready(function(){
	
		var x = 0;	// counter variable for the films arrays
		var currFilmIndex = location.hash.substring(1);	

		$('#transcript-extra').hide('fast');
		$('.close-transcript-link').hide('fast');

		// if no currFilmIndex selected set it as 0
		if(!currFilmIndex){
			currFilmIndex = 0;	// stores the index of the current film
			window.location = window.location.href.replace(/\#.*/,'') + '#' + currFilmIndex;			
		}
			
		var filmsArray = new Array();
		filmsArray[0] = "/projects/birdseyeview2009/mp4/ica_ysl_468x350.mp4&amp;image=/projects/birdseyeview2009/img/ysl_film_still.jpg";
		filmsArray[1] = "/projects/birdseyeview2009/mp4/ica_gareth_pugh_468x266.mp4&amp;image=/projects/birdseyeview2009/img/gp_film_still.jpg";
		filmsArray[2] = "/projects/birdseyeview2009/mp4/ica_hannah_marshall_468x350.mp4&amp;image=/projects/birdseyeview2009/img/i_film_still.jpg";	
		filmsArray[3] = "/projects/birdseyeview2009/mp4/ica_billow_468x266.mp4&amp;image=/projects/birdseyeview2009/img/billow_film_still.jpg";

		var filmDescriptionArray = new Array();
		filmDescriptionArray[0] = "<strong>Directed by:</strong> <br />Sarah Chatfield & Chris Sweeney  <br />at Colonel Blimp, 2008 <br /> <br /><strong>Featuring</strong> <br />Yves Saint Laurent Menswear S/S 2009";
		filmDescriptionArray[1] = "<strong>Directed by:</strong> <br />		Ruth Hogben, 2009<br />	<br />		<strong>Featuring:</strong> <br />		Gareth Pugh Autumn/Winter 2009";
		filmDescriptionArray[2] = "<strong>Directed by:</strong><br />Monica Elkelv and Darren Smith, 2009<br /><br />	<strong>Featuring:</strong><br /> 	Hannah Marshall Spring/Summer 2009";	
		filmDescriptionArray[3] = "<strong>Directed by:</strong><br />		Kathryn Ferguson, 2009<br /><br />	<strong>Featuring:</strong><br /> Erika Trotzig Autumn/Winter 2009";

		var filmTitleArray = new Array();
		filmTitleArray[0] = "'YSL S/S 2009'";
		filmTitleArray[1] = "'Gareth Pugh A/W 09'";
		filmTitleArray[2] = "'I'";	
		filmTitleArray[3] = "'Billow'";		
	
		//loadCurrentFilm();
		setFilmSelected(currFilmIndex);		

		// load the first movie when the page is ready	
		$.fn.media.defaults.flashvars = { plugins:'googlytics-1'};		
		$('.VideoPlayer').attr('href', '/projects/antonypriceforyourpleasure/swf/player.swf?streamer=rtmp://red5.showstudio.com/streaming&amp;file=/projects/birdseyeview2009/flv/ICA_468x266_Deinterlace.flv&amp;image=/projects/birdseyeview2009/img/film_still.jpg&amp;autostart=true');	
		$('.VideoPlayer').media( {   width: 620, height: 371, params:{allowFullScreen:true}, bgColor:'#FFFFFF', flashVersion:'9'  });	
		$('.VideoPlayer2').attr('href', '/swf/mediaplayer_white.swf?file='+ filmsArray[currFilmIndex] + '&autostart=false&screencolor=0x000000');
		$('.VideoPlayer2').media( {   width: 620, height: 370, params:{allowFullScreen:true}, bgColor:'#FFFFFF', flashVersion:'9'  });
		$('.film-title').html(filmTitleArray[currFilmIndex]);
		$('.film-description').html(filmDescriptionArray[currFilmIndex]);	
	
	
		function loadCurrentFilm(){
				$('.VideoPlayer2').attr('href', '/swf/mediaplayer_white.swf?'+ filmsArray[currFilmIndex] + '&amp;autostart=true');	
				$('.VideoPlayer2').media( {   width: 620, height: 370, params:{allowFullScreen:true}, bgColor:'#FFFFFF', flashVersion:'9'  });	
		}	
	
		// NEEEDS TO ME MOVED TO A REAUSABLE FUNCTION - INSTEAD OF USING ONE FUNCTION FOR EACH ONE OF THE LINKS
		// when clicking the individual films load the corresponding player
				
		$('#VideoThumbnails a:eq(0)').mousedown(function() {
				currFilmIndex = $(this).attr("href").substring(1);
				loadCurrentFilm();
				setFilmSelected(0);
		});

		$('#VideoThumbnails a:eq(1)').mousedown(function() {
				currFilmIndex = $(this).attr("href").substring(1);
				loadCurrentFilm();
				setFilmSelected(1);
		});

		$('#VideoThumbnails a:eq(2)').mousedown(function() {
				currFilmIndex = $(this).attr("href").substring(1);
				loadCurrentFilm();
				setFilmSelected(2);
		});

		$('#VideoThumbnails a:eq(3)').mousedown(function() {
				currFilmIndex = $(this).attr("href").substring(1);
				loadCurrentFilm();
				setFilmSelected(3);
		});


		$.gaTracker('UA-7210865-1');
		$.gaTracker('UA-7210865-1');		

		function setFilmSelected(whichFilm)
		{
			removeSelectedNav();
			$('#VideoThumbnails a:eq('+whichFilm+')').addClass("selectedVideoThumb");	
		}

		function loadCurrentFilm(){

				// stop the top videoPlayer
				$('.VideoPlayer').attr('href', '/projects/antonypriceforyourpleasure/swf/player.swf?streamer=rtmp://red5.showstudio.com/streaming&amp;file=/projects/birdseyeview2009/flv/ICA_468x266_Deinterlace.flv&amp;image=/projects/birdseyeview2009/img/film_still.jpg&amp;autostart=false');	
				$('.VideoPlayer').media( {   width: 620, height: 370, params:{allowFullScreen:true}, bgColor:'#FFFFFF', flashVersion:'9'  });	

				$('.VideoPlayer2').attr('href', '/swf/mediaplayer_white.swf?file='+ filmsArray[currFilmIndex] + '&autostart=true&screencolor=0x000000');
				$('.VideoPlayer2').media( {   width: 620, height: 371, params:{allowFullScreen:true}, bgColor:'#FFFFFF', flashVersion:'9'  });	

				$('.film-title').html(filmTitleArray[currFilmIndex]);
				$('.film-description').html(filmDescriptionArray[currFilmIndex]);

		}

		function removeSelectedNav()
		{
				$('#VideoThumbnails a').removeClass("selectedVideoThumb");	
		}
		
	     // shows the slickbox DIV on clicking the link with an ID of "slick-show"
        $('a.transcript-link').click(function() {
          	$('#transcript-extra').slideDown('slow');
			$('.close-transcript-link').show('fast');
			$('.transcript-link').hide('fast');			
          	return false;
        });		
		
		// shows the slickbox DIV on clicking the link with an ID of "slick-show"
	  $('a.close-transcript-link').click(function() {
	    	$('#transcript-extra').slideUp('slow');
			$('.close-transcript-link').hide('fast');
			$('.transcript-link').show('fast');			
	    	return false;
	  });
		
	 
});

