﻿/*

 Copyright (c) 2008 ViCon GmbH
 
 Usage:
 ======
 
 <script language="javascript" type="text/javascript" src="player.js"></script>
 <a href="openPlayer('MYMEDIA.SWF', 'MYWIDTH', 'MYHEIGHT');"
 
*/

// ~~~ fields ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var player = new Array(
	'<html>',
	'<head />',
	'<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">',
	'<object',
	'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"',
	'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"',
	'width="%WIDTH%"',
	'height="%HEIGHT%"',
	'>',
	'<param name="movie" value="%URI%" />',
	'<param name="play" value="true" />',
	'<param name="loop" value="true" />',
	'<param name="quality" value="best" />',
	'<param name="scale" value="exactfit">',
	'<embed',
	'src="%URI%"',
	'quality="low"',
	'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"',
	'type="application/x-shockwave-flash"',
	'width="%WIDTH%"',
	'height="%HEIGHT%"',
	'>',
	'</embed>',
	'</object>',
	'</body>',
	'</html>'
);

// ~~~ functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function openPlayer(myURI, myWidth, myHeight)
{
 var tw;	// target window
 var po;	// player object
 var w;		// width
 var h;		// height
 
	tw = window.open('', '', 'width=' + myWidth + ',height=' + myHeight + ',toolbar=no,status=no,scrollbars=no,resizable=yes,menubar=no,location=no');

	po = player.join(' ');
	po = po.replace(/%URI%/g, myURI);
	
	w = h = '100%';
	
	// all except ie
	if (window.innerWidth) {
		w = tw.innerWidth;
		h = tw.innerHeight;
	} 
	
	// ie >=6
	else if (document.documentElement && document.documentElement.clientHeight) {
		w = tw.document.documentElement.clientWidth;
		h = tw.document.documentElement.clientHeight;
	} 
	
	// other explorer versions
	else {
		w = tw.document.body.clientWidth;
		h = tw.document.body.clientHeight;
	}
	
	po = po.replace(/%WIDTH%/g, w);
	po = po.replace(/%HEIGHT%/g, h);

	tw.document.open();
	tw.document.write(po);
	tw.document.close();
}

