//***************************************
// FOR JW FLV PLAYER
	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;
	var swfObjsLoaded = false;
	var tmrPrototype;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
	function getUpdate(typ,pr1,pr2,pid) {

	if(typ == "time") { currentPosition = pr1; }
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
	};

	function thisMovie(movieName) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};

//***************************************

	function writeVideoObject(id, pic, flv, width, height){
		var file = flv;
		
		with(new SWFObject('/jwplayer/flvplayer.swf?preventCache=' + (new Date().valueOf()),id,width,height,'7')){
			addVariable('file',file);
			addVariable('image',pic);
			addVariable("javascriptid","_" + id);
			addVariable('height',height);
			addVariable('width',width);
			addVariable('displaywidth',width);
			addVariable('displayheight',height);
			addVariable('showvolume','true');
			//addVariable('enablejs','true'); //ENABLING THIS SEEMS TO CAUSE PROBLEMS IN IE
			addVariable('useaudio','false');
			addVariable('usecaptions','false');
			addVariable('usekeys','false');
			addVariable('autostart','true');
			addVariable("overstretch","fit");
			addParam('allowscriptaccess','always');
			addParam('allowfullscreen','true');
			
			addVariable('usefullscreen','false');
			addVariable('showdigits','false');
			
			//$(id).style.background= 'none';
			write(id);
		}
		
	}

	function addVideo(evt){
		var id, pic, flv, width, height;
		var srcElt = (window.event)?window.event.srcElement:Event.element(evt);
		id = srcElt.parentNode.id;
		pic = srcElt.getAttribute('img');
		flv = srcElt.getAttribute('url');
		width = srcElt.getAttribute('vidwidth');
		height = srcElt.getAttribute('vidheight');
		writeVideoObject(id, pic, flv, width, height);
	}

	function addVideos(){
		if(swfObjsLoaded) return;
		var intVideos = 0;
		var videoDivs = $$('.swfObj');
		videoDivs.each(
			function (item){
				intVideos++;
				var url = item.getAttribute('url');
				var img = item.getAttribute('img');
				var width = item.getAttribute('vidwidth');
				var height = item.getAttribute('vidheight');
				if(item.id=='') item.id = 'swfObj' + intVideos;
				
				item.style.background= 'url(/business/toughbook/img/video-loading-bg.gif) center no-repeat';
				item.innerHTML = '';
				
				// CREATE PREVIEW IMAGE
				var imgPreview = document.createElement('img');
				imgPreview.setAttribute('src',img);
				imgPreview.setAttribute('width',width);
				imgPreview.setAttribute('height',height);
				imgPreview.setAttribute('id','swfObjImg'+intVideos);
				item.appendChild(imgPreview);
				
				imgPreview = $('swfObjImg'+intVideos);
				with(imgPreview){
					style.width = width + 'px';
					style.height = height + 'px';
					style.cursor = 'pointer';
					setAttribute('img',img);
					setAttribute('url',url);
					setAttribute('vidwidth',width);
					setAttribute('vidheight',height);
					imgPreview.onclick = addVideo;
				}
				
			}
		);
	}
	
	function addFlashBanners(){
		var intBanners = 0;
		var bannerDivs = $$('.swfBanner');
		bannerDivs.each(
			function (item){
				intBanners++;
				var url = item.getAttribute('url');
				var width = item.getAttribute('bnrwidth');
				var height = item.getAttribute('bnrheight');
				if(item.id=='') item.id = 'swfBanner' + intBanners;
				writeFlashObject(item,url,width,height);
			}
		);
	}
	
	function writeAudioObject(id, url, width){
		var file = url;
				
		with(new SWFObject('/jwplayer/flvplayer.swf?preventCache=' + (new Date().valueOf()),id,width,20,'7')){
			addVariable('file',file);
			addVariable("javascriptid","_" + id);
			addVariable('height',20);
			addVariable('width',width);
			addVariable('displaywidth',width);
			addVariable('displayheight',0);
			addVariable('showvolume','true');
			//addVariable('enablejs','true'); //ENABLING THIS SEEMS TO CAUSE PROBLEMS IN IE
			addVariable('useaudio','false');
			addVariable('usecaptions','false');
			addVariable('usekeys','false');
			addVariable('autostart','true');
			addVariable('showicons','false');
			addVariable('thumbsinplaylist','false');
			addVariable('shuffle','false');
			
			addParam('allowscriptaccess','always');
			addParam('allowfullscreen','true');
			
			addVariable('usefullscreen','false');
			addVariable('showdigits','true');
			write(id);
		}
		
	}
	
function writeFlashObject(srcElement,url,width,height){
	var div = srcElement.parentNode;
	if(typeof(srcElement)=='string') srcElement = $(srcElement);
	var ret = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\""+url+"\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"transparent\"><embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\" type=\"application/x-shockwave-flash\"></embed></object>";
	
	// FOR MAC
	if(navigator.appVersion.indexOf("Mac")!=-1){
		ret = "<embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\"></embed>";
	}
	
	srcElement.innerHTML = ret;	
}

Event.observe(window,'load',function(){
	addVideos();
	addFlashBanners();
},false);