function Player(url, autoplay, width, height, barDifference) {	
	
	this.url = url;
	this.autoplay = autoplay;
	this.width = width;
	this.height = height;
	this.shift = "";	

	
	
	BrowserDetect.init();
	this.defaultPlayer = false;
	
	if (BrowserDetect.OS == "Mac") {
		this.defaultPlayer = true; 
		if (BrowserDetect.browser == "Safari" && BrowserDetect.version >= 1.3) {
			this.defaultPlayer = false; 
		}
		if (BrowserDetect.browser == "Firefox" && BrowserDetect.version >= 1) {
			this.defaultPlayer = false; 
		}		
	}
	if (BrowserDetect.OS == "Windows") {
		if (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 6) {
			this.defaultPlayer = true;
		}	
	}

	if (!this.isQTInstalled()){
		this.createNoPlayer();
	} else {
		this.createPlayer();
		
		if (this.defaultPlayer == false) {	
			
			this.barDifference = barDifference;
			this.loadbarWidth = this.width - this.barDifference;	
			this.playerInterval;
			
			this.playStatus = "stop";
			if (this.autoplay == "true") { this.playStatus = "play"; }
			
			this.createControls();
			
			this.loadBar = document.getElementById("load-bar");
			this.playHead = document.getElementById("handle");
			this.playBtn = document.getElementById("playBtn");
			this.playBtnImg = document.getElementById("playBtnImg");
			this.stopBtnImg = document.getElementById("stopBtnImg");
		
			this.setPlayerInterval();
		
		}
	}

}

Player.prototype.createPlayer = function () {
	document.write('<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"');
	document.write('codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="480" height="' + this.height + '" id="movie1" >');
	document.write('<PARAM name="src" value="' + this.url + '">');
	document.write("<PARAM name=\"autoplay\" value=\"" + this.autoplay + "\">");
	document.write('<PARAM name="controller" value="' + this.defaultPlayer + '">');
	document.write('<PARAM name="pluginspage" value="http://www.apple.com/quicktime/download/">');
	document.write('<EMBED width="480" height="' + this.height + '"');
	document.write('	src="' + this.url + '"');
	document.write('	name="movie1"');
	document.write('	enablejavascript="true"');
	document.write("	autoplay=\"" + this.autoplay + "\"");
	document.write('	controller="' + this.defaultPlayer + '"');
	document.write('	bgcolor="000000"');
	document.write('	pluginspage="http://www.apple.com/quicktime/download/">');
	document.write('</EMBED>');				
	document.write('</OBJECT>');
}

Player.prototype.createControls = function () {
	document.write('<div id="controls">');
	document.write('	<div class="btn"><a href="#" id="rwdBtn" onmousedown="p.btnRwd()" onmouseup="p.clearShift()"><img src="img/player/rwd.gif" alt="Rewind" id="rwdBtnImg" width="15" height="15"/></a></div>');
	document.write('	<div class="btn"><a href="#" class="btn" id="playBtn" onclick="p.btnPlay()"><img src="img/player/play.gif" alt="Play" id="playBtnImg" width="15" height="15"/></a></div>');
	document.write('	<div class="btn"><a href="#" class="btn" id="ffBtn" onmousedown="p.btnFF()" onmouseup="p.clearShift()"><img src="img/player/ff.gif" alt="Forward" id="ffBtnImg" width="15" height="15"/></a></div>');
	document.write('	<div class="btn"><a href="#" class="btn" id="stopBtn" onclick="p.stopPlay()"><img src="img/player/stop.gif" alt="Stop" id="stopBtnImg" width="15" height="15"/></a></div>');	
	document.write('	<div id="time-line" style="width:393px">');
	document.write('		<form onsubmit="return false;">');
	document.write('			<div class="slider" id="slider-1" tabIndex="1">');
	document.write('				<input class="slider-input" id="slider-input-1"/>');
	document.write('			</div>');
	document.write('			<div id="load-line"><div id="load-bar" style="width:375px"></div></div>');
	document.write('		</form>');
								
	var sliderEl = document.getElementById ? document.getElementById("slider-1") : null;
	var inputEl = document.forms[0]["slider-input-1"];
	s = new Slider(sliderEl, inputEl);
	s.setMaximum(this.width);
	s.setValue(0);
								
	document.write('	</div>');
	document.write('<div class="clear"></div>');
	document.write('</div>');
	document.write('<div id="controls-btm"></div>');
}

Player.prototype.createNoPlayer = function () {
	document.write('<div id="no-qt">');
	document.write('	<img src="img/player/qtlogo.gif" alt="" />');
	document.write('	QuickTime is required to view video clips. <a href="http://www.apple.com/quicktime/download/" target="_blank">Click here</a> to download.');
	document.write('</div>');
}


Player.prototype.isQTInstalled = function() {
	var qtInstalled = false;
	qtObj = false;
	if (navigator.plugins && navigator.plugins.length) {
		for (var i=0; i < navigator.plugins.length; i++ ) {
         var plugin = navigator.plugins[i];
         if (plugin.name.indexOf("QuickTime") > -1) {
			qtInstalled = true;
         }
      }
	} else {
		execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))','VBScript');
		qtInstalled = qtObj;
	}
	return qtInstalled;
}


Player.prototype.updatePlayer = function() {
	this.movie = document.movie1;
	this.duration = parseInt(this.movie.GetDuration());	
	
	var loadPercentage = parseInt(this.movie.GetMaxTimeLoaded()/this.duration*100);
	var currentPos = parseInt(this.movie.GetTime());
	var playPerc = parseInt(currentPos/this.duration*100);
	
	
	this.shiftPlay();
	this.setButtonStates();	
	
	

	this.loadBar.style.width = parseInt((this.loadbarWidth / 100) * loadPercentage) + "px";	
	s.setValue (parseInt((this.width / 100) * playPerc));	

	
	if (currentPos >= this.duration) { this.stopPlay(); }
	
}

Player.prototype.setButtonStates = function() {
	if (this.playStatus == "stop") {		
		this.playBtnImg.style.visibility = "visible";
		this.stopBtnImg.style.visibility = "hidden";
				
	}	
	else if (this.playStatus == "play") {		
		this.playBtnImg.style.visibility = "hidden";	
		this.stopBtnImg.style.visibility = "visible";
				
	}
}


Player.prototype.setPlayerInterval = function() {
	//alertSpan (this + "[setPlayerInterval]");
	this.playerInterval = window.setInterval("p.updatePlayer()",100);
}

Player.prototype.clearPlayerInterval = function() {
	//alertSpan (this + "[clearPlayerInterval]");
	clearInterval(this.playerInterval);	
}

Player.prototype.playAt = function(playPerc) { 
	var pos = parseInt((this.duration / 100) * playPerc);
	//alertSpan ("playAt = " + pos);
	this.movie.SetTime(pos);	
	this.setPlayerInterval();
}


Player.prototype.stopPlay = function() {
	this.playBtnImg.src = "img/player/play.gif";
	if (this.playStatus == "pause") { 
		this.playBtnImg.style.visibility = "hidden";
		this.playBtnImg.src = "img/player/play.gif";				 
	};	
	this.playStatus = "stop";
	this.movie.Stop();
	this.movie.SetTime(0);	
}


Player.prototype.shiftPlay = function () {	
	if (this.playStatus != "stop" && this.shift != "") {			
		var shiftAmount = 300;		
		this.movie.Stop();		
		if (this.shift == "rwd") {
			shiftAmount = -300;
		}
		var currentPos = parseInt(this.movie.GetTime());
		currentPos += shiftAmount;
		this.movie.SetTime(currentPos);
	}
}

Player.prototype.clearShift = function () {
	this.shift = "";
	if (this.playStatus == "play") {	
		this.movie.Play();
	}
}

Player.prototype.btnRwd = function () {
	this.shift = "rwd";
}

Player.prototype.btnFF = function () {
	this.shift = "ff";	
}


Player.prototype.btnPlay = function () {
	this.shift = "";
	if (this.playStatus == "play") {
		this.playStatus = "pause";
		this.movie.Stop();		
		this.playBtnImg.src = "img/player/pause-over.gif";
		this.playBtnImg.style.visibility = "visible";
	}
	else{ 
		this.playStatus = "play";
		this.movie.Play();	
	}
}

Player.prototype.getBarDifference = function() {
	return this.barDifference;	
}

Player.prototype.getWidth = function() {
	return this.width;	
}

/*function alertSpan(alertText) {
	var alertSpan = document.getElementById("alert");
	alertSpan.innerHTML = alertText;
}*/
