$(document).ready(function() {
	$.get('contents.xml', function(data){
		var filmARRAY = [];
		var thumbnail_urlARRAY = []; 
		var titleARRAY = [];
		var desARRAY = [];
		var timeARRAY = [];
		var player_urlARRAY = [];
		var store_urlARRAY = [];
		var trailer_urlARRAY = [];
		var url_ARRAY = [];   
        var html_text = '';
		var html_trailer = '';
		var index = '';
		
		$(data).find('content').each(function(){
			var $content = $(this);  
			filmARRAY.push($content.text());
			thumbnail_urlARRAY.push($content.find('thumbnail_url').text());
			titleARRAY.push($content.find('title').text()); 
			desARRAY.push($content.find('description').text());
			timeARRAY.push($content.find('duration').text());
			player_urlARRAY.push($content.find('player_url').text()); 
			store_urlARRAY.push($content.find('store_link').text());
			trailer_urlARRAY.push($content.find('trailer_link').text());
			url_ARRAY.push($content.find('url').text());
			var html_img = '<li class="thumb"><img src="' + $content.find('thumbnail_url').text() + '" width="189px" alt="' + $content.find('title').text() + '" ><span class="title">' + $content.find('title').text().replace('NOOMA ','').replace('Rob Bell', '') + '</span><div class="over"></div></li>';
			$('ul.sc_menu').append(html_img);
   		});

		//grab the default
		var variable = $('div.chooser').attr('default');
		
		//generate default
   		//var def = url_ARRAY.indexOf(variable);
		var def = 0
		var pos = (def * -190);	
		var drag = ((def * 190)/4.75);	
		if(def < (url_ARRAY.length - 5)){
			$('div.sc_menu').css({'left': pos});
			$('div.jScrollPaneDrag').css({'left': drag});
		}
		
    	html_text ='<p class="title">' + titleARRAY[def] + '</p><p class="des">' + desARRAY[def] + '</p><p class="time">Run Time: ' + timeARRAY[def] + '</p><a href="' + player_urlARRAY[def] + '" title="view the film">Watch this film</a>';
		html_trailer = '<div id="mediaspace"></div><script type="text/javascript">var so = new SWFObject("player.swf","mpl","523","294","9");so.addParam("allowfullscreen","true");so.addParam("allowscriptaccess","always");so.addParam("wmode","opaque");so.addVariable("file","' + trailer_urlARRAY[def] + '");so.addVariable("image","' + thumbnail_urlARRAY[def] + '");so.addVariable("controlbar","none");so.write("mediaspace");</script>';
		$('div.trailer').empty();
		$('div.info').empty(); 
		$('div.trailer').append(html_trailer);
		$('div.info').append(html_text); 
		   	
		$('li.thumb').eq(def).find('span.title').css({'color': '#bae1d0'});
		$('li.thumb').eq(def).find('div.over').css({
			'border-left-width': '1px',
			'border-left-style': 'solid',
			'border-left-color': '#bae1d0',
			'border-right-width': '1px',
			'border-right-style': 'solid',
		   	'border-right-color': '#bae1d0', 
			'border-top-width': '1px',
			'border-top-style': 'solid',
			'border-top-color': '#bae1d0',
			'border-bottom-width': '1px',
			'border-bottom-style': 'solid',
			'border-bottom-color': '#bae1d0',
			'width': '187px',
			'height': '104px',
			'position': 'absolute', 
			'top': '0'
		});

		//click selections
		$('li.thumb').click(function(){
			index = $('li.thumb').index(this);
	    	html_text ='<p class="title">' + titleARRAY[index] + '</p><p class="des">' + desARRAY[index] + '</p><p class="time">Run Time: ' + timeARRAY[index] + '</p><a href="' + player_urlARRAY[index] + '" title="view the film">Watch this film</a>';
			html_trailer = '<div id="mediaspace"></div><script type="text/javascript">var so = new SWFObject("player.swf","mpl","523","294","9");so.addParam("allowfullscreen","true");so.addParam("allowscriptaccess","always");so.addParam("wmode","opaque");so.addVariable("file","' + trailer_urlARRAY[index] + '");so.addVariable("image","' + thumbnail_urlARRAY[index] + '");so.addVariable("controlbar","none");so.write("mediaspace");</script>';
			$('div.trailer').empty();
			$('div.info').empty(); 
			$('div.trailer').append(html_trailer);
			$('div.info').append(html_text);
			
			//clear selections
			$('li.thumb').find('div.over').css({
				'border-left': 'none',
				'border-right': 'none',
				'border-top': 'none',
				'border-bottom': 'none'
			});
			$('li.thumb').find('span.title').css({'color': 'white'});
			
			//highlight selections
			$('li.thumb').eq(index).find('span.title').css({'color': '#bae1d0'});
			$('li.thumb').eq(index).find('div.over').css({
				'border-left-width': '1px',
				'border-left-style': 'solid',
				'border-left-color': '#bae1d0',
				'border-right-width': '1px',
				'border-right-style': 'solid',
			   	'border-right-color': '#bae1d0', 
				'border-top-width': '1px',
				'border-top-style': 'solid',
				'border-top-color': '#bae1d0',
				'border-bottom-width': '1px',
				'border-bottom-style': 'solid',
				'border-bottom-color': '#bae1d0',
				'width': '187px',
				'height': '104px',
				'position': 'absolute', 
				'top': '0'
			});
		});
	});
	$('div.scroll-pane').jScrollHorizontalPane({scrollbarHeight:11}); 
});  	


