﻿var rplayer;


function Msn.Video.OnExternalInterfaceLoaded(id)
{
//	alert("hello");
	rplayer = window.document.getElementById("player1_pobj");
	docName = getDocumentName();
	curVID = getVideoID();
	if ((docName == "playvideo.asp") || (docName == "playvideo_retired.asp"))
	{
		rplayer.vidPlayId(curVID);
		getVideoTitle();
		initControls();
	}	
}

function initControls()
{
		updateLinkIt();
		updateEmbedIt();
}

function AddToSpaces()
{

	var msnSpacesApi="http://spaces.live.com/BlogIt.aspx?mkt=zh-hk&";

	title = escape(rplayer.vidGetTitle());
	txt = "<embed src=\"http://images.video.msn.com/flash/soapbox1_1.swf\" width=\"432\" height=\"364\" id=\"celoik2u\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowScriptAccess=\"always\" pluginspage=\"http://macromedia.com/go/getflashplayer\" flashvars=\"c=v&v=" + rplayer.vidGetId() + "&ifs=true&fr=msnvideo&mkt=zh-HK\"></embed><noembed><a href=\"http://video.msn.com.hk/playvideo.asp?id=" + rplayer.vidGetId() + "\" target=\"_new\" title=\""+ rplayer.vidGetTitle() + "\">Video: " + rplayer.vidGetTitle() + "</a></noembed>";

	bnew = true;

	window.open(msnSpacesApi + "Title=" + title + 
              "&SourceURL=" + escape(window.location.href.replace(window.location.hash, "")) + 
              "&description=" + escape(txt), (bnew) ? "_toolbar" : "_self", "", bnew)

}


function updateLinkIt()
{
	window.document.getElementById("linkit_movie").value = "http://video.hk.msn.com/playvideo.asp?id=" + getVideoID();
	window.document.getElementById("linkit_image").value = "<a href=\"http://video.hk.msn.com/playvideo.asp?id=" + getVideoID() + "\" target=\"_new\" title=\"" + rplayer.vidGetTitle() + "\"><img src=\"http://img2.catalog.video.msn.com/Image.aspx?uuid=" + getVideoID() + "&w=112&h=84\" border=0 alt=\"" + rplayer.vidGetTitle() + "\" width=112 height=84><br />" + rplayer.vidGetTitle() + "</a>";
}

function copyMovieLink()
{
	clipboardData.setData("Text","http://video.hk.msn.com/playvideo.asp?id=" + getVideoID());
}

function copyImageLink()
{
	clipboardData.setData("Text","<a href=\"http://video.hk.msn.com/playvideo.asp?id=" + getVideoID() + "\" target=\"_new\" title=\"" + rplayer.vidGetTitle() + "\"><img src=\"http://img2.catalog.video.msn.com/Image.aspx?uuid=" + getVideoID() + "&w=112&h=84\" border=0 alt=\"" + rplayer.vidGetTitle() + "\" width=112 height=84><br />" + rplayer.vidGetTitle() + "</a>");
}

function updateEmbedIt()
{
	window.document.getElementById("embedit_movie").value = "<embed src=\"http://images.video.msn.com/flash/soapbox1_1.swf\" width=\"432\" height=\"364\" id=\"celoik2u\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowScriptAccess=\"always\" pluginspage=\"http://macromedia.com/go/getflashplayer\" flashvars=\"c=v&v=" + getVideoID() + "&ifs=true&fr=msnvideo&mkt=zh-HK\"></embed><noembed><a href=\"http://video.msn.com/video.aspx?vid=" + getVideoID() + "\" target=\"_new\" title=\"Water bird\">Video: " + rplayer.vidGetTitle() + "</a></noembed>";
}

function copyEmbedIt()
{
	clipboardData.setData("Text","<embed src=\"http://images.video.msn.com/flash/soapbox1_1.swf\" width=\"432\" height=\"364\" id=\"celoik2u\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowScriptAccess=\"always\" pluginspage=\"http://macromedia.com/go/getflashplayer\" flashvars=\"c=v&v=" + getVideoID() + "&ifs=true&fr=msnvideo&mkt=zh-HK\"></embed><noembed><a href=\"http://video.msn.com/video.aspx?vid=" + getVideoID() + "\" target=\"_new\" title=\"Water bird\">Video: " + rplayer.vidGetTitle() + "</a></noembed>");
}

function play_video(guid)
{
	//guid = prompt("Input the guid","");
	//b9a7c3e2-820b-4214-b895-295389ed42b3 original one
	//596b2af2-f11c-4222-ac04-00784de14a22
	//91c278be-0785-4184-9cbd-6034a1ec074b
	//93981e61-6b8f-4594-867a-c84676c96c7c
	//612f4e4a-f5fe-48b0-88c5-d6283051d406
	//0d2f09b4-1cf8-44fc-8575-d97e9af9978b
	docName = getDocumentName();
	curVID = getVideoID();
	if ((docName == "playvideo.asp") || (docName == "playvideo_retired.asp"))
	{
		window.location ="playvideo.asp" + window.location.search.replace(curVID,guid);
	}
	else
	{
		rplayer.vidPlayId(guid);
	}
}

function add_to_playlist(guid)
{
	rplayer.queAddId(guid)
}

function getDocumentName()
{
	pathname = window.location.pathname;
	arr_path = pathname.split("/");
	return arr_path[arr_path.length - 1];
}

function getVideoTitle()
{
	document.getElementById('videotitle').innerHTML = rplayer.vidGetTitle();
}

function getVideoID()
{
	//for playvideo.asp use only
	parm = window.location.search;
	parm = parm.replace("?","");
	arr_parm = parm.split("&");
	for (i = 0; i<arr_parm.length; i++)
	{
		if (arr_parm[i].indexOf("id") >= 0)
		{
			return arr_parm[i].replace("id=","");
		}
	}
	return "";
}
