var WMVolBarPosition = 0;
var WMSliderPosition = 0;
var WMPlyBtnState = true;
var WMPauseBtnState = false;
var WMStopBtnState = false;
var WMVidVisible = true;
var WMVidPlaying = false; //set to true once a video is played, used for the browse/video buttons
var wmVidPlayrRelatedURL = "";
var Timeout_id = "";
var NumericPositionID = "";
var adCheckTimer = "";
var WMQueryString = window.location.search.substring(1);
var wmaMuteStatus = false;
var WMVolBar, WMSlider, WMTimeDisplay, WMMuteBtn, WMPlayBtn, WMStopBtn, WMPauseBtn,WMNavImage, WMNavContent, WMVidContent;
var wmMediaBrowserSupportsActiveX = detectWMPSupport();

// _____________________________________________________________ WebMonkey code
/*
WM_setCookie(), WM_readCookie(), WM_killCookie()
A set of functions that eases the pain of using cookies.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
*/

// This next little bit of code tests whether the user accepts cookies.
function WM_browserAcceptsCookies() {
	var WM_acceptsCookies = false;
	if ( document.cookie == '' ) {
		document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
		if ( document.cookie.indexOf( 'WM_acceptsCookies=yes' ) != -1 ) {
			WM_acceptsCookies = true;
		} // If it succeeds, set variable
	} else { // there was already a cookie
		WM_acceptsCookies = true;
	}
	
	return ( WM_acceptsCookies );
}

function WM_readCookie( name ) {
	if ( document.cookie == '' ) { // there's no cookie, so go no further
	    return false;
	} else { // there is a cookie
	    var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if ( (firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=') ) { // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if (lastChar == -1) lastChar = theBigCookie.length;
			return unescape( theBigCookie.substring(firstChar, lastChar) );
		} else { // If there was no cookie of that name, return false.
			return false;
		}
	}	
}

function wmSetVidPlyrInitialize() {
	wmSetVidPlyrObj();
		if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX && document.wmVidPlayer.controls) {
			NumericPositionID = window.setInterval("WMObjTimeDisplay(WMgetTimePositionStr())",1000);
		}
}

function wmUnloadVidComponents(){
	window.clearInterval(NumericPositionID);
	window.clearTimeout(adCheckTimer);
}

function WMVolume(direction) {
	if (direction == 'up') {
		WMincVolume();
	} else {
		WMdecVolume();
	}
WMChangeObjVolBar(direction);

Timeout_id = window.setTimeout("WMVolume('"+ direction +"')", 500);
}

function wmGetVidPlyrObj(name)
{
  if (document.getElementById)
  {
  	if (document.getElementById(name)) {
  		this.obj = document.getElementById(name);
	}
  }
}		

function wmSetVidPlyrObj() {
	//initializes player control objects
	WMVolBar = new wmGetVidPlyrObj('volBar');
	WMSlider = new wmGetVidPlyrObj('slider');
	WMTimeDisplay = new wmGetVidPlyrObj('time');
	WMMuteBtn = new wmGetVidPlyrObj('mute');
	WMPlayBtn = new wmGetVidPlyrObj('play');
	WMStopBtn = new wmGetVidPlyrObj('stop');
	WMPauseBtn = new wmGetVidPlyrObj('pause');
}


function wmSetVidPlyrFfwRwdClr() {
	if (!WMPauseBtnState && !WMStopBtnState) { 
		WMChangeObjControlBtn(1);
	}
}

function WMChangeObjControlBtn(WMPlayPosition, triggerEvent) {
	if (WMStopBtn.obj && WMPlayBtn.obj && WMPauseBtn.obj) {
		switch ( WMPlayPosition ) {
			case 1: //show play state
				WMStopBtn.obj.style.backgroundPosition = "-256px -3px";
				WMPlayBtn.obj.style.backgroundPosition = "-294px 0";
				WMPauseBtn.obj.style.backgroundPosition = "-340px -3px";
                WMPlyBtnState = true;
				WMPauseBtnState = false;
				WMStopBtnState = false; 
				if (!triggerEvent) {
                	WMstartVideo();
                }
				break;
			case 2: //show pause state
				if (WMPlyBtnState) { 
				WMStopBtn.obj.style.backgroundPosition = "-129px -3px";
				WMPlayBtn.obj.style.backgroundPosition = "-167px 0";
				WMPauseBtn.obj.style.backgroundPosition = "-213px -3px";
				WMPauseBtnState = true;
				WMStopBtnState = false; 
                WMpauseVideo();
                }
				break;
			case 3: //show stop state
				WMStopBtn.obj.style.backgroundPosition = "-2 -3px";
				WMPlayBtn.obj.style.backgroundPosition = "-40px 0";
				WMPauseBtn.obj.style.backgroundPosition = "-86px -3px";
                WMPlyBtnState = false;
				WMPauseBtnState = false;
				WMStopBtnState = true; 
                WMstopVideo();
				break;
			default:
				WMStopBtn.obj.style.backgroundPosition = "-256px -3px";
				WMPlayBtn.obj.style.backgroundPosition = "-294px 0";
				WMPauseBtn.obj.style.backgroundPosition = "-340px -3px";
                WMPlyBtnState = true;
				WMPauseBtnState = false;
				WMStopBtnState = false; 
                WMstartVideo();
		}
	}
}

function WMChangeObj(img, map, url) {
	if (WMNavContent.obj) {
		if (WMNavContent.obj.src) {
				if (url == "" ) {
					WMNavContent.obj.src = wmVidPlayrRelatedURL;
				} else {
					WMNavContent.obj.src = url;
				}
		}
	}
	if (WMNavImage.obj) {
		if (WMNavImage.obj.useMap) {	
			WMNavImage.obj.useMap = '#'+map;
		}
		if (WMNavImage.obj.src) {	
			WMNavImage.obj.src = img;
		}
	}
}

function WMMoveObjSlider(val) {
	//var percentValue;
	if (WMSlider && WMSlider.obj) {
	//percentValue = 184- (Math.round((184 * val)/ 100));

		//WMSlider.obj.style.backgroundPosition = "-"+percentValue+"px 0";
		document.getElementById('progBar').width = Math.round((184 * val)/ 100);
	}
}

function WMObjTimeDisplay(val) {
	if (WMTimeDisplay.obj.innerHTML) {
		if (val) {
			WMTimeDisplay.obj.innerHTML = val;
		} else {
			WMTimeDisplay.obj.innerHTML = "00:00";
			document.getElementById('progBar').width = "1";			
		}
	}
	
	if (WMgetVideoDurationInt() && WMgetTimePositionInt()) {
		WMMoveObjSlider(Math.round((WMgetTimePositionInt() / WMgetVideoDurationInt()) * 100));
	}

}

function WMChangeObjVolBar(direction,value) {

		if (direction == "up" && WMVolBarPosition < 7) {
			WMVolBarPosition++;
		} else if (direction == "down" && WMVolBarPosition > -5) {
			WMVolBarPosition--;		
		}
		
		if (WMVolBarPosition <= 12 && direction != "mute") {
			switch ( WMVolBarPosition ) {
			case -5:
				WMVolBar.obj.style.backgroundPosition = "-71px 0";	
				break;
			case -4:
				WMVolBar.obj.style.backgroundPosition = "-65px 0";	
				break;
			case -3:
				WMVolBar.obj.style.backgroundPosition = "-59px 0";	
				break;
			case -2:
				WMVolBar.obj.style.backgroundPosition = "-53px 0";	
				break;
			case -1:
				WMVolBar.obj.style.backgroundPosition = "-47px 0";	
				break;
			case 0:
				WMVolBar.obj.style.backgroundPosition = "-41px 0";	
				break;
			case 1:
				WMVolBar.obj.style.backgroundPosition = "-35px 0";	
				break;
			case 2:
				WMVolBar.obj.style.backgroundPosition = "-29px 0";	
				break;
			case 3:
				WMVolBar.obj.style.backgroundPosition = "-23px 0";	
				break;
			case 4:
				WMVolBar.obj.style.backgroundPosition = "-17px 0";	
				break;
			case 5:
				WMVolBar.obj.style.backgroundPosition = "-11px 0";	
				break;
			case 6:
				WMVolBar.obj.style.backgroundPosition = "-5px 0";	
				break;
			case 7:
				WMVolBar.obj.style.backgroundPosition = "0 0";	
				break;
			default:
				WMVolBar.obj.style.backgroundPosition = "-41px 0";	
			}
		}
			//whenever the volume buttons are hit, the player will be unmuted, this just ensures that the image display is correct
			WMMuteBtn.obj.style.backgroundPosition = "-69px 0";		

}


// -- Windows Media Video Control javascript


function WMdisplayVideo (vid,width,height,args) {
var wmVideoPlayerString = "";
     
	if ( vid.charAt( 0 ) == '/' ) { 
    	vid = "http://" + location.host + vid;
	}      


    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {

      wmVideoPlayerString += '<OBJECT ID="wmVidPlayer" height="'+height+'" width="'+width+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" MAYSCRIPT>';
      wmVideoPlayerString += '  <PARAM name="URL" value="'+vid+'"/>';
      wmVideoPlayerString += '  <PARAM NAME="uiMode" VALUE="none"/>';
      wmVideoPlayerString += '  <PARAM NAME="enableContextMenu" value="false" />';
      wmVideoPlayerString += '  <param name="windowlessVideo" value="false"/>';      
      wmVideoPlayerString += '</OBJECT>';
      wmVideoPlayerString += '<ul id="wmVdPlyrControls">';
      wmVideoPlayerString += '<li id="rewind"><a href="#" onmousedown="WMfastReverseVideo();" onmouseup="WMChangeObjControlBtn(1);this.blur();" onmouseout="wmSetVidPlyrFfwRwdClr();this.blur();" onclick="return false;"></a></li>';
      wmVideoPlayerString += '<li id="return"><a href="#" onclick="WMstartVideo(vid);return false;"></a></li>';
      wmVideoPlayerString += '<li id="ffw"><a href="#" onmousedown="WMfastForwardVideo();" onmouseup="WMChangeObjControlBtn(1);this.blur();" onmouseout="wmSetVidPlyrFfwRwdClr();this.blur();" onclick="return false;"></a></li>';
      wmVideoPlayerString += '<li id="stop"><a href="#" onclick="WMChangeObjControlBtn(3);return false;"></a></li>';
      wmVideoPlayerString += '<li id="play"><a href="#" onclick="WMChangeObjControlBtn(1);return false;"></a></li>';
      wmVideoPlayerString += '<li id="pause"><a href="#" onclick="WMChangeObjControlBtn(2);return false;"></a></li>';
      wmVideoPlayerString += '<li id="mute"><a href="#" onclick="WMtoggleMuteValue();return false;"></a></li>';
      wmVideoPlayerString += '<li id="slider"><img src="controls2/progress_bar.gif" border="0" width="1" height="6" id="progBar"></li>';
	  wmVideoPlayerString += '<li id="divName"></li>';
	  wmVideoPlayerString += '<li id="divState"></li>';
      wmVideoPlayerString += '<li id="time">00:00</li>';
      wmVideoPlayerString += '<li id="volBar"><img src="controls2/soundbars_overlay.gif" width="71" height="16" alt="" border="0" /></li>';	
      wmVideoPlayerString += '<li id="vol_down"><a href="#" onmousedown="WMVolume(\'down\');" onmouseout="clearTimeout(Timeout_id);this.blur();" onmouseup="clearTimeout(Timeout_id);this.blur();" onclick="return false;"></a></li>';									
      wmVideoPlayerString += '<li id="vol_up"><a href="#" onmousedown="WMVolume(\'up\');" onmouseup="clearTimeout(Timeout_id);this.blur();" onmouseout="clearTimeout(Timeout_id);this.blur();" onclick="return false;"></a></li>';	
      wmVideoPlayerString += '</ul>';      
		document.write(wmVideoPlayerString);
    } else {
     var newheight = 345;
     var showStatusBar = detectPlatformMac();

      wmVideoPlayerString += '<object id="wmVidPlayer" name="wmVidPlayer" width="' + width + '" height="' + newheight + '" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading Stream..." type="application/x-oleobject">';

      wmVideoPlayerString += '    <param name="URL" value="' + vid + '">';
      wmVideoPlayerString += '    <param name="AllowChangeDisplaySize" value="True">';
      wmVideoPlayerString += '    <param name="AutoSize" value="False">';
      wmVideoPlayerString += '    <param name="DisplaySize" value=0>';
      wmVideoPlayerString += '    <param name="ShowControls" value="True">';
      wmVideoPlayerString += '    <param name="AutoRewind" value="True">';
      wmVideoPlayerString += '    <param name="AutoStart" value="True">';
      wmVideoPlayerString += '    <embed id="wmVidPlayer" name="wmVidPlayer" src="' + vid + '" type="application/x-mplayer2" width="' + width + '" height="' + newheight + '" showstatusbar="'+showStatusBar+'" AutoSize="true" loop="true" DisplaySize="0" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/">';
      wmVideoPlayerString += '    </embed>';
      wmVideoPlayerString += '</object>';
      document.write(wmVideoPlayerString);

	}
}


function WMstartVideo(str) {

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        if(WMisDefined(str)){
            document.wmVidPlayer.URL = str;
			//forces play button highlight
			WMChangeObjControlBtn(1,1);
        }
        document.wmVidPlayer.controls.play();
    }
}

function wmCheckMuteStatus(){
	    WMsetMuteValue(wmaMuteStatus);
}

function WMstopVideo (){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        document.wmVidPlayer.controls.stop();
    }
}

function WMpauseVideo (){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        document.wmVidPlayer.controls.pause();
    }
}

function WMfastReverseVideo (){
	//forces play button highlight
	WMChangeObjControlBtn(1,1);
    if (wmcodecPassedDetection == "activeX" | wmMediaBrowserSupportsActiveX) {
        document.wmVidPlayer.controls.fastReverse();
    }
}

function WMfastForwardVideo (){
	//forces play button highlight
	WMChangeObjControlBtn(1,1);
    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        document.wmVidPlayer.controls.fastForward();
    }
}

function WMtoggleMuteValue (){

    if(WMgetMuteValue() == true){
        WMsetMuteValue(false);
		WMMuteBtn.obj.style.backgroundPosition = "-60px 0";
		WMChangeObjVolBar('',WMVolBarPosition);
    }else{
    	WMMuteBtn.obj.style.backgroundPosition = "0 0";							
		WMVolBar.obj.style.backgroundPosition = "-71px 0";
        WMsetMuteValue(true);
    }
}

function WMsetMuteValue (status){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
		try {
	        document.wmVidPlayer.settings.mute = status;
		} catch(e){};
    }
    wmaMuteStatus = status;
}

function WMgetMuteValue (){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return document.wmVidPlayer.settings.mute;
    }
}

function WMincVolume (increment){

    var volNum = 50;
    var inc = 8;
    if(WMisDefined(increment)) {inc = increment;}

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        volNum = document.wmVidPlayer.settings.volume + inc;
        document.wmVidPlayer.settings.volume = volNum;
    }
}

function WMdecVolume (increment){

    var volNum = 50;
    var inc = 8;
    if(WMisDefined(increment)) {inc = increment;}

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        volNum = document.wmVidPlayer.settings.volume - inc;
        document.wmVidPlayer.settings.volume = volNum;
    }
    if(volNum < 0) { volNum = 0; }
    
    return volNum;
}

function WMgetVolume(){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return document.wmVidPlayer.settings.volume;
    }
}

function WMsetVolume(volNum){

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return document.wmVidPlayer.settings.volume = volNum;
    }
}

function WMgetVideoDurationStr() {

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return document.wmVidPlayer.controls.CurrentPositionString || '';
    }
}


function WMgetVideoDurationInt() {

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return Math.floor(document.wmVidPlayer.currentMedia.duration) || 0;
    }
}


function WMgetTimePositionStr() {

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return document.wmVidPlayer.controls.CurrentPositionString || '';
    }
}


function WMgetTimePositionInt() {

    if (wmcodecPassedDetection == "activeX" || wmMediaBrowserSupportsActiveX) {
        return Math.floor(document.wmVidPlayer.controls.CurrentPosition) || 0;
    }
}


function OnPlayStateChange(NewState) {
    if(NewState == 1){;}
}

function WMisDefined (input){
    return (input != "" && input != undefined);
}


function detectPlatformWindows(){
    var platform = /Win/i;
    return platform.test(navigator.platform);
}

function detectPlatformMac(){
    var platform = /Mac/i;
    return platform.test(navigator.platform);
}

// Taken from Netscape's Devedge Site
//http://devedge-temp.mozilla.org/viewsource/2003/windows-media-in-netscape/index_en.html
function detectWMPSupport(){

    var wmp64 = "MediaPlayer.MediaPlayer.1";
    var wmp7 = "WMPlayer.OCX.7";
    if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject)
    {
        if(createActiveXObject(wmp7)){ 
            return true;

        }else{
            if(createActiveXObject(wmp64)){
                return true;
            }else{
                return false;
            }
        }
    }else{ 
        return false;
    }
}

function createActiveXObject(id){
  var error;
  var control = null;

  try{
    if (window.ActiveXObject){
      control = new ActiveXObject(id);
    }else if (window.GeckoActiveXObject){
      control = new GeckoActiveXObject(id);
    }
  }
  catch (error){;}
  return control;
}


if(WM_browserAcceptsCookies()) {
	wmcodecPassedDetection = WM_readCookie('wmVid');
}

var wmDocDomain = '';
if(wmDocDomain) {document.domain = wmDocDomain;}



var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")


