// author: Steve Gu
// date: 9/02/09
// this snipped of jQuery replaces image elements w/ the 'audio' and 'video' class id 
// with the proper code for inline playing
//

// I can't get replaceWith or replaceAll to work, so here is the equivalent
$.fn.replace = function(o) { return this.after(o).remove(); }; 

$(function() {
    AUDIO_PLAYER_PATH = '/swf/1pixelout.swf';
  	VIDEO_PLAYER_PATH = '/swf/player.swf';

    $(".audio").each(function() {

	original_src = $(this).attr('href');
	
	
	audio_player = '<object type="application/x-shockwave-flash"' +
	               'data="' + AUDIO_PLAYER_PATH + '" height="24" width="290">' +
	    '<param name="movie" value="' + AUDIO_PLAYER_PATH + '">' +
	    '<param name="wmode" value="transparent"> <param name="menu" value="false"> <param name="quality" value="high">' +
	    '<param name="FlashVars" value="soundFile=' + original_src + '">' +
	    '<embed src="' + AUDIO_PLAYER_PATH + '" flashvars="soundFile=' + original_src  + '" height="24" width="290">' +
	    '</object>';

	$(this).replace(audio_player);

	/* use 'this' as the dom object, so $(this).attr('class') */
    })

  $(".video").each(function() {

	original_src = $(this).attr('href');
	pos = original_src.lastIndexOf("/");
	filename = original_src.substr(pos);
	
	video_player = "<span id='cjvideo'>The player will show in this paragraph</span>" +
	"<script type='text/javascript'>" +
	"var s1 = new SWFObject('" + VIDEO_PLAYER_PATH + "','player','320','186','9');" +
	"s1.addParam('allowfullscreen','true');" + 
	"s1.addParam('allowscriptaccess','always');" +
	"s1.addParam('flashvars','file=" + original_src + "&image=../../videothumbs" + filename + ".jpg');" +
	"s1.write('cjvideo');" +
	"</script>" ;


	$(this).replace(video_player);

	/* use 'this' as the dom object, so $(this).attr('class') */
    })
});
