
// create more videos list
$(document).ready(function(){
	$.ajax({
		type:"GET",
		url:root+"library/xml/videoPlaylist.xml",
		dataType:"xml",
		success:function(xml){
			$('<ul id="videoThumbList"></ul>').insertAfter("#vid_player");
			$('<h3 class="copy">More Videos</h3>').insertAfter("#vid_player");
			
			// embed first track from XML
			var firstVid = $(xml).find("track:first");
			var join = firstVid.children("location").text().indexOf('?') == -1 ? '?' : '&'
			flashembed(firstVid.children("location").text()+join+"swfwidth="+firstVid.children("width").text()+"&swfheight="+firstVid.children("height").text())
			
			// create thumbnail list for all videos
			$(xml).find("track").each(function(){
				var join = $(this).children("location").text().indexOf('?') == -1 ? '?' : '&'
				$("<li></li>")
					.html("<a href=\""+$(this).children("location").text()+join+"swfwidth="+$(this).children("width").text()+"&swfheight="+$(this).children("height").text()+"\"><img width=\"76\" height=\"50\" src=\""+root+"library/images/videos/"+$(this).children("image").text()+"\" title=\""+$(this).children("title").text()+"\" alt=\""+$(this).children("annotation").text()+"\"></a>")
					.appendTo("#videoThumbList");
			});
			
			// set now playing state
			$('<span class="nowplaying"><span class="inner">Now Playing</span></span>').appendTo("#videoThumbList li:first a");
			
			// set thumbnail listeners
			$("#videoThumbList a").click(function(e){
				flashembed($(this).attr("href"));
				$(".nowplaying").remove().appendTo($(this));
				e.preventDefault();
			});
		}
	});	
});

function flashembed(href)
{
	var hrefparts = href.split(/swfwidth=|&swfheight=/);
	var src = hrefparts[0];
	var width = hrefparts[1];
	var height = hrefparts[2];
	width = width != '' ? width : '425';
	height = height != '' ? height : '339';
	swfobject.embedSWF(src, "vid_player",width,height,"9", root+"library/swf/expressInstall.swf");
}

