
// Flash player write
function flash_write(url, w, h, id, fullScreen) {
	var id = id ? id : "flashDefaultID";
	var fullScreen = fullScreen ? fullScreen : false;
	var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="'+id+'" width="'+w+'" height="'+h+'" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">';
	str += '<param name="allowScriptAccess" value="always" />';//sameDomain
	str += '<param name="wmode" value="transparent" />';
	str += '<param name="movie" value="'+url+'" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="allowFullScreen" value="'+fullScreen+'">';
	str += '<embed src="'+url+'" quality="high" width="'+w+'" height="'+h+'" id="'+id+'" name="'+id+'" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>';
	str += '</object>';
	return str;
}

// Flash player show
function flash_show(url, w, h, id, fullScreen) {
	var id = id ? id : "flashDefaultID";
	var fullScreen = fullScreen ? fullScreen : false;
	document.write(flash_write(url, w, h, id, fullScreen));
}

// Sitemap, add/del
function flash_add(url, w, h, flashID, tableID) {
	var tag_swf = "";
	tag_swf = flash_write(url, w, h, flashID);
	var obj_chk = document.getElementById(flashID);

	if (obj_chk == null) {
		document.getElementById(tableID).innerHTML = tag_swf;
	} else {
		document.getElementById(tableID).removeChild(obj_chk);
	}
}

// ResizeWin
function resizeWin(maxX, maxY, speed, delay, win) {
	this.obj = "resizeWin"+(resizeWin.count++);
	eval(this.obj+"=this");
	if (!win) {
		this.win = self;
	} else {
		this.win = eval(win);
	}
	if (!maxX) {
		this.maxX = 5;
	} else {
		this.maxX = maxX;
	}
	if (!maxY) {
		this.maxY = 5;
	} else {
		this.maxY = maxY;
	}
	if (!speed) {
		this.speed = 1/3;
	} else {
		this.speed = 1/speed;
	}
	if (!delay) {
		this.delay = 0;
	} else {
		this.delay = delay;
	}
	this.doResize = (document.all || document.getElementById);
	this.stayCentered = false;

	this.initWin = function() {
		if (this.doResize) {
			this.resizeMe();
		} else {
			this.win.resizeTo(this.maxX,this.maxY);
		}
	};

	this.resizeMe = function() {
		this.win.focus();
		this.updateMe();
	};

	this.resizeTo = function(x, y) {
		this.maxX = x;
		this.maxY = y;
		this.resizeMe();
	};

	this.stayCentered = function() {
		this.stayCentered = true;
	};

	this.updateMe = function() {
		this.resizing = true;
		var x = Math.ceil((this.maxX-this.getX())*this.speed);
		var y = Math.ceil((this.maxY-this.getY())*this.speed);
		if (x == 0 && this.getX() != this.maxX) {
			if (this.getX()>this.maxX) {
				x = -1;
			} else {
				x = 1;
			}
		}
		if (y == 0 && this.getY() != this.maxY) {
			if (this.getY()>this.maxY) {
				y = -1;
			} else {
				y = 1;
			}
		}
		if (x == 0 && y == 0) {
			this.resizing = false;
		} else {
			this.win.top.resizeBy(parseInt(x),parseInt(y));
			if (this.stayCentered == true) {
				this.win.moveTo((screen.width-this.getX())/2,(screen.height-this.getY()-50)/2);
			}
			setTimeout(this.obj+'.updateMe()',this.delay);
		}
	};

	this.write = function(text) {
		if (document.all && this.win.document.all["coords"]) {
			this.win.document.all["coords"].innerHTML = text;
		} else if (document.getElementById && this.win.document.getElementById("coords")) {
			this.win.document.getElementById("coords").innerHTML = text;
		}
	};

	this.getX = function() {
		if (document.all) {
			return (this.win.top.document.body.clientWidth+10);
		} else if (document.getElementById) {
			return this.win.top.outerWidth;
		} else {
			return this.win.top.outerWidth-12;
		}
	};

	this.getY = function() {
		if (document.all) {
			return (this.win.top.document.body.clientHeight+29);
		} else if (document.getElementById) {
			return this.win.top.outerHeight;
		} else {
			return this.win.top.outerHeight-31;
		}
	};

	this.onResize = function() {
		if (this.doResize) {
			if (!this.resizing) {
				this.resizeMe();
			}
		}
	};

	return this;
}
resizeWin.count = 0;

// Windows Media player
function embedMediaPlayer( mediaUrl, showControls, autoPlay, loop, autoSize, width, height, mediaObjectId )
{
	var showControlsValue = (true == showControls) ? "true" : "false";
	var autoPlayValue = (true == autoPlay) ? "true" : "false";
	var autoSizeValue = (true == autoSize) ? "true" : "false";

	var str = "<object";
	str += ( "" == mediaObjectId ) ? "" : " id=\"" + mediaObjectId + "\"";
	str += ( "" == width || true == autoSize ) ? "" : " width=\"" + width + "\"";
	str += ( "" == height || true == autoSize ) ? "" : " height=\"" + height + "\"";
	str += " classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\">";
	str += "<param name=\"FileName\" value=\"" + mediaUrl + "\">";
	str += "<param name=\"AutoStart\" value=\"" + autoPlayValue + "\">";
	str += "<param name=\"ShowTracker\" value=\"" + showControlsValue + "\">";
	str += "<param name=\"ShowControls\" value=\"" + showControlsValue + "\">";
	str += "<param name=\"ShowGotoBar\" value=\"false\">";
	str += "<param name=\"ShowDisplay\" value=\"false\">";
	str += "<param name=\"ShowStatusBar\" value=\"" + showControlsValue + "\">";
	str += "<param name=\"AutoSize\" value=\"" + autoSizeValue + "\">";
	str += (false == loop) ? "" : "<param name=\"PlayCount\" value=\"0\">";
	str += "<embed";
	str += ( "" == width || true == autoSize ) ? "" : " width=\"" + width + "\"";
	str += ( "" == height || true == autoSize ) ? "" : " height=\"" + height + "\"";
	str += ( false == loop ) ? "" : " PlayCount=\"0\"";
	str += " src=\"" + mediaUrl + "\" AutoStart=\"" + autoPlayValue + "\" ShowTracker=\"" + showControlsValue + "\" ShowControls=\"" + showControlsValue + "\" ShowGotoBar=\"false\" ShowDisplay=\"false\" ShowStatusBar=\"" + showControlsValue + "\" AutoSize=\"" + autoSizeValue + "\" pluginspage=\"http://www.microsoft.com/windows/windowsmedia/download/\"></embed>";
	str += "</object>";

	document.write( str );
}

