var cswf = Class.create({
	initialize: function(sFilename, oOptions) {
		this.filename  = sFilename;
		this.width = (oOptions.width != undefined)?oOptions.width:100;
		this.height = (oOptions.height != undefined)?oOptions.height:100;
		this.version = (oOptions.version != undefined)?oOptions.version:"6,0,29,0";
		this.bgcolor = (oOptions.bgcolor != undefined)?oOptions.bgcolor:"#FFFFFF";
		this.swf_id = (oOptions.swf_id != undefined)?oOptions.swf_id:"swf_" + Math.random();
		this.menu = (oOptions.menu != undefined)?oOptions.menu:"";
		this.flash_vars = (oOptions.flash_vars != undefined)?oOptions.flash_vars:"";
		this.quality = (oOptions.quality != undefined)?oOptions.quality:"high";
		this.allow_script_access = (oOptions.allow_script_access != undefined)?oOptions.allow_script_access:"always";
		this.wmode = (oOptions.wmode != undefined)?oOptions.wmode:"window";
		this.container = (oOptions.container != undefined)?oOptions.container:"";
	},
	
	playMovie: function() {
		var sMovie = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= ' + this.version + '" width=' + this.width + ' height=' + this.height + ' id=' + this.swf_id + '>\n';
		sMovie += '<param name="movie" value="' + this.filename + '" />\n';
		sMovie += '<param name= "allowScriptAccess" value="' + this.allow_script_access + '" />\n';
		sMovie += '<param name="quality" value="' + this.quality + '" />\n';
		sMovie += '<param name="FlashVars" value="' + this.flash_vars + '" />\n';
		sMovie += '<param name="bgcolor" value="' + this.bgcolor + '" />\n';
		sMovie += '<param name="menu" value="' + this.menu + '" />\n';
		sMovie += '<param name="wmode" value="' + this.wmode + '" />\n';
		sMovie += '<embed src="' + this.filename + '" bgcolor="' + this.bgcolor + '" FlashVars="' + this.flash_vars + '" menu="' + this.menu + '" allowScriptAccess="' + this.allow_script_access + '" quality="' + this.quality + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + this.width + '" height="' + this.height + '" swLiveConnect="true" name="' + this.swf_id + '" wmode="' + this.wmode + '"></embed>';
		sMovie += '</object>\n';
		
		if(this.container != ""){
			$(this.container).update(sMovie);
		}
		else{
			document.write(sMovie);
		}
	} 
});

function showSwf(sFilename, oOptions){
	var newSwf = new cswf(sFilename, oOptions);
	newSwf.playMovie();
}

var cqt = Class.create({
	initialize: function(sFilename, oOptions) {
		this.filename  = sFilename;
		this.classid = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
		this.mime_type = "video/quicktime";
		this.version = (oOptions.version != undefined)?oOptions.version:"6,0,2,0";
		this.codebase = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + this.version
		this.pluginspage = "http://www.apple.com/quicktime/download/";
		this.width = (oOptions.width != undefined)?oOptions.width:100;
		this.height = (oOptions.height != undefined)?oOptions.height:100;
		this.qt_id = (oOptions.qt_id != undefined)?oOptions.qt_id:"swf_" + Math.random();
		this.align = (oOptions.align != undefined)?oOptions.align:"left";
		this.scale = (oOptions.scale != undefined)?oOptions.scale:"1";
		this.autoplay = (oOptions.autoplay != undefined)?oOptions.autoplay:"true";
		this.container = (oOptions.container != undefined)?oOptions.container:"";
	},
	
	playMovie: function() {
		var sMovie = '<object classid="' + this.classid + '" codebase= "' + this.codebase + '" width="' + this.width + '" height="' + this.height + '" align="' + this.align + '" id="' + this.qt_id + '">\n';
		sMovie += '<param name="src" value="' + this.filename + '" />\n';
		sMovie += '<param name= "autoplay" value="' + this.autoplay + '" />\n';
		sMovie += '<param name="scale" value="' + this.scale + '" />\n';
		sMovie += '<embed src="' + this.filename + '" autoplay="' + this.autoplay + '" scale="' + this.scale + '" align="' + this.align + '" type="' + this.mime_type + '" pluginspage="' + this.pluginspage + '" width="' + this.width + '" height="' + this.height + '" />';
		sMovie += '</object>\n';
		
		if(this.container != ""){
			$(this.container).update(sMovie);
		}
		else{
			document.write(sMovie);
		}
	} 
});

function showQt(sFilename, oOptions){
	var newQt = new cqt(sFilename, oOptions);
	newQt.playMovie();
}

function playMovie(sFilename, oOptions){
	var aNewFileName = sFilename.split(".");
	openMovieWindow(sFilename, oOptions, aNewFileName[aNewFileName.length - 1]);
}

function openMovieWindow(sFilename, oOptions, sFiletype){
	
	var nWidth = (oOptions.width != undefined)?oOptions.width:350 + 40;
	var nHeight = (oOptions.height != undefined)?oOptions.height:250 + 40;
	var oPosition = getCentered(nWidth, nHeight);
	var sFeatures = 'toolbar=0,status=0,left=' + oPosition.left + ',top=' + oPosition.top + ',width=' + nWidth + ',height=' + nHeight;
	var hOptions = $H(oOptions);
	hOptions.unset('container');
	window.open('movies.php?src=' + sFilename + '&type=' + sFiletype + '&options=' + hOptions.toJSON(), 'play_movie', sFeatures);
}

function getCentered(nWidth, nHeight) {

	var nScreenX = window.screen.width;
	var nScreenY = window.screen.height;
	var nLeft = Math.round((nScreenX / 2)) - Math.round((nWidth / 2));
	var nTop = Math.round((nScreenY / 2)) - Math.round((nHeight / 2));
	
	return {left: nLeft, top: nTop};
}
