﻿var oFlowPlayer,ActiveTab, currentContentID;
function setActiveVideo(videoData)
{
    if(oFlowPlayer != null)
	    oFlowPlayer.setConfig(videoData);	
}
function onFlowPlayerReady(){
    if(oFlowPlayer != null)
    {
	    var fpConf = {baseURL: '',autoPlay: false,autoBuffering: false, loop: false,initialScale: 'scale',showStopButton: true,showPlayListButtons:true,useNativeFullScreen: true}
	    oFlowPlayer.setConfig(fpConf);	
	}
}
function playClip(clip)
{
    if(oFlowPlayer != null)
        oFlowPlayer.playClip(clip);
}
function ClientTabChanged(sender, e)
{
	ActiveTab = sender.get_activeTab();
	var catId = getCatIdFromTab(ActiveTab)
	if(!IsPopulated(ActiveTab))
	{
		VideoService.GetVideoList(catId, GetPlayListComplete, CallError);
	}
}
function GetVideoInfo(contentID, catID)
{
	if(currentContentID != contentID)
	{
		VideoService.GetVideoInfo(contentID, catID, GetVideoInfoComplete, CallError);
	}
}
function GetPlayListComplete(Result)
{
	if(Result != null)
	{
		var elem = ActiveTab.get_element();
		elem.innerHTML = Result.Html;		
	}
}

function GetVideoInfoComplete(Result)
{
	if(Result != null)
	{
		currentContentID = Result.ContentID;
		var wsInfoComment = $get("ws-info-comment");
		wsInfoComment.innerHTML = Result.Html;
		var ekcontentid = $get("ctl00$mcp$ekCrekcontentid")
		if(ekcontentid == null)
		    ekcontentid = $get("ctl00_mcp_ekCrekcontentid")
		if(ekcontentid != null)
		    ekcontentid.value = Result.ContentID;
		var Flyout_tbComments = $get("ctl00$mcp$ekCr_tbComments");
		if(Flyout_tbComments == null)
		    Flyout_tbComments = $get("ctl00_mcp_ekCr_tbComments");
		if(Flyout_tbComments != null)
		{
		    Flyout_tbComments.value = "";
		    Flyout_tbComments.cols = 30;	
		}	
	}
}

function CallError(Result)
{
	var elem = ActiveTab.get_element();
	elem.innerHTML = "<p class='playlist-error'>An error has occurred while processing your last request.  Please try again later.</p>";
}

function IsPopulated(Tab)
{
	var elem = Tab.get_element();
	return (elem != null && elem.innerHTML.trim() != "");
}
function getCatIdFromTab(tab)
{
	var tabId = tab.get_id();
	return tabId.substring(tabId.lastIndexOf('_') + 1);	
}
function SetEkContentId(contentId)
{
	var ekcontentid = $get("ekcontentid");
	ekcontentid.value = contentId;
	var Flyout_tbComments = $get("Flyout_tbComments");
	Flyout_tbComments.value = "Gotcha";
}
window.onresize = SetFlowplayerPos;
function SetFlowplayerPos()
{
    var videoPos = $get("video-pos"); 
    var desPos = Sys.UI.DomElement.getLocation(videoPos);
    var playerHolder = $get("flowplayerholder");
    Sys.UI.DomElement.setLocation(playerHolder, desPos.x, desPos.y);
    playerHolder.style.display ="block";
    desPos = Sys.UI.DomElement.getLocation($get("comment-pos"));
    var infoComment = $get("info-comment");
    Sys.UI.DomElement.setLocation(infoComment, desPos.x, desPos.y);
    infoComment.style.display = "block";
    playerHolder.style.display = "block";
}