

$(document).ready(function() {

	jwplayer('player').setup({
	    'file': '/playlist.xml',
	    'flashplayer': '/includes/jwplayer/player.swf',
	    'width': '700',
	    'height': '440',
		'stretching': 'fill',
		'autostart': 'true',
		'repeat': 'always'
	});

	function setCurrentVideoThumb(thumbIDX) {
		$("#dirScroller").setThumb('thumb' + thumbIDX);
	}

	function setCurrentVideoDetails(videoIDX) {

		$.get('playlist.xml', function(xml) {

			var count = 0;

			$(xml).find('item').each( function() {
				if (count == videoIDX) {
					var $video = $(this);
					var title = $video.find('title').text();
					var type = $video.find('type').text();
					var director = $video.find('director').text();
					var directordrama = $video.find('directordrama').text();
					var directorphoto = $video.find('directorphoto').text();
					var link = $video.find('link').text();
					var animation = $video.find('animation').text();

					var html = '<h3>' + title + '</h3>';

					if (link != "") {
						html += '<p class="video_details_link"><a href="' + link + '" target="_blank">' + $video.find('linktitle').text() + '</a></p>';
					};
					html += '<p><span class="video_details_type">' + type + '</span></p>';

					if (director != "") {
						html += '<p><span class="video_details_title">Director:&nbsp;</span>';
						html += '<span class="video_details_text">' + director + '</span></p>';
					} else if (directordrama !=""){
						html += '<p><span class="video_details_title">Director of Dramatizations:&nbsp;</span>';
						html += '<span class="video_details_text">' + directordrama + '</span></p>';
					};

					if (directorphoto != "") {
						html += '<p><span class="video_details_title">DP:&nbsp;</span>';
						html += '<span class="video_details_text">' + directorphoto + '</span></p>';
					};

					if (animation != "") {
						html += '<p><span class="video_details_title">Animation:&nbsp;</span>';
						html += '<span class="video_details_text">' + animation + '</span></p>';
					};

					$('#videodetails').html(html);

					return false;
				};

				count++;
			});
		});

		 $('#videodetails').fadeIn('slow');
	}

	$('#reasons').mouseenter(function() {
		$('#reasons_text').css('color', '#444546');
		$("#mariostar").attr("src","images/mariostar1_ht.png");
	});

	$('#reasons').mouseleave(function() {
		$('#reasons_text').css('color', 'white');
		$("#mariostar").attr("src","images/mariostar1.png");
	});

	jwplayer().onPlaylistItem(
		function(event) {
			setCurrentVideoThumb(event.index);
			$('#videodetails').fadeOut('slow', function() {
				setCurrentVideoDetails(event.index);
			});
		}
	);
	
	setCurrentVideoThumb(0);

});
