var realmoviewidth;

function showmovie(container, controlscontainer, src, moviewidth) {
	var w = moviewidth || 320; //$(container).width();
	realmoviewidth = w;
	var h = 260; //$(container).height();
	var out = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '+
	'width="' + w+ 'px" height="' + h+ 'px" '+
	'codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" id="player1">'+
	'<param name="kioskmode" value="true">' +
	'<param name="controller" value="true">'+
	'<param name="controller" value="true">'+ 
	'<param name="type" value="video/quicktime">'+
	'<param name="autoplay" value="false">'+
	'<param name="target" value="myself">'+
	'<param name="enablejavascript" value="true">'+
	'<param name="scale" value="aspect">'+
	'<param name="bgcolor" value="#000000">'+
	'<param name="src" value="' + src + '">'+
	'<param name="loop" value="false">'+
	'<param name="pluginspage" value="http://www.apple.com/quicktime/download/indext.html">'+
	'<embed type="video/quicktime" bgcolor="#000000" border="0" '+
	'pluginspage="http://www.apple.com/quicktime/download/indext.html" '+
	'src="' + src + '" '+
	'kioskmode="true" ' +
	'controller="true" '+
	'autoplay="false" '+
	'enablejavascript="true" '+
	'scale="aspect" '+
	'bgcolor="#000000" '+
	'loop="false" '+
	'style="width:' + w + 'px;height:' + h + 'px;" '+
	'name="player1"></embed></object>';
	document.write(out);
	$(document).ready(function(){
		/*
		$(controlscontainer).html('<div id="playcontrol" style="float:left;width:30px;"><a href="#" onclick="playToggle(); return false;"><img src="/images/movie_pause.jpg" style="border:0px;"></a></div><div style="padding:8px 0px 0px 10px;"><div id="outerbar"><div id="playbar" style="height:7px;width:513px;border:1px solid #C9C9C9;overflow-x:hidden;font-size:0.1em;"><div id="progress" style="height:7px;width:0%;background-color: #CCCCCC;float:left;"></div><div id="loaded" style="float:left;height:7px;width:0%;background-color: #eeeeee;"></div></div></div></div><div id="timecode" style="text-align:right;">0:00:00</div>');

		window.setInterval(function(){
			try{
				if(document.player1) {
					document.player1.GetMaxTimeLoaded()
					var playpct = Math.ceil(100 * document.player1.GetTime() / document.player1.GetDuration());
					var loadpct = Math.ceil(100 * document.player1.GetMaxTimeLoaded() / document.player1.GetDuration()) - playpct;
					$('#loaded').css('width', loadpct + '%');
					$('#progress').css('width', playpct + '%');
					var seconds = Math.floor(document.player1.GetTime() / document.player1.GetTimeScale());
					minutes = Math.floor(seconds / 60);
					hours = Math.floor(minutes / 60);
					minutes = minutes % 60;
					seconds = seconds % 60;
					$('#timecode').html(hours + ':' + two(minutes) + ':' + two(seconds));
				}
			}
			catch(e){}
		},1000);
		*/
	});
}


function createMovie(container, controlscontainer, src, moviewidth) {
	var w = moviewidth || 320; //$(container).width();
	realmoviewidth = w;
	var h = 260; //$(container).height();
	var out = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '+
	'width="' + w+ 'px" height="' + h+ 'px" '+
	'codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0" id="player1">'+
	'<param name="kioskmode" value="true">' +
	'<param name="controller" value="true">'+
	'<param name="controller" value="true">'+ 
	'<param name="type" value="video/quicktime">'+
	'<param name="autoplay" value="false">'+
	'<param name="target" value="myself">'+
	'<param name="enablejavascript" value="true">'+
	'<param name="scale" value="aspect">'+
	'<param name="bgcolor" value="#000000">'+
	'<param name="src" value="' + src + '">'+
	'<param name="loop" value="false">'+
	'<param name="pluginspage" value="http://www.apple.com/quicktime/download/indext.html">'+
	'<embed type="video/quicktime" bgcolor="#000000" border="0" '+
	'pluginspage="http://www.apple.com/quicktime/download/indext.html" '+
	'src="' + src + '" '+
	'kioskmode="true" ' +
	'controller="true" '+
	'autoplay="false" '+
	'enablejavascript="true" '+
	'scale="aspect" '+
	'bgcolor="#000000" '+
	'loop="false" '+
	'style="width:' + w + 'px;height:' + h + 'px;" '+
	'name="player1"></embed></object>';
	
	return out;
}


function getPlayer(){
	if(document.player1.GetRate) return document.player1;
	if(document.player1.GetRate) return document.player1;
	if(document.player1.GetRate) return document.player1;
}

function two(digits){
	strint = '0' + digits;
	return strint.substr(strint.length-2, 2);
}
function playToggle(){
	window.setTimeout(doPlayToggle,500);
}

function doPlayToggle(){
	try{
		if(document.player1.GetRate() == 0) {
			// play
			if(getPlayer().GetTime() == document.player1.GetDuration()) {
				getPlayer().Rewind();
			}
			getPlayer().Play();
		}
		else {
			// pause
			getPlayer().SetRate(0);
		}
	}
	catch(e){
		window.setTimeout(doPlayToggle,500);
	}
}

function playMovie(){
	cancelRotate = true;
	try{
		// play
		if(document.player1.GetTime() == document.player1.GetDuration()) {
			document.player1.Rewind();
		}
		document.player1.Play();
	}
	catch(e){
		window.setTimeout(playMovie, 500);
	}
	//resizeMovie();
}

function resizeMovie() {
	try{
		rect = document.player1.GetRectangle();
		dims = rect.split(',');
		dimensions = '0,' + dims[1].toString() + ',' + (parseInt(dims[2]) - parseInt(dims[0])).toString() + ',' + dims[3].toString();
		$('#project_title').css({width:((parseInt(dims[2]) - parseInt(dims[0])).toString() - $('#project_link').width()) + 'px',marginRight:'0px'});
		document.player1.SetRectangle(dimensions);
		document.player1.SetBgColor('#000000');
	}
	catch(e){
		window.setTimeout(resizeMovie, 2000);
	}
}

function stopMovie(){
	try{
		// pause
		document.player1.SetRate(0);
	}
	catch(e){
		window.setTimeout(stopMovie, 500);
	}
}

