/**
 * Inserts a QuickTime object into the document at the current location
 * @author Michael Hesler
 * @param {string} url This is the url of the media file to play
 * @param {int} width This is the width of the viewable area in which the media will play. Defaults to 320
 * @param {int} height This is the height of the viewable area in which the media will play. Defaults to 256
 * @param {bool} autoplay Indicates if the media should be played immediately.  Defaults  to false.
 */
function InsertQuickTime(url,width,height,autoplay) {
	document.write(getQuickTime(url,width,height,autoplay));
}

/**
 * Gets an HTML string containing the QuickTime object that can be placed in the document.
 * @author Michael Hesler
 * @param {string} url This is the url of the media file to play
 * @param {int} width This is the width of the viewable area in which the media will play. Defaults to 320
 * @param {int} height This is the height of the viewable area in which the media will play. Defaults to 256
 * @param {bool} autoplay Indicates if the media should be played immediately.  Defaults  to false.
 */
function getQuickTime(url,width,height,autoplay) {
	if (width == undefined) width = 320;
	if (height == undefined) height = 256;
	if (autoplay == undefined) autoplay = 'false';

    var content = '';
	content += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+height+'" width="'+width+'"> ';
	content += '<param name="src" value="'+url+'">';
	content += '<param name="autoplay" value="'+autoplay+'">';
	content += '<param name="type" value="video/quicktime" height="'+height+'" width="'+width+'">';
	content += '<embed src="'+url+'" height="'+height+'" width="'+width+'" autoplay="'+autoplay+'" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">';
	content += '</object>';
	return content;
}

/**
 * Replaces all the image elements with the mediaPlaceholder css class with the
 * QuickTime object.  Applies attributes taken from the image tag to the 
 * resulting object/embed tags.  Executes after page is loaded.
 * @author Michael Hesler
 */
$(function() {
    var placeholders = $('img.mediaPlaceholder');
    placeholders.each(function() {
        var placeholder = $(this);
        var src = placeholder.attr('src');
        var width = placeholder.css('width');
        var height = placeholder.css('height');
        var autoplay = placeholder.attr('autoplay');
        placeholder.replaceWith(getQuickTime(src,width,height,autoplay));
    });
})