	var currentID = 0;
	var activeAssetId;
	var assetMetricsPath = "/business/storeMetricForAsset.ajax"; 
	var event;
	var playClicked;
	var activeMovie;
	var playstateValues = new Array("Undefined","Stopped","Paused","Playing","Scan Forward","Scan Reverse","Buffering","Waiting","Media Ended","Transitioning","Ready","Reconnecting");
	var playStateChangeDetectable;
	var t;
function timedCount(){
	if(!playClicked){
		jQuery("#hidden").trigger("click");
	}
	t = setTimeout("timedCount()", 2000);
}
function autoClick(){
		var wmp = document.getElementById('VIDEO');
		var currPlayState = wmp.playState;
		if(playstateValues[currPlayState]=="Play"||playstateValues[currPlayState]=="Stopped"||playstateValues[currPlayState]=="Buffering"||playstateValues[currPlayState]=="Paused"||playstateValues[currPlayState]=="Playing"||playstateValues[currPlayState]=="Waiting"){
			storeMetrics(activeAssetId);
			playClicked=true;
		}
		else{
			playClicked=false;
		}
		
}
function wmpPlayStateChange(newState) {
	playStateChangeDetectable = true;
	if(playstateValues[newState]=="Play"||playstateValues[newState]=="Buffering"||playstateValues[newState]=="Paused"||playstateValues[newState]=="Playing"||playstateValues[newState]=="Waiting"){
		//trigger off the call..ensure the AJAX request is made just once despite the various changes in playState
		storeMetrics(activeAssetId);
		playClicked=true;
	}
	else{
		playClicked=false;
	}
	if(playstateValues[newState]=="Stopped"){
		playClicked=true;
	}
}

$(document).ready(function(){
	$("#bmgCL_media_player_descriptions p").hide();
	$("#bmgCL_media_player_descriptions p").eq(0).show().addClass("bmgCL_active_text");
	$("a.bmgCL_norm_tab").click(function() {
		var index = $("#menu li").index($(this).parent()[0]);
		$("a.bmgCL_active_tab").removeClass("bmgCL_active_tab");
		$(this).addClass("bmgCL_active_tab");
		$("p.bmgCL_active_text").hide();
		$("#bmgCL_media_player_descriptions p").eq(index).show().addClass("bmgCL_active_text");
	});
	PluginDetect.getVersion(".");
    var version = PluginDetect.getVersion("WindowsMediaPlayer");
    var downLoadLink = "http://windows.microsoft.com/en-US/windows/downloads/windows-media-player";
    if (PluginDetect.isSafari) {
        downLoadLink = "http://www.apple.com/safari/download/plugins.html";
    }
    if (PluginDetect.isChrome) {
        downLoadLink = "http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx";
    }
    if (PluginDetect.isGecko) {
        downLoadLink = "http://www.interoperabilitybridges.com/windows-media-player-firefox-plugin-download";
    }
    if (version != null) {
        version = parseInt(version.slice(0, version.indexOf(".")));
        if (version < 7) {
            jQuery(".bmgCL_voc_media_player_content").html("<div><div style='margin: 0px;'><p>Your version of Windows Media Player (v " + PluginDetect.getVersion('WindowsMediaPlayer') + ") is currently not supported.  <br> <br>Please upgrade to a newer version of Windows Media Player: <br /> <br /> <a target='_blank' href='" + downLoadLink + "'> " + downLoadLink + " </a> </p></div></div>");
        }
        else {
			//do nothing
        }
    }
    else {
        jQuery(".bmgCL_voc_media_player_content").html("<div><div style='margin: 0px;'><p>Your browser does not seem to have the Windows Media Player plugin that is required to play this media.  <br> <br>Please install from the following URL: <br /> <br /> <a target='_blank' href='" + downLoadLink + "'> " + downLoadLink + " </a> </p></div></div>");
    }
	
	jQuery("a#hidden").bind("click",function(){
		autoClick();
		
	})
	
	jQuery(".bmgCL_voc_media_player_menu").find("li").each(function(i,n){
		$(n).data("allData",{
			"link":$(this).find("a:first"),
			"movieName": $(this).find("a").text(),
			"movieURL" : $(this).find("a").attr("href"),
			"assetId": $(this).find("a").attr("assetId"),
			"isActive": $(this).find("a").hasClass("bmgCL_active_tab"),
			"siblings":$(this).siblings(),
			"siblingsLinks":$(this).siblings().find("a:first"),
			"hasPlayed": 0
		})
		$(this).data("allData").link.bind("click",function(){
			//set playClicked to false - new values will be sent
			playClicked = false;
			ajaxCallActive=false;
			setMovie($(n).data("allData").movieURL);
			activeAssetId = $(n).data("allData").assetId;
			$(n).data("allData").isActive = $(this).hasClass("bmgCL_active_tab");
			$(n).siblings().each(function(){
				$(this).data("allData").isActive = $(this).find("a").hasClass("bmgCL_active_tab");
			})
			return false;
		})
	})
	setActiveId();
		if(!playStateChangeDetectable){
		timedCount();
	}
});

function setActiveId(n){
	//find (mabe URL check, maybe click) the activeTab
	if (!n) {
		jQuery(".bmgCL_voc_media_player_menu").find("li").each(function(i, n){
			if ($(this).find("a").hasClass("bmgCL_active_tab")) {
				activeAssetId = $(this).data("allData").assetId
				$(this).data("allData").link.trigger("click");
			}
		})
	}
	else {
		activeAssetId = jQuery(n).data("allData").assetId;
		jQuery(n).data("allData").link.trigger("click");
	}
}

// http://www.mioplanet.com/rsc/embed_mediaplayer.htm
function setMovie(arg){
	try {
		var obj = document.getElementById("VIDEO");
		if (obj.URL) 
			obj.URL = arg;
		if (obj.src) 
			obj.src = arg;
			activeMovie=arg;
	}
	catch(e){
		//do nothing
	}
}

function storeMetrics(assetId){
	if (playClicked==false) {
		jQuery.ajax({
			type: "GET",
			async: false,
			timeout: 3000,
			url: assetMetricsPath,
			data: "assetId=" + assetId,
			success: function(data){
				log.info("storeMetrics","JS: Passed Asset Id: "+assetId+" to the metrics path: "+assetMetricsPath,5);
			},
			error: function(x, t, m){
				if (t === "timeout") {
					log.error("JS: Request timed out. Could NOT pass Asset Id: " + assetId + " to the metrics path: " + assetMetricsPath);
				}
				log.error("JS: Could NOT pass Asset Id: " + assetId + " to the metrics path: " + assetMetricsPath);
			},
			complete: function(XMLHttpRequest, textStatus){
			}
		})
	}
}

/****************************************
 Track Movie with Omniture
****************************************/

var player = null;
var previousStatus;
var currentPosition;

function mediaPlayerStatus(){
	try{
		var status = "";
		if(player!=null){
			
			if(player.controls.currentPositionString !=  "")
				currentPosition = player.controls.currentPositionString;
			switch(player.playState){
				case 1:
					status = "Stop";
					break;
				case 2:
					status = "Pause" ;
					break;
				case 3:
					if(player.controls.currentPositionString ==  "")
						currentPosition = "0:00";
					status = "Play";
					break;
			}
			if(status != "" && previousStatus != status){
				previousStatus = status;
				generateDataForOmniture(status);
			}
		} else {
			initPlayer();
		}
	} catch (e){}
}
function initPlayer(){
	player = (document.getElementById("VIDEO"))?document.getElementById("VIDEO"):null;
}
var basePageName = ""; var basePageNameSet=false;
function generateDataForOmniture(_status){
	var pageName = "";
	if(s.pageName && !basePageNameSet){
		pageName = s.pageName;
		basePageName = s.pageName;
		basePageNameSet=true;
	} else {
		pageName = basePageName;
	}
	var movieName = player.URL.split("/")[player.URL.split("/").length - 1];
	var dataForOmniture = "s.pageName='"+pageName + "|" + movieName + "|" + _status + "|" + currentPosition + "|" + player.currentMedia.durationString+"';";
	try{sendOmnitureData(dataForOmniture);}catch(e){}
}
$(window).load(function(){
	player = (document.getElementById("VIDEO"))?document.getElementById("VIDEO"):null;
	setInterval("mediaPlayerStatus()", 10);
});
