$(document).ready(function(){
	
	var x = 0;	// counter variable for the films arrays
	var k = 0;	// counter variable for the films arrays
	var currFilmIndex;	// stores the index of the current film
	var filmsArray = new Array();
	var filmTitlesArray = new Array();	
	var currFilmIndex = location.hash.substring(1);	

	var tweeterMessageArray = new Array();
	var tweeterMessageDateArray = new Array();
	
	// if no currFilmIndex selected set it as 0
	if(!currFilmIndex){  currFilmIndex = 0;	}
	
	loadFashionFilm();
	// initialize Google Analytics
	$.gaTracker('UA-7210865-1');

	// when clicking the individual films load the corresponding player
	$('.fashionFilm .viewFashionFilm').click( function() {
			removeSelectedNav();
			// scroll to the page top
			$('html,body').animate({scrollTop: 200}, 500);
			loadFashionFilm();
	});

	// when clicking the individual films load the corresponding player
	$('.videoThumb a').each( function() {
		$(this).attr('video', $(this).attr('href'));
		$(this).attr('href', '#' + $(this).parent('.videoThumb').attr('id').replace(/^video/,'') );		
		$(this).click(function() {
			removeSelectedNav();
			// set the video title
			$("#filmTitle h4").html($(this).attr('title'));
			// display the video
			$('.VideoPlayer').attr('href', $(this).attr('video') );	
			$('.VideoPlayer').media( {   width: 600, height: 363, params:{allowFullScreen:true, autoPlay:true}, bgColor:'#f7f7f9', flashVersion:'9'  });	
			// scroll to the page top
			$('html,body').animate({scrollTop: 200}, 500);
			$(this).addClass("selectedVideoThumb");
			// send the play of this clip to the server, to update the user preferences
			$.ajax({ type: "GET", url: "/project/lettherebelight/play/" + $(this).attr('href').replace(/^\#/,'') });
			// remove the new marker
			$(this).siblings('.new').remove();
		});
	});

	function loadFashionFilm(){
			$('.VideoPlayer').attr('href', '/swf/videoplayer.swf?src=/projects/lettherebelight/mp4/lilys.mp4&img=/projects/lettherebelight/img/lilys_still.jpg&autoplay=true');	
			$('.VideoPlayer').media( {   width: 600, height: 368, params:{allowFullScreen:true, autoPlay:true}, bgColor:'#f7f7f9', flashVersion:'9'  });		
	}

	function loadTweeterFeed(){
			$(".TwitterFeed").remove();		
			$(".Live").append('<div class="TwitterFeed"></div>');				
			for (k=0;k<=3;k++){
				$(".TwitterFeed").append('<h3>'+tweeterMessageDateArray[k]+'</h3>');
				$(".TwitterFeed").append('<p>'+tweeterMessageArray[k]+'</p>');	
			}		
			$(".TwitterFeed").append('<a class="twitterLink" title="Showstudio twitter" href="http://twitter.com/showstudio">  [Follow us on twitter] </a>');	
	}
		
	function removeSelectedNav(){
			$(".selectedVideoThumb").removeClass("selectedVideoThumb");	
	}
		
});