//<![CDATA[

var video_list = new Array();


function videoQuickTime(video_url, audio_enabled, float_dir, caption, width, height, div_name) {
	this.video_url = video_url;
	this.audio_enabled = audio_enabled;
	this.float_dir = float_dir;
	this.caption = caption;
	
	this.vid_width = width;
	this.embed_vid_width = width;
	this.vid_height = height + 28;  // allow for control bar
	this.embed_vid_height = height + 28; // allow for control bar
	
	this.embed_frame_width = width+14;
	this.frame_width = width+12;
	//this.frame_height = height+2;
	this.div_name = div_name;
	
	this.div_caption = this.div_name+"_cap";
	this.auto_play = "true";
	this.loop = "true";
	this.controller = "true";
	this.scale = "tofit";
	this.initial_volume = "0";
	this.autohref="true";
	this.mime_type="video/quicktime";
	
	this.w_offset = 10;
	this.h_offset = 10;
	this.cmd = "";
	
	// functions 
	this.init = initQuickTime;
	this.getCmd = getQuickTimeCmd;
}	
	
function initQuickTime() {	

	if (is_msie) {
		this.cmd = this.cmd + '<div id="'+this.div_name+'" style="margin-top:2mm; margin-right:2mm; float:'+this.float_dir+'; width:'+this.frame_width+'px; overflow:hidden;">\n';
		this.cmd = this.cmd + '<div class="qt_vid_div" style="width:'+this.vid_width+'px;">\n';
		this.cmd = this.cmd + '<div style="border:0px ridge red;" style="width:'+this.frame_width+'px;">\n'; 
	}
	else {
		this.cmd = this.cmd + '<div id="'+this.div_name+'" style="margin-top:2mm; margin-right:2mm; float:'+this.float_dir+'; width:'+this.embed_frame_width+'px; overflow:hidden;">\n';
		this.cmd = this.cmd + '<div class="qt_vid_div" style="width:'+this.embed_vid_width+'px;">\n';
		this.cmd = this.cmd + '<div style="border:0px ridge red;" style="width:'+this.embed_frame_width+'px; text-align:center;">\n'; 
	}

	this.cmd = this.cmd + '<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="'+this.vid_width+'" height="'+this.vid_height+'" style="overflow:hidden;" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> \n';
		this.cmd = this.cmd + '<param name="src" value="'+this.video_url+'" />\n';
		this.cmd = this.cmd + '<param name="autoplay" value="'+this.auto_play+'" />\n'; 
		this.cmd = this.cmd + '<param name="controller" value="'+this.controller+'" />\n'; 
		this.cmd = this.cmd + '<param name="loop" value="'+this.loop+'" />\n'; 
		this.cmd = this.cmd + '<param name="cache" value="true" />\n';
		this.cmd = this.cmd + '<param name="scale" value="'+this.scale+'" />\n'; 
		this.cmd = this.cmd + '<param name="volume" value="'+this.initial_volume+'" />\n';
		this.cmd = this.cmd + '<param name="autohref" value="'+this.autohref+'" />\n';
		this.cmd = this.cmd + '<param name="enablejavascript" value="true" />\n';
		if (this.mime_type.length>2)
		    this.cmd = this.cmd + '<param name="type" value="'+this.mime_type+'" />\n';
		this.cmd = this.cmd + '<embed style="margin:0px;" src="'+this.video_url+'" ';
		if (this.mime_type.length > 2)
		    this.cmd = this.cmd +' type="'+this.mime_type+'" ';
		this.cmd = this.cmd + ' loop="'+this.loop+'" cache="true" volume="'+this.initial_volume+'" enablejavascript="true" scale="'+this.scale+'" width="'+this.embed_vid_width+'" height="'+this.embed_vid_height+'" autoplay="'+this.auto_play+'" autohref="'+this.autohref+'"  controller="'+this.controller+'"      pluginspage="http://www.apple.com/quicktime/download/"></embed>\n';
	this.cmd = this.cmd + '</object> \n';
	this.cmd = this.cmd + '</div> \n';
	this.cmd = this.cmd + '<div class="qt_vid_caption"> \n';
		this.cmd = this.cmd + this.caption+"\n";
	this.cmd = this.cmd + '</div> \n </div> \n </div>';

	document.writeln(this.cmd);
	// alert (this.cmd);
}
function getQuickTimeCmd () {return (this.cmd);}

// ===================================================================


function videoMP4 (filename, audio_enabled, float_pos, caption, width, height, vid_id) {
	this.w = getAvailWidth();
	this.h = getAvailHeight();
	this.video_buffer = 20;
	// for aac audio codec
	//this.archive_param = "mediaframe-mpeg4.jar,mediaframe-aac.jar";
	//for mp3 audio codec
	this.archive_param = "mediaframe-mpeg4.jar,jlme0.1.3.jar";
	this.code_param="mediaframe.mpeg4.MPEG4.class";
	this.icons = "http://raupplab.umd.edu/video/icons";
	this.audio_enabled = audio_enabled;
	this.filename = filename;
	this.float_pos = float_pos;
	this.caption = caption;
	this.width = width;
	this.height = height;
	this.id = vid_id;
	this.applet_name = vid_id+"_applet";
	this.loop = true;
	
	this.monitor_started = 0;
	this.init_style = 0;

	// functions
	this.initVideo = initMP4Video;
	this.stopApplet = video_applet_stop;
	this.startApplet = video_applet_start;
	this.video_applet_ready = video_applet_ready;
	this.resizeVideo = resizeVideo;
	this.audioOFF = audioOFF;
	this.audioON = audioON;
	this.audioToggle = audioToggle;
	this.setVideoBuffer = setVideoBuffer;

	if (this.init_style==1) {
		var cmd  = cmd + '<div class="video_caption" id="'+this.id+'"\n';
			cmd = cmd + 'style = "position:relative; float:'+this.float_pos+'; width:'+(this.width)+'px; padding:5px; margin:10px; border:3px ridge rgb(0,128,0); z-index:10;"></div> \n\n';
	
	}
}

function audioToggle() {
    this.audio_enabled = !this.audio_enabled;
    this.initVideo();
}
function audioOFF () {
    this.audio_enabled = false;
    this.initVideo();
}
function audioON () {
    this.audio_enabled = true;
    this.initVideo();
}
function setVideoBuffer (vbuff_pcnt) {
    this.video_buffer = vbuff_pcnt;
}

function initMP4Video () {
	var cmd = '<a name="'+this.applet_name+'"></a> \n';
		if (this.init_style!=1) {
			cmd  = cmd + '<div class="video_caption" id="'+this.id+'"\n';
			cmd = cmd + 'style = "position:relative; float:'+this.float_pos+'; width:'+(this.width)+'px; padding:5px; margin:10px; border:3px ridge rgb(0,128,0); z-index:10;"> \n\n';
		}
		cmd = cmd + '<div id="'+this.id+'_2" style="position:relative; width:'+this.width+'px; height:'+this.height+'px"> \n';
		cmd = cmd+'<applet name="'+this.applet_name+'" code="'+this.code_param+'" archive="'+this.archive_param+'" width="'+this.width+'" height="'+this.height+'" mayscript="true">\n';
		cmd = cmd + '<param name="id" value="ID: '+this.filename+'" /> \n';
		cmd = cmd + '<param name="default_media"		value="'+this.filename+'" /> \n';
		cmd = cmd + '<param name="pre_buffer"	value="'+(this.video_buffer)+'%" /> \n';
		cmd = cmd + '<param name="playback"	value="auto_start" /> \n';
		cmd = cmd + '<param name="loop"	value="'+(this.loop?"true":"false")+'" /> \n';
		cmd = cmd + '<param name="controls" value="true" />\n';
		cmd = cmd + '<param name="control_location" value="'+this.icons+'" />\n';
		cmd = cmd + '<param name="cache" value="false" />\n';
		//cmd = cmd + '<param name="pre_screen"		value="posters/pre.gif" /> \n';
		cmd = cmd + '<param name="pre_screen_loop"	value="false" />\n';
		cmd = cmd + '<param name="post_screen"		value="false" /> \n';
		cmd = cmd + '<param name="post_screen_loop"	value="false" /> \n';
		cmd = cmd + '<param name="audio"	  		value="'+(this.audio_enabled?"true":"false")+'" /> \n';
		cmd = cmd + '<param name="smooth_video"		value="true" /> \n';
		cmd = cmd + '<param name="video_license"		value="false" /> \n';
		cmd = cmd +'<param name="allow_save"		value="false" /> \n';
		cmd = cmd + '</applet>\n';
		cmd = cmd + '</div>\n';
		cmd = cmd + '<div style="position:static; padding-top:3px; padding-left:1px; padding-bottom:3px; width:98%; font-weight:normal; font-size:0.8em; font-style:oblique; color:rgb(0,64,64);">\n';
		
		//cmd = cmd + '<div><input type="button" onclick="javascript:document.'+this.applet_name+'.playerplay();" value="Play" /> | <a href="javascript:document.'+this.applet_name+'.playerpause()">Pause</a> | <a href="javascript:document.'+this.applet_name+'.playerrewind()">Stop</a> | <a href="javascript:document.'+this.applet_name+'.playersetmute(true)">Mute</a> | <a href="javascript:document.'+this.applet_name+'.playersetmute(false)">Un-mute</a></div>';
		
		cmd = cmd + this.caption+' <a href="#" onclick=\'javascript:restartApplet("'+this.applet_name+'");\'>(if video fails to start, click *here*)</a>\n</div>\n';
		if (this.init_style!=1) {
			cmd = cmd + '</div> <!-- video -->\n';
			document.writeln (cmd);
		}
		else {
			document.getElementById(this.id).innerHTML=cmd;
		}
}


//************* video1_applet video scripts **************
// Variables	
//var monitor_started = 0;

// This function is called when MediaFrame finishes playback.  It is
// set to rewind the video in this case
function video_applet_stop(){
	setTimeout('document.video_applet.playerrewind()', 2500);
}

// This function is called when MediaFrame begins playback
function video_applet_start(){
}

// This function is called when MediFrame is ready to begin video
// playback
function video_applet_ready(){
	if(this.monitor_started == 0) {
		this.monitor_started = 1;
	}
}
/***************************************************/

function videoMPG (filename, audio_enabled, float_pos, caption, width, height, vid_id, low_res_url, auto_start, pre_screen_img, post_screen_img) {
	this.w = getAvailWidth();
	this.h = getAvailHeight();
	this.archive_param = "mediaframe-mpeg1.jar";
	this.code_param="mediaframe.mpeg1.MPEG1.class";
	this.icons = "http://raupplab.umd.edu/video/icons";
	this.audio_enabled = audio_enabled;
	this.filename = filename;
	this.float_pos = float_pos;
	this.caption = caption;
	this.loop = true;
	this.width = width;
	this.height = height;
	this.img_div_width = width;
	this.img_div_height = height;
	this.video_buffer = 25;
	this.low_res_url = low_res_url;
	this.auto_start = "AUTO_START";
	// OTHER VALUES: CLICK_TO_START  ROLLOVER_TO_START  NULL
	if (auto_start)
	    this.auto_start = auto_start;
	this.pre_screen = null;
	if (pre_screen_img)
	    this.pre_screen=pre_screen_img;
	this.post_screen = null;
	if (post_screen_img)
	    this.post_screen=post_screen_img;
	this.low_res_param = "128k_media";

	this.id = vid_id;
	this.vid_id = vid_id;
	this.applet_name = vid_id+"_applet";
	
	this.init_style = 0;
	this.initMPGVideo = initMPGVideo;
	this.initVideo = initMPGVideo;
	this.resizeVideo = resizeVideo;
	this.setImgDivSize = setImgDivSize;

	if (this.init_style==1) {
		var cmd  = cmd + '<div class="video_caption" id="'+this.id+'"\n';
			cmd = cmd + 'style = "position:relative; float:'+this.float_pos+'; width:'+(this.width)+'px; padding:5px; margin:10px; border:3px ridge rgb(0,128,0); z-index:10;"></div> \n\n';
	
	}
}

function setImgDivSize (width,height) {
    this.img_div_width = width;
    this.img_div_height = height;
}

function initMPGVideo () {
    var cmd = '<a name="'+this.applet_name+'"></a> \n';
    if (this.init_style!=1) {
	    cmd  = cmd + '<div id="'+this.id+'"\n';
	    cmd = cmd + 'style = "position:relative; float:'+this.float_pos+'; width:'+(this.width)+'px; padding:5px; margin:10px; border:3px ridge rgb(0,128,0); z-index:10;"> \n\n';
    }
    cmd = cmd + '<div id="'+this.id+'_2" style="position:relative; width:'+this.img_div_width+'px; height:'+this.img_div_height+'px"> \n';
    cmd = cmd+'<applet name="'+this.applet_name+'" code="'+this.code_param+'" archive="'+this.archive_param+'" width="'+this.width+'" height="'+this.height+'" mayscript="true">\n';
    cmd = cmd + '<param name="id" value="ID: '+this.filename+'" /> \n';
    cmd = cmd + '<param name="default_media"		value="'+this.filename+'" /> \n';
    if (this.low_res_url!=null && this.low_res_url)
	cmd = cmd + '<param name="'+this.low_res_param+'"    value="'+this.low_res_url+'" /> \n';
    cmd = cmd + '<param name="pre_buffer"	value="'+(this.video_buffer)+'%" /> \n';
    cmd = cmd + '<param name="playback"	value="'+this.auto_start+'" /> \n';
    cmd = cmd + '<param name="loop"	value="'+(this.loop?"true":"false")+'" /> \n';
    cmd = cmd + '<param name="control_location" value="'+this.icons+'" />\n';
    cmd = cmd + '<param name="controls" value="true" />\n';
    cmd = cmd + '<param name="cache" value="true" />\n';
    cmd = cmd + '<param name="pre_screen"		value="'+this.pre_screen+'" /> \n';
    cmd = cmd + '<param name="pre_screen_loop"	value="false" />\n';
    cmd = cmd + '<param name="post_screen"		value="'+this.post_screen+'" /> \n';
    cmd = cmd + '<param name="post_screen_loop"	value="false" /> \n';
    cmd = cmd + '<param name="audio"	  		value="'+(this.audio_enabled?"true":"false")+'" /> \n';
    cmd = cmd + '<param name="smooth_video"		value="true" /> \n';
    cmd = cmd + '<param name="video_license"		value="false" /> \n';
    cmd = cmd +'<param name="allow_save"		value="false" /> \n';
    cmd = cmd + '</applet>\n';
    cmd = cmd + '</div>\n';
    cmd = cmd + '<div style="position:static; padding-top:3px; padding-left:1px; padding-bottom:3px; width:98%; font-weight:normal; font-size:0.8em; font-style:oblique; color:rgb(0,64,64);">\n';
    //cmd = cmd + '<div><a href="javascript:document.'+this.applet_name+'.playerplay()">Play</a> | <a href="javascript:document.'+this.applet_name+'.playerpause()">Pause</a> | <a href="javascript:document.'+this.applet_name+'.playerrewind()">Stop</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="javascript:document.'+this.applet_name+'.playersetmute(true)">Mute</a> | <a href="javascript:document.'+this.applet_name+'.playersetmute(false)">Un-mute</a></div>';

    cmd = cmd + this.caption+' <a href="#" onclick=\'javascript:restartApplet("'+this.applet_name+'");\'>(if video fails to start, click *here*)</a>\n</div>\n';
    if (this.init_style!=1) {
	    cmd = cmd + '</div> <!-- video -->\n';
	    document.writeln (cmd);
    }
    else {
	    document.getElementById(this.id).innerHTML=cmd;
    }
}

function hideVideo () {
	
}

function restartApplet (applet_name) {
    window.location.href=window.location.href;
    /*
    var d = document.applet_name;
    if (d) {
    }
    */
}

function resizeVideo(set_new_width, set_new_height) {
	var new_width=(typeof set_new_width == "undefined"?this.width:set_new_width);
	var new_height=(typeof set_new_height == "undefined"?this.height:set_new_height);
	var d = document.getElementById(this.vid_id);
	var a = eval("document.applets."+this.applet_name);
	if (d && a) {
		d.style.width=(new_width)+"px";
		d.style.height=(new_height)+"px";
		a.width=(new_width)+"px";
		a.height=(new_height)+"px";
	}
}

//]]>

