// This is for the Video Gallery page

var photoPlaylist = 'xml/photoGallery.xml';
var isFirst;

jQuery(function($){
	
	if ($('.video_scroll_contents').length) {
		$.ajax({
			type: "GET",
			url: photoPlaylist,
			dataType: "xml",
			success: function(xml) {
				isFirst = true;
				$(xml).find('playlist media').each(function(){
					var id_text = $(this).attr('id');
					var thumbnail = $(this).find('asset[type=thumbnail]').text();
					var photo = $(this).find('asset[type=photo]').text();
					var href = $(this).find('asset[type=href]').text();
					var photo_title = $(this).find('description').attr('title');
					var short_desc = $(this).find('description short-description').text();
					var long_desc = $(this).find('description long-description').text();
					var tag = $(this).find('tags').attr('type');
					if (isFirst) {
						$('.video_player_container h2:eq(0)').text(photo_title);
						$('.video_player_container img:eq(0)').attr('src',photo);
						//$('.video_player_container p:eq(0)').html(long_desc);
					}
					isFirst = false;
					var html = '<a href="'+href+'"><img src="'+thumbnail+'" alt=""/></a><h2>'+
								  '<a href="'+href+'">'+photo_title+'</a></h2><p>'+short_desc+'</p><span style="display: none;">'+
								  '</span><span style="display: none;" title="'+photo_title+'">'+photo+'</span><span '+
								  'style="display: none;">'+tag+'</span>';					
					$('<li></li>').html(html).appendTo('.video_scroll_contents ul');
				});
				//$('.video_scroll_contents').jScrollPane({showArrows:true});
				$('.video_scroll_contents ul li a').click(function(e){
					e.preventDefault();
					var photo_title = $(this).parents('li').find('h2 a').text();
					var photo = $(this).parents('li').find('span:eq(1)').text();
					var long_desc = $(this).parents('li').find('span:eq(0)').text();
					$('.video_player_container h2:eq(0)').text(photo_title);
					$('.video_player_container img:eq(0)').attr('src',photo);
					$('.video_player_container img:eq(0)').attr('title',photo_title);
					//$('.video_player_container p:eq(0)').html(long_desc);
				});
			}
		});
	
	$('.video_nav li a').click(function(e){
		e.preventDefault();
		var aLink = $(this);
		$('.video_scroll_contents ul li').each(function(){
			if ($(this).find('span:last').text()!=aLink.attr('href')&&$(this).is(':visible')) $(this).stop(false, true).slideUp(500); 
			else if ($(this).find('span:last').text()==aLink.attr('href')&&$(this).is(':hidden')) $(this).stop(false, true).slideDown(500);
		});
		setTimeout("$('.video_scroll_contents').jScrollPane({showArrows:true});",550);
	});
	
	}
});
