$(document).ready(function(){
	
	// for each link to an mp3, remove it and add music player to show-media div...

	$("#content a[href*='.mp3']").each(function(){
		var embedcode = '<embed width="172" height="68" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" flashvars="song=' + $(this).attr("href") + '" src="/scripts/flash/music_player.swf"/>'
		$(this).parent().hide().prevAll(".show-media:first").prepend(embedcode);
	});

	
	// for each youtube vid, remove it and add it to the nearest show-media div above it...
	
	var curVid = 0;
	$("div.video").each(function(){
		curVid++;

		// select the YT player in this div
		var myObject = $(this).children(":first");

		// get width and height of YT player
		var myWidth = parseInt(myObject.attr("width"));
		var myHeight = parseInt(myObject.attr("height"));

		// hide the div and set ID for fancybox to point to
		$(this).hide().attr("id","video"+curVid);

		// select previous show-media div and add a link to the start of it pointing to our div
		$(this).prevAll(".show-media:first").prepend("<p class='video_link'><a class='video_link video_link"+curVid+"' href='#video"+curVid+"'>Watch video</a></p>");

		// add fancybox to this link
		$("a.video_link"+curVid).fancybox({
			'hideOnContentClick': false,
			'overlayShow':	true,
			'overlayOpacity': .8,
			'overlayColor': "#000",
			'zoomOpacity':true,
			'frameWidth':myWidth,
			'frameHeight':myHeight
		});
	});
});
