var JWPFolder = "/jwplayer/"
var SWFPlayerFilename = "player-viral.swf";
var JWPTemplate = "jwpTemplate.html";

function JWPInit(){
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
	flvFilename = qsParm['file'];
	writeSWFcode(flvFilename, "100%", "100%");
}


function jwpPopup (filename, width, height){
	rnum = (Math.round((Math.random()*1000000)+1));
	padControls = height+20;
	theURL = JWPFolder + JWPTemplate + '?file='+filename;
	winName = 'Player'+rnum;
	extras = 'width='+width+',height='+padControls;
	window.open(theURL,winName,extras);
}


function writeSWFcode(flvFilename, theWidth, theHeight){
	rnum = (Math.round((Math.random()*1000000)+1));
	flashCode = '';
	flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab// - version=7,0,0,0" width="'+theWidth+'" height="'+theHeight+'" name="jwp'+rnum+'" id="jwp'+rnum+'">';
	flashCode += '	<param name="movie" value="'+ SWFPlayerFilename +'" />';
	flashCode += '	<param name="allowfullscreen" value="true" />';
	flashCode += '	<param name="allowscriptaccess" value="always" />';
	flashCode += '	<param name="flashvars" value="file=' + flvFilename +'&autostart=true" />';
	flashCode += '	<embed';
	flashCode += '		type="application/x-shockwave-flash"';
	flashCode += '		id="jwp'+rnum+'"';
	flashCode += '		name="jwp'+rnum+'"';
	flashCode += '		src="'+ SWFPlayerFilename +'"';
	flashCode += '		width="'+theWidth+'"';
	flashCode += '		height="'+theHeight+'"';
	flashCode += '		allowscriptaccess="always"';
	flashCode += '		allowfullscreen="true"';
	flashCode += '		flashvars="file=' + flvFilename +'&autostart=true"';
	flashCode += '	/>';
	flashCode += '</object>';
	document.write(flashCode);
}

