//js for flash detection
document.write('<script type=\"text/javascript\" src=\"/forms/js/swfobject.js\"><\/script>')

//vars for google tracking
var movieID = [];
var movieFrame = [];
var movieCat = [];
var movieLab = [];
	
//function to display FLVs
function slb_FLVPlayer(setHeight,setWidth,playerVars){
	playerVars = playerVars.replace(/refsite=/,"");
	var divName = playerVars.replace(/\./gi, "");
	divName = divName.replace(/\//gi, "");
	//alert(2);
	document.write("<div id=\"" + divName + "\" style=\"width: " + setWidth + "px; height: " + setHeight + "px; padding: 10px; text-align: center; background-color: Gray;\">Flash player is required for this media type.<br><br><a href=\"https://www.adobe.com/go/getflashplayer\"><img src=\"https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" \/><\/a><\/div>");
	var flashvars = {};
	flashvars.skinPath= "~/media/Videos/flvplayer/ClearOverPlaySeekMute.swf";
	flashvars.refsite= playerVars;
	//alert(flashvars);
	var params = {};
	var attributes = {};
	swfobject.embedSWF("~/media/Videos/flvplayer/videoplayer.swf", divName, setWidth, setHeight, "9.0.0", "/forms/js/expressInstall.swf", flashvars, params, attributes);
}

//tracking codes
function getTracker(var1, var2, var3, var4){
	pageTracker._trackEvent(var1, var2, var3, var4);
	//alert(var1 + " -- " + var2 + " -- " + var3 + " -- " + var4);
}

//counts the seconds that have elapse in movie
function framecount(fcat, flab, fid, fnum){
	var foundID = false;
	if(movieID.length == 0){
		//if movie array is empty create first record
		tempNum = movieID.length;
		movieID[tempNum]=fid;
		movieFrame[tempNum]=fnum;
		movieCat[tempNum]=fcat;
		movieLab[tempNum]=flab;
	} else {
		//search to see if record exist
		for(i=0; i<movieID.length; i++) { 
			if(fid == movieID[i]){
				//if exist set frame number to array location
				movieFrame[i]=fnum;
				foundID = true;
			}
		}
		if(foundID==false){
			//if doens't exist then create a new record at the bottom of array
			tempNum = movieID.length;
			movieID[tempNum]=fid;
			movieFrame[tempNum]=fnum;
			movieCat[tempNum]=fcat;
			movieLab[tempNum]=flab;
		}
	}
}

//when page closes, all event tracking data is sent
function endAction(){
	if(movieID.length != 0){
		var tempStr = "Result:\n";
		var tempText;
		//loops through array of all objects being tracked
		for(i=0; i<movieID.length; i++) {
			tempText =  document.location.href.toLowerCase();
			tempText = tempText.replace(/http:\/\/westerngeco/,"http://www.westerngeco");
			tempText = tempText.replace(/http:\/\/slb/,"http://www.slb");
			tempText = tempText.replace(/https/,"http");
			tempText = tempText.replace(/http:\/\/public.slb/,"http://www.slb");
			
			getTracker(movieCat[i], tempText, movieID[i], parseInt(movieFrame[i]));
			tempStr += movieCat[i] + " - " + movieLab[i] + " - " + movieID[i] + " - " + parseInt(movieFrame[i]) + "\n";
		}
		if(document.location.href.indexOf("test.") > 0 || document.location.href.indexOf("pilot.") > 0 ){
			alert(tempStr);
		}
	}
}

//finds all media files on page and track them w/ google
function setAnchors(){
	var anchorx = document.getElementsByTagName('a');
	for(var i = 0; i < anchorx.length; i++) {
		if(anchorx[i].href.indexOf("media")>=0){
			anchorx[i].onclick = function(){javascript:getTracker('Download', document.location.href.toLowerCase(), this.href);};
			//anchorx[i].onclick = function(){javascript:alert(this.href)};
		}
	}
}
window.onload=setAnchors;

//execute when page closes	
window.onbeforeunload = endAction;