var vidBox;
var _CurrentVideo = null;
var _browser = navigator.userAgent;
var isSafari = _browser.indexOf('Safari') > - 1 ? true : false;
var isMac = _browser.indexOf('Macintosh') > - 1 ? true : false;
var isIE = document.defaultView ? false : true;
var pcFF = isMac == false ? isIE ? false : true : false;
var safariINIT = false;
var ffPos = null;

var IEvers = isIE ? Number(_browser.substring(_browser.indexOf('MSIE ')+4,_browser.indexOf('MSIE ')+8)) : null;
var IE7 = isIE ? IEvers > 6 ? true : false : false;

isSafari ? pcFF = true : null;

function PlayVideo(vid,summaryHTML){
	
	_CurrentVideo = vid;
	
	if(isSafari == true || isMac == false) {
		//$('TEXT_1').style.display='none';
		//$('NewsHolder').style.display='none';
	}
	
	boxElem = $('VID-PLAYER');
	frElem = $('VID-FRAME');
	smElem = $('VID-SUMMARY');
	
	boxElem.style.visibility='hidden';
	boxElem.style.display='block';
	
	if(pcFF == false) {
		smElem.style.visibility='hidden';
	}
	if(summaryHTML != null) {
		var sHTML = unescape("" + summaryHTML);
	} else {
		var sHTML = null;
	}
	summaryHTML == 'null' ? sHTML = null : null;
	if(sHTML != null) {
		smElem.innerHTML = "";
		smElem.style.display = 'block';
		smElem.innerHTML = sHTML;
	} else {
		smElem.style.display = 'none';
		if(pcFF == false) {
			smElem.style.visibility='hidden';
		}
	}
		
	if(pcFF == false) {
		
		boxElem.style.width='484px';
		boxElem.style.height='330px';

		vidBox = new BlakBox(boxElem);
		
		if(sHTML != null) {
			vidBox.offset = [(-1 * smElem.offsetHeight),0];
		}
		
		boxElem.style.visibility='hidden';
		smElem.style.visibility='hidden';
		
		vidBox.Blak(BoxCallBack);
	} else {
		
		var tpElem = $('VID-TOP');
		var bmElem = $('VID-BTM');
		
		$('VID-TOP').style.display='block';
		$('VID-BTM').style.display='block';
		
		frElem.style.position='absolute';
		frElem.style.width= $clientWidth() + 'px';
		//frElem.style.height= $clientHeight() + 'px';
		frElem.style.height = window.innerHeight + 'px';
		frElem.style.top = $scrollTop() + 'px';
		frElem.style.left = $scrollLeft() + 'px';
		
		if(sHTML != null) {
			var smH = smElem.offsetHeight;
		} else {
			var smH = 0;
		}
		
		var vidOBJ = window.frames['VID-FRAME'].document.getElementById('VIDEO-HOLDER');
		
		vidOBJ.style.position='absolute';
		var eW = Number($clientWidth()) - 484;
		var eH = Number($clientHeight()) - 330;
		vidOBJ.style.top = (Math.floor(eH / 2) - smH) + 'px';
		vidOBJ.style.left = Math.floor(eW / 2) + 'px';
		
		tpElem.style.position='fixed';
		tpElem.style.top = (Math.floor(eH / 2) - (6 + smH)) + 'px';
		tpElem.style.left = Math.floor(eW / 2) + 'px';
		
		smElem.style.position='fixed';
		smElem.style.top = (Math.floor(eH / 2) + (330 - smH)) + 'px';
		smElem.style.left = Math.floor(eW / 2) + 'px';
		
		bmElem.style.position='fixed';
		bmElem.style.top = (Math.floor(eH / 2) + (330)) + 'px';
		bmElem.style.left = Math.floor(eW / 2) + 'px';
		
		window.frames['VID-FRAME'].DrawFlash(_CurrentVideo);
		
		boxElem.style.visibility='visible';
		frElem.style.visibility='visible';
		frElem.style.display='block';
		frElem.style.zIndex=2030;
		
		ffPos = setInterval(function(){
			frElem.style.width= $clientWidth() + 'px';
			//frElem.style.height= $clientHeight() + 'px';
			frElem.style.height = window.innerHeight + 'px';
			frElem.style.top = $scrollTop() + 'px';
			frElem.style.left = $scrollLeft() + 'px';
			
			var eW = Number($clientWidth()) - 484;
			var eH = Number($clientHeight()) - 330;
			vidOBJ.style.top = (Math.floor(eH / 2) - smH) + 'px';
			vidOBJ.style.left = Math.floor(eW / 2) + 'px';
			tpElem.style.top = (Math.floor(eH / 2) - (6 + smH)) + 'px';
			tpElem.style.left = Math.floor(eW / 2) + 'px';
			smElem.style.top = (Math.floor(eH / 2) + (330 - smH)) + 'px';
			smElem.style.left = Math.floor(eW / 2) + 'px';
			bmElem.style.top = (Math.floor(eH / 2) + (330)) + 'px';
			bmElem.style.left = Math.floor(eW / 2) + 'px';
		},20);
	}
}

function BoxCallBack() {
		
	boxElem = $('VID-PLAYER');
	frElem = $('VID-FRAME');
	smElem = $('VID-SUMMARY');
	
	if(isIE == false) {
		
		if(isSafari == true) {
			// Safari
			if(safariINIT == false) {
				safariINIT = true;
				window.frames['VID-FRAME'].DrawFlash(_CurrentVideo);
			} else {
				frElem.src="VideoPlayer.html";
			}
		} else {
			if(isMac == true) {
				// FireFoxMAC
				window.frames['VID-FRAME'].DrawFlash(_CurrentVideo);
			}
		}
		
		boxElem.style.visibility='visible';
		smElem.style.visibility='visible';
		var bod = window.frames['VID-FRAME'].document.getElementById('BOD');
		bod.className='NoBody';
		
	} else {
		// IE
		frames['VID-FRAME'].location.href="VideoPlayer.html";
		boxElem.style.visibility='visible';
		smElem.style.visibility='visible';
	}
}

function CloseVideo() {
	
	_CurrentVideo = null;
	
	if(pcFF == false) {
		if(isIE == true) {
			frames['VID-FRAME'].location.href="Blank.html";
		}
		vidBox.Close();
	} else {
		clearInterval(ffPos);
		$('VID-FRAME').style.visibility='hidden';
		$('VID-PLAYER').style.visibility='hidden';
		
		$('VID-TOP').style.display='none';
		$('VID-BTM').style.display='none';
		
		window.frames['VID-FRAME'].location.href="VideoPlayer.html";
	}
	
	//$('NewsHolder').style.display='block';
	//$('TEXT_1').style.display='block';
}
