/**********
 * Clip Constructor
 * create an object for each clip set
 */
function Clip(videos, caption, photo, category){
	this.caption = caption;
	this.photo = photo;
	if (category != null) {
		this.category = category;
	} else {
		this.category = "Top Videos";
	}
	this.videos = new Array();
	for(var i=0; i<videos.length; i++) {
		this.videos[i] = new Video(videos[i]);
	}
}
		
// Clip Method: returns if clip sets are complete
Clip.prototype.getComplete = function () {
	for(var i=0; i<this.videos.length; i++) {
		if(this.videos[i].url == "" && this.videos[i].type != "ad") {
			return false;
			break;
		}
	}
	return true;
};







/**********
 * Video Constructor
 * create an object for each video in a clip set
 */
function Video(obj) {
	this.name = null;
	this.url = null;
	this.id = null;
	this.type = null;
	this.banner_class = null;
	this.insite_related = null;
	this.insite_start = null;
	this.insite_end = null;
	this.ad_start = null;
	this.ad_end = null;
	this.ad_button = null;
	this.ad_buttonclick = null;
	this.ad_class = null;
	this.ad_frame = null;
	if(obj != null) {
		this.name = obj.name;
		this.id = obj.id;
		this.url = this.getPathByName(this.name);
		this.ad_class = obj.ad_class;
		this.type = "asset";
		this.setTracking();
	} 
}
		
// Video Method: sets properties for the ads
Video.prototype.setAd = function (s) {
	this.ad_frame = (s != null) ? s : null;
	this.name = (window.frames["ad_data_"+this.ad_frame] && null != window.frames["ad_data_"+this.ad_frame].adClip) ? window.frames["ad_data_"+this.ad_frame].adClip : adClip;
	this.url = this.getPathByName(this.name);
	this.type = "ad";
	this.setTracking();
};

// Video Method: sets tracking code for the videos & ads
Video.prototype.setTracking = function () {
	this.insite_related = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=RELATEDVIDEO_START&goto=http://espn.go.com/i/blank.gif";
	this.insite_start = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=START_MOTION_WMV_" + this.name + "&goto=http://espn.go.com/i/blank.gif";
	this.insite_end = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=END_MOTION_WMV_" + this.name + "&goto=http://espn.go.com/i/blank.gif";
	if(this.type == "ad" && window.frames["ad_data_"+this.ad_frame]) {
		this.ad_start = (null != window.frames["ad_data_"+this.ad_frame].adTrack) ? window.frames["ad_data_"+this.ad_frame].adTrack : adTrack;
		this.ad_end = adTrackFinish;
		this.ad_button = (null != window.frames["ad_data_"+this.ad_frame].adButton) ? window.frames["ad_data_"+this.ad_frame].adButton : adButton;
		this.ad_buttonclick = (null != window.frames["ad_data_"+this.ad_frame].adButtonClick) ? window.frames["ad_data_"+this.ad_frame].adButtonClick : adButtonClick;
	}
};

// Video Method: get the local path of clips by name
Video.prototype.getPathByName = function (name) {
	var localPath = "";
	if(document.DIGStreamLocator != null && document.DIGStreamLocator.object != null) {
		localPath = DIGStreamLocator.GetLocalPathFromName("ESPNMotion", name);
	}
	return localPath;
};







/**********
 * Playlist Constructor
 * create an object for the playlist
 */
function Playlist(clips,intro,promo) {
	this.clips = clips;
	this.assets = new Array();
	this.intro = intro;
	this.promo = promo;
	this.ad = new Video();
	this.viewed = this.getViewedCookie();
	this.current_asset = 0;
	this.current_video = 0;
	this.contentviews = -1;
	this.adplayed = false;
	this.lastadclass = null;
	for(var i=0; i<this.clips.length; i++) {
		if(this.clips[i].getComplete()) {
			this.assets.push(this.clips[i]);
		}
	}
			
	if (this.assets.length==0 && this.promo.getComplete()) {
		this.assets.push(this.promo);
		this.contentviews = 0;
		this.adplayed = true;
	}
}

// Playlist Method: determine if has assets
Playlist.prototype.addAsset = function (clip) {
	this.clips.push(clip);
	if(clip.getComplete()) {
		this.assets.push(clip);
	}
};

// Playlist Method: determine if has assets
Playlist.prototype.getHasAssets = function () {
	return this.assets.length>0;
};

// Playlist Method: determine if automatically play motion
Playlist.prototype.getAutoPlay = function () {
	var play = -1;
	if (this.viewed != null && this.viewed.length > 0) {
		var temp;
		for (var i=0; i<this.assets.length; i++) {
			for (var j=0; j<this.assets[i].videos.length; j++) {
				if (this.assets[i].videos[j].type != "ad") {
					temp = this.assets[i].videos[j].id;
					break;
				}
			}

			for (var j=0; j<this.viewed.length; j++) {
				if (temp == this.viewed[j].id) {
					play = -1;
					break;
				} else {
					play = i; 
				}
			}
			if (play > -1) {
				break;
			}
		}
	} else {
		play = 0;
	}
	return this.getHasAssets()
		&& play > -1
		&& autoStartVideo ? play : -1;
};




// Playlist Method: get/set property
Playlist.prototype.getAssetProperty = function (property) {
	return this.assets[this.current_asset].videos[this.current_video][property];
};

Playlist.prototype.setProperty = function (name, value) {
	this[name] = value;
};


// Playlist Method: 
Playlist.prototype.setCurrentAsset = function (name) {
	for(var i=0; i<this.assets.length; i++) {
		if(name == this.assets[i].videos[0].name) {
			this.current_asset = i;
			this.playAssets();
			return;
		}
	}
		
	for(var i=0; i<this.assets.length; i++) {
		for(var j=0; j<this.assets[i].videos.length; j++) {
			if(name == this.assets[i].videos[j].name) {
				this.current_asset = i;
				this.playAssets();
				return;
			}
		}
	}
};

// Playlist Method: play videos in each clip set
Playlist.prototype.playAssets = function () {
	var currentVideosArray = this.assets[this.current_asset].videos;
	
	if (this.contentviews == -1) {
		this.contentviews += 1;
		currentVideosArray.unshift(this.intro);
	} else if (this.current_video == 0 || (this.adplayed == false && adClip != null)) {
		if (currentVideosArray[0].name == this.intro.name) {
			currentVideosArray.splice(0,1);
			(this.current_video - 1 < 0) ? this.current_video = 0 : this.current_video -= 1;
		} else {
			this.removeAssets();
		}
		
		if (this.getAssetProperty("ad_class") != "noad" && this.lastadclass != "noad") {
			this.contentviews += 1;
			
			if (this.adplayed == false) {
				this.assignAd();
				
				(this.ad.url != "") ? currentVideosArray.unshift(this.ad) : null;
				this.contentviews = adInsertNum;
			} else if (this.contentviews%adInsertNum == 0) {
				this.assignAd();
				
				(this.ad.url != "") ? currentVideosArray.unshift(this.ad) : null;
			}
		} else {
			this.contentviews = adInsertNum-1;
		}
	}

	if (this.current_video<this.assets[this.current_asset].videos.length) {
		if (this.getAssetProperty("url") != "") {
			video_player.URL = this.getAssetProperty("url");
			this.trackAssets("start");
			readyToPlay();
			if (this.getAssetProperty("id") != null) {
				this.appendViewedCookie(this.getAssetProperty("id"));
			}
			if (this.assets[this.current_asset].category=="Related Videos") {
				this.trackAssets("related");
			}
		} else {
			++ this.current_video; 
			this.playAssets();
		}
	} else {
		this.current_asset = 0;
		this.current_video = 0;
		//video_player.close();
		video_layer.style.visibility = "hidden";
		shadow_layer.style.visibility = "hidden";
		this.nextClip();
	} 
};

// Playlist Method: remove intro and ads after they are played from video array
Playlist.prototype.nextClip = function () {
	var divcontainer = "flash_nextclip";
	if(!document.getElementById(divcontainer)){
		var divholder = document.createElement("div");
		divholder.id = divcontainer;
		document.body.appendChild(divholder);
	}
	var sender = fbroadcaster;
	var method = "nextClip";
	var flashquery = "sender="+sender+"&method="+method;
	document.getElementById(divcontainer).innerHTML = "";
	var divinfo = "<embed src='http://static.espn.go.com/broadband/flash/proxy1.swf' FlashVars='"+flashquery+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
	document.getElementById(divcontainer).innerHTML = divinfo;
};

// Playlist Method: remove intro and ads after they are played from video array
Playlist.prototype.removeAssets = function () {
	for(var i=0; i<this.assets.length; i++) {
		for(var j=0; j<this.assets[i].videos.length; j++) {
			if(this.assets[i].videos[j].type == "ad") {
				this.assets[i].videos.splice(0,j+1);
			}
		}
	}
};
		

// Playlist Method: track clips as they are started or completed
Playlist.prototype.trackAssets = function (tracktype) {
	bannerImg.style.display = "none";
	promoImg.style.display = "inline";
	if (tracktype == "start") {
		trackVideoStart.src = this.getAssetProperty("insite_start");
		if (this.getAssetProperty("type") == "ad" ) {
			this.adplayed = true;
			trackVideoAd.src = this.getAssetProperty("ad_start");
			bannerImg.style.display = "inline";
			promoImg.style.display = "none";
			bannerImg.src = this.getAssetProperty("ad_button");
			bannerClick.href = this.getAssetProperty("ad_buttonclick");
			(window.frames["ad_data_"+this.getAssetProperty("ad_frame")]) ? window.frames["ad_data_"+this.getAssetProperty("ad_frame")].location.reload() : null;
		} else if (this.getAssetProperty("banner_class") != null && window.frames["promo_frame"]) {
			this.lastadclass = this.getAssetProperty("ad_class");
			var src = (this.getAssetProperty("banner_class") != "generic") ? promoFrameSrc + "&url=" + this.getAssetProperty("banner_class") : promoFrameSrc;
			window.frames["promo_frame"].location.replace(src);
		} else {
			this.lastadclass = this.getAssetProperty("ad_class");
		}
		
		if (this.getAssetProperty("name") == bumperClip) {
			trackVideoAd.src = bumperTrack;
		}
		
	} else if (tracktype == "end") {
		trackVideoEnd.src = this.getAssetProperty("insite_end");
		if (this.getAssetProperty("type") == "ad") {
			trackVideoAd.src = this.getAssetProperty("ad_end");
		}
	} else if (tracktype == "related") {
		trackVideoEnd.src = this.getAssetProperty("insite_related");
	}
};

// Playlist Method: sets a new ad within the clip sets
Playlist.prototype.assignAd = function () {
	this.ad.setAd(this.getAssetProperty("ad_class"));
};

// Return the active videos in the _viewed cookie
Playlist.prototype.getViewedCookie = function() {
	var clipsCookie = GetCookieUtil("espnmotion_viewed");
	
	var today = new Date();
	var time = today.getTime();
	var expire = time-(2 * 24 * 60 * 60 * 1000);

	if (clipsCookie != null) {
		var clipsArray = clipsCookie.split("|");
		for (var i=0; i<clipsArray.length; i++) {
			var properties = clipsArray[i].split("~");
			clipsArray[i] = {id:properties[0], date:properties[1]};
		}
		for (var i=0; i<clipsArray.length; i++) {
			if (clipsArray[i].date < expire || clipsArray[i].id == "") {
				clipsArray.splice(i,1);
				i--;
			}
		}
		return clipsArray;
	} else {
		return null;
	}
};

// Add active videos to the _viewed cookie
Playlist.prototype.appendViewedCookie = function(newclip) {
	var today = new Date();
	var time = today.getTime();
	var temp = newclip + "~" + time + "|";
	var append = {id:newclip, date:time};
	if (this.viewed != null && this.viewed.length > 0) {
		var unseen = false;
		for (var i=0; i<this.viewed.length; i++) {
			if (newclip == this.viewed[i].id) {
				unseen = false;
				break;
			} else {
				unseen = true; 
			}
		}
		if (unseen) {
			for (var i=0; i<this.viewed.length; i++) {
				temp += this.viewed[i].id + "~" + this.viewed[i].date + "|";
			}
			SetCookieUtil("espnmotion_viewed",temp,oneWeek);
			this.viewed.push(append);
		}
	} else {
		SetCookieUtil("espnmotion_viewed",temp,oneWeek);
		this.viewed = new Array();
		this.viewed.push(append);
	}
};

// Insure Player Ready State
function readyToPlay() {
	if(video_player.playstate == 10) {
		setTimeout("video_player.controls.play()", 100);
	} else {
		setTimeout("readyToPlay()", 200);
	}
}







function Wmp(id){
	this.id = id;
	this.height = 240;
	this.width = 320;
	this.volume = 100;
	this.params = new Object();
}

Wmp.prototype.render = function () {
	var o = '<OBJECT ID="' + this.id + '" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="' + this.width + '" HEIGHT="' + this.height + '">'
	var p = "";
	for (var i in this.params) {
		p += '<PARAM NAME="' + i + '" VALUE="' + this.params[i] + '"">'
	}
	var s = o + p + '<\/OBJECT>';
	return s;
};





var mTop = 0;
var mSize = "min";

// Control Video via Flash
function motioncontrols_DoFSCommand(command, args) {
	switch (command){
		case "playpause":
			if(video_player.playstate == 3) {
				video_player.controls.pause();
			} else {
				video_layer.style.visibility = "visible";
				mSize == "max" ? shadow_layer.style.visibility = "visible" : shadow_layer.style.visibility = "hidden";
				video_player.controls.play();
				if(motionplaylist.getAssetProperty("type") == "ad") {
					bannerImg.style.display = "inline";
					promoImg.style.display = "none";
				}
			}
			break;

		case "stop":
			video_player.controls.stop();
			motionplaylist.setProperty("current_video", 0);
			video_player.URL = motionplaylist.getAssetProperty("url");
			video_player.close();
			video_layer.style.visibility = "hidden";
			shadow_layer.style.visibility = "hidden";
			bannerImg.style.display = "none";
			promoImg.style.display = "inline";
			if(storyInlineAd!=null) { storyInlineAd.style.visibility = "visible"; } 
			if(storySkyAd!=null) { storySkyAd.style.visibility = "visible"; }
			if(uniNavDiv!=null) { uniNavDiv.style.visibility = "visible"; }
			if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "visible"; }
			break;
			
		case "jumpback":
			if(video_player.playstate == 3 || video_player.playstate == 2) {
				if (video_player.controls.currentPosition>10) {
					video_player.controls.currentPosition -= 10;
				} else {
					video_player.controls.currentPosition = 0;
				}
			}
			break;
			
		case "volume":
			var v = parseInt(args);
			if (v >= 0) {
				video_player.settings.volume = v;
				SetCookieUtil("espnmotion_volume",v,oneWeek);
			}
			break;

		case "playlist":
			video_layer.style.visibility = "visible";
			
			var clickstartTrack = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=CLICKSTART_" + args + "&goto=http://espn.go.com/i/blank.gif";
			trackVideoEnd.src = clickstartTrack;
		
			mSize == "max" ? shadow_layer.style.visibility = "visible" : shadow_layer.style.visibility = "hidden";
			motionplaylist.setProperty("current_video", 0);
			motionplaylist.setCurrentAsset(args);
			if(mSize=="max") {
				if(storyInlineAd!=null) { storyInlineAd.style.visibility = "hidden"; } 
				if(storySkyAd!=null) { storySkyAd.style.visibility = "hidden"; }
				if(uniNavDiv!=null) { uniNavDiv.style.visibility = "hidden"; }
				if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "hidden"; }
			}
			break;
			
		case "toggleSize":
			if (args == "max") {
				video_layer.style.top = mTop;
				video_layer.style.left = 258;
				video_player.style.height = 360;
				video_player.style.width = 480;
				video_layer.style.padding = 16;
				if(video_player.playstate == 3 || video_player.playstate == 2) {
					shadow_layer.style.visibility = "visible";
					var expand_track = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=ENLARGE_MOTION_WMV_" + motionplaylist.getAssetProperty("name") + "&goto=http://espn.go.com/i/blank.gif";
					trackVideoEnd.src = expand_track;
					if(storyInlineAd!=null) { storyInlineAd.style.visibility = "hidden"; } 
					if(storySkyAd!=null) { storySkyAd.style.visibility = "hidden"; }
					if(uniNavDiv!=null) { uniNavDiv.style.visibility = "hidden"; }
					if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "hidden"; }
				}
				mSize = "max";
			} else if (args == "min") {
				video_layer.style.top = mTop+32;
				video_layer.style.left = 772;
				video_player.style.height = 171;
				video_player.style.width = 228;
				video_layer.style.padding = 0;
				shadow_layer.style.visibility = "hidden";
				mSize = "min";
				if(storyInlineAd!=null) { storyInlineAd.style.visibility = "visible"; } 
				if(storySkyAd!=null) { storySkyAd.style.visibility = "visible"; }
				if(uniNavDiv!=null) { uniNavDiv.style.visibility = "visible"; }
				if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "visible"; }
			}
			break;
			
		case "sendtofriend":
			var id;
			
			if (motionplaylist.getAssetProperty("id") != null && motionplaylist.getAssetProperty("id") > 1) {
				video_player.controls.pause();
				id = motionplaylist.getAssetProperty("id");
				mSendToFriend(id);
			} else {
				for(var i=0; i<motionplaylist.assets[motionplaylist.current_asset].videos.length; i++) {
					if(motionplaylist.assets[motionplaylist.current_asset].videos[i].id != null && motionplaylist.assets[motionplaylist.current_asset].videos[i].id > 1) {
						video_player.controls.pause();
						id = motionplaylist.assets[motionplaylist.current_asset].videos[i].id;
						mSendToFriend(id);
						break;
					}
				}
			}
		
			break;
			
	}
}

function mSendToFriend(id) {
	mailpop = window.open("http://broadband.espn.go.com/broadband/motion/sendtofriend/index?id="+id,"sendtofriend","width=400,height=540,scrollbars=1,resizable=0,status=0,left=350,top=100");
}





function trackSWFVideos (tracktype, name) {
	var nameArray = name.split(".");
	
	bannerImg.style.display = "none";
	promoImg.style.display = "inline";
	
	if (tracktype == "start") {
		if (isMac || ((navigator.userAgent.toLowerCase().indexOf("netscape/7") != -1 || navigator.userAgent.toLowerCase().indexOf("firefox") != -1))) {
			trackVideoStart.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=START_MOTION_MAC_" + name + "&goto=http://espn.go.com/i/blank.gif";
		} else {
			trackVideoStart.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=START_MOTION_WMV_" + name + "&goto=http://espn.go.com/i/blank.gif";
		}
		if (adClip.indexOf(nameArray[0]) > -1) {
			trackVideoAd.src = adTrack;
			promoImg.style.display = "none";
			bannerImg.style.display = "inline";
			bannerImg.src = adButton;
			bannerClick.href = adButtonClick;
		} 
		
	} else if (tracktype == "end") {
		if (isMac || ((navigator.userAgent.toLowerCase().indexOf("netscape/7") != -1 || navigator.userAgent.toLowerCase().indexOf("firefox") != -1))) {
			trackVideoEnd.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=END_MOTION_MAC_" + name + "&goto=http://espn.go.com/i/blank.gif";
		} else {
			trackVideoEnd.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=END_MOTION_WMV_" + name + "&goto=http://espn.go.com/i/blank.gif";
		}
		if (adClip.indexOf(nameArray[0]) > -1) {
			trackVideoAd.src = adTrackFinish;
		}
	}
}


function toggleSize(size) {
	if (size == "max") {
		flash_layer.style.left = "356px";
		flash_layer.style.width = "646px";
		if(storyInlineAd!=null) { storyInlineAd.style.visibility = "hidden"; } 
		if(storySkyAd!=null) { storySkyAd.style.visibility = "hidden"; }
		if(uniNavDiv!=null) { uniNavDiv.style.visibility = "hidden"; }
		if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "hidden"; }
	} else if (size == "min") {
		flash_layer.style.left = "772px";
		flash_layer.style.width = "230px";
		if(storyInlineAd!=null) { storyInlineAd.style.visibility = "visible"; } 
		if(storySkyAd!=null) { storySkyAd.style.visibility = "visible"; }
		if(uniNavDiv!=null) { uniNavDiv.style.visibility = "visible"; }
		if(uniNavDiv2!=null) { uniNavDiv2.style.visibility = "visible"; }
	}
}









function loadXMLDoc() {
	//alert("load Motion XML");

    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", motionXML, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", motionXML, true);
            req.send();
        }
    }
}

function processReqChange() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			handleResponse();
		} else {
			//alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

BASE_IMG_URL = "";

function handleResponse() {
	var categories = req.responseXML.getElementsByTagName("SECTION");

	sectionsArray = new Array();
	var sectionNode, clipNode, clipsArray, section_data, clip_data, name, image, caption, duration, related;
	var clip;

	for (var i=0; i<categories.length; i++) {
		sectionNode = categories[i];
		clipsArray = new Array();
		
		clips = sectionNode.getElementsByTagName("CLIP");
		var caption, photo;
		
		for (var j=0; j<clips.length; j++) {
			clipNode = clips[j];
			caption = clipNode.getAttribute("CAPTION");
			photo = clipNode.getAttribute("IMAGE");
			videos = new Array();
			
			for (var k=0; k<clipNode.childNodes.length; k++) {
				videoNode = clipNode.childNodes[k];
				videoObj = {name:videoNode.getAttribute("NAME"), id:videoNode.getAttribute("ID"), banner_class:videoNode.getAttribute("BANNER"), ad_class:videoNode.getAttribute("AD")};
				videos.push(videoObj);
			}
			clip = new Clip(videos, caption, photo);
			clip.category = sectionNode.getAttribute("NAME");
			
			addit = true;
			for (var k=0; k<playlistArr.length; k++) {
				if (playlistArr[k].caption == clip.caption && playlistArr[k].category == clip.category) {
					addit = false;
					break;
				}
			}
		 	if (addit) {
				//playlistArr.push(clip);
				motionplaylist.addAsset(clip);
			}
		}
	}
	//motionplaylist = new Playlist(playlistArr,motionintro,motionpromo);
	
	setPlaylist();
}


function setPlaylist() {
	var playlist = "";
	for(var i=0; i<motionplaylist.assets.length; i++) {
		videopointer = 0;
		try { 
			if (motionplaylist.assets[i].videos[0].name == bumperClip || motionplaylist.assets[i].videos[0].name == adClip) {
				if(motionplaylist.assets[i].videos.length>1)
					videopointer = 1;
			}
			playlist += motionplaylist.assets[i].category + "~" + motionplaylist.assets[i].caption + "~" + motionplaylist.assets[i].videos[videopointer].name + "|";
		} catch(_e) {}
	}
	flash_player.SetVariable("playlistStr",playlist);
	flash_player.TCallLabel("_level0", "setup");
}


//Motion Guide
function openMotionGuide(src) {
	var guide_src = src;
			
	if (hasMotion) {
		if (mSize == "max") {
			video_layer.style.top = mTop+32;
			video_layer.style.left = 772;
			video_player.style.height = 171;
			video_player.style.width = 228;
			video_layer.style.padding = 0;
			mSize = "min";
		} else {
			shadow_layer.style.visibility = "visible";
		}
	}
			
	motion_guide_layer.style.display = "inline";
	window.frames["motion_guide_frame"].location.replace(guide_src);
}
		
function closeMotionGuide() {
	if (hasMotion) {
		shadow_layer.style.visibility = "hidden";
	}
	motion_guide_layer.style.display = "none";
}

//Contextual Links
function playVideoLink(id, category) {
	mTrackImage = new Image();
	mTrackImage.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=MOTION_CONTEXTLINK&goto=http://espn.go.com/i/blank.gif";
	
	/*//hide Motion ad div if it exists
	motionAd = document.getElementById("motionAd");
	if (motionAd!=null) {
		motionAd.style.display = "none";
	}*/
	
	if (browser != ie && browser != "ie" || (limitedFlash && !hasMotion)) {
		
		var divcontainer = "flash_setvideo";
		if(!document.getElementById(divcontainer)){
			var divholder = document.createElement("div");
			divholder.id = divcontainer;
			document.body.appendChild(divholder);
		}
		var sender = (typeof fbroadcaster != 'undefined')?fbroadcaster:"_motionProxy"+Math.round(Math.random()*100);
		var method = "linkClip";
		var flashquery = "sender="+sender+"&method="+method+"&fileId="+id+"&categoryName="+category;
		document.getElementById(divcontainer).innerHTML = "";
		var divinfo = "<embed src='http://static.espn.go.com/broadband/flash/proxy1.swf' FlashVars='"+flashquery+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
		document.getElementById(divcontainer).innerHTML = divinfo;
		return;
	} else if (!hasMotion && !isMac && (browser == ie || browser == "ie") && (sample_num == null || sample_num >= 100000)) {
		document.location.href = "http://espn.go.com/motion/download.html";
		return;
	}
		
	if (typeof hasMotion == "undefined" || !hasMotion) {
  		window.open('http://sports.espn.go.com/broadband/motion/showcase_popoff?CMP=ILC-motionpoplink&video='+id+'&category='+category,'showcase','width=780,height=430,scrollbars=no,noresize'); 
 		return false;
 	} else {
		if (typeof motionplaylist == "undefined") {
			window.open('http://sports.espn.go.com/broadband/motion/showcase_popoff?CMP=ILC-motionpoplink&video='+id+'&category='+category,'showcase','width=780,height=430,scrollbars=no,noresize'); 
 			return false;
 		} else {
			var divcontainer = "flash_setvideo";
			if(!document.getElementById(divcontainer)){
				var divholder = document.createElement("div");
				divholder.id = divcontainer;
				document.body.appendChild(divholder);
			}
		
			if (id == null || id == "") {
				motionplaylist.setProperty("adplayed", true);
				motionplaylist.setProperty("contentviews", adInsertNum-2);
				motioncontrols_DoFSCommand("toggleSize", "max");
				
				var sender = fbroadcaster;
				var method = "linkClip";
				var flashquery = "sender="+sender+"&method="+method+"&fileName=&captionName=&categoryName="+category;
				document.getElementById(divcontainer).innerHTML = "";
				var divinfo = "<embed src='http://static.espn.go.com/broadband/flash/proxy1.swf' FlashVars='"+flashquery+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
				document.getElementById(divcontainer).innerHTML = divinfo;
				return;
			}
  			
			for(var i=0; i<motionplaylist.assets.length; i++) {
				for(var j=0; j<motionplaylist.assets[i].videos.length; j++) {
					if(id == motionplaylist.assets[i].videos[j].id) {
						motionplaylist.setProperty("adplayed", true);
						motionplaylist.setProperty("contentviews", adInsertNum-2);
						motioncontrols_DoFSCommand("toggleSize", "max");
						
						var sender = fbroadcaster;
						var method = "linkClip";
						var flashquery = "sender="+sender+"&method="+method+"&fileName="+motionplaylist.assets[i].videos[j].name+"&captionName="+escape(motionplaylist.assets[i].caption)+"&categoryName="+escape(category);
						document.getElementById(divcontainer).innerHTML = "";
						var divinfo = "<embed src='http://static.espn.go.com/broadband/flash/proxy1.swf' FlashVars='"+flashquery+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
						document.getElementById(divcontainer).innerHTML = divinfo;
						return;
					}
				}
			}	
			
			for(var i=0; i<motionplaylist.clips.length; i++) {
				for(var j=0; j<motionplaylist.clips[i].videos.length; j++) {
					if(id == motionplaylist.clips[i].videos[j].id) {
						motionplaylist.setProperty("adplayed", true);
						motionplaylist.setProperty("contentviews", adInsertNum-2);
						motioncontrols_DoFSCommand("toggleSize", "min");
						motioncontrols_DoFSCommand("stop", "");
						
						var sender = fbroadcaster;
						var method = "linkClip";
						var flashquery = "sender="+sender+"&method="+method+"&fileName="+motionplaylist.clips[i].videos[j].name+"&captionName="+escape(motionplaylist.clips[i].caption)+"&categoryName="+escape(category);
						document.getElementById(divcontainer).innerHTML = "";
						var divinfo = "<embed src='http://static.espn.go.com/broadband/flash/proxy1.swf' FlashVars='"+flashquery+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";
						document.getElementById(divcontainer).innerHTML = divinfo;
						return;
					}
				}
			}			

			window.open('http://sports.espn.go.com/broadband/motion/showcase_popoff?CMP=ILC-motionpoplink&video='+id+'&category='+category,'showcase','width=780,height=430,scrollbars=no,noresize'); 
			return false;
		}
 	} 
}

//Motion To Go popoff
function launchPopoff() {
	mTrackImage = new Image();
	mTrackImage.src = "http://transfer.go.com/cgi/transfer.dll?srvc=sz&name=MOTION_BANNER_POPOFF&goto=http://espn.go.com/i/blank.gif";
	
	if ((browser != ie && browser != "ie") || hasMotion || isMac || (sample_num!=null && sample_num<100000))
		window.open('http://sports.espn.go.com/broadband/motion/showcase_popoff?CMP=ILC-motionpopban','showcase','width=780,height=430,scrollbars=no,noresize');
	else 
		document.location.href = "http://espn.go.com/motion/download.html";
}