function ShowVideoPlayer(pointX,pointY,ptWidth,ptHeight,hideAnyway)
{
	hideAnyway = (typeof(hideAnyway)=="undefined")? false:hideAnyway;
	
	var divID = document.getElementById("divOCX");
	VP.width = ptWidth;
	VP.height = ptHeight;
	divID.style.position = "absolute";
	divID.style.left=pointX;
    divID.style.top=pointY;
	divID.style.width = ptWidth;
	divID.style.height = ptHeight;
	if(hideAnyway)
	{
		divID.style.display ="none";
	}
	else
	{
		divID.style.display ="block";	
	}
}

function DisplayVideoPlayer()
{
	var divID = document.getElementById("divOCX");
	divID.style.display ="block";
}

function HideVideoPlayer()
{
	var divID = document.getElementById("divOCX");
	divID.style.display ="none";
}

function GetCurrentChannel()
{
	return VP.CurrentChannel;
}

function SetCurrentChannel(channel)
{
	if(channel<0)
	{
		return;
	}
	VP.CurrentChannel = channel;
}

function SetFullScreenFlag(flag)
{
	VP.FullScreenEnabled = flag;
}

function SetDBClickFlag(flag)
{
	VP.DBClickEnabled = flag;
}

function SetPicInPic(enable)
{
	VP.SetPicInPic = enable;
}
function GetNumConnected(maxChannel)
{
	var nNum = 0;
	for(var i=0;i<maxChannel;i++)
	{
		VP.IsConnected(i)
		{
			nNum++;
		}
	}
	return nNum;
}

function MotionRectAddedCallback(channel, rectInfo)
{
	thisMovie("AppLoader").motionRectAddedCallback(channel, rectInfo);
}

function AddMotionRectCallback()
{
	try
	{
		VP.attachEvent("MotionRectAdded", MotionRectAddedCallback);	
	}
	catch(error)
	{
		if(error instanceof TypeError)
		{
			thisMovie("AppLoader").onBlocked();
		}
	}
}

function RemoveMotionRectCallback()
{
	VP.detachEvent("MotionRectAdded", MotionRectAddedCallback);	
}

function AddPreviewCallback()
{
	try
	{
		VP.attachEvent("ChannelSwitched",onChannelSwitched);
		VP.attachEvent("ChannelConnected",onChannelConnected);
		VP.attachEvent("ChannelDisconnected",onChannelDisconnected);
		VP.attachEvent("ScreenModeChanged",onScreenModeChanged);
		
		
		VP.PicInPic = 1;
		for(i=0;i<4;i++)
		{
			VP.SetPipChildren(i,1);
		}
	}
	catch(error)
	{
		if(error instanceof TypeError)
		{
			return false;
		}		
	}
	
	return true;
}

function RemovePreviewCallback()
{
	VP.detachEvent("ChannelSwitched",ChannelSwitched);
	VP.detachEvent("ChannelConnected",ChannelConnected);
	VP.detachEvent("ChannelDisconnected",ChannelDisconnected);
}

//通知AS当前通道已改变	  
function onChannelSwitched(Channel)
{
	thisMovie("AppLoader").onChannelSwitch(Channel);
}

function onChannelConnected(Channel)
{
	thisMovie("AppLoader").onChannelConnected(Channel);	
}

function onChannelDisconnected(Channel)
{
	thisMovie("AppLoader").onChannelDisconnected(Channel);		
}

function onScreenModeChanged()
{
	thisMovie("AppLoader").onScreenModeChanged();		
}

function MoveVideoPlayer(pointX,pointY,ptWidth,ptHeight)
{
	var divID = document.getElementById("divOCX");
	VP.width = ptWidth;
	VP.height = ptHeight;
	divID.style.left=pointX;
	divID.style.top=pointY;
	divID.style.width = ptWidth;
	divID.style.height = ptHeight;
}

function HideVideoScheme()
{
	var divID = document.getElementById("divOCX");
	divID.style.display ="none";
}

function SetMode(nChannel, strMode)
{
	if(VP.IsConnected(nChannel))
	{
		VP.Disconnect(nChannel);
	}
	VP.SetMode(nChannel, strMode);
}

function SetScreenMode(nScreenMode)
{
	VP.ScreenMode = nScreenMode;
}

function GetScreenMode()
{
	return VP.ScreenMode;
}

function SwitchSingleScreen()
{
	VP.SwitchSingleScreen();	
}

function SwitchFullScreen()
{
	VP.SwitchFullScreen();	
}

function Connect(localChannel,remoteChannel,useProxy)
{
	var bRet = false;
	if(VP.IsConnected(localChannel))
	{
		VP.Disconnect(localChannel);
	}
	if(useProxy)
	{
		bRet = VP.ConnectProxy(localChannel,g_Address,g_Port,remoteChannel,g_Username,g_Password);
	}
	else
	{
		bRet = VP.Connect(localChannel,g_Address,g_Port,remoteChannel,g_Username,g_Password);				
	}
	return bRet;
}

function SetProxy(localChannel,proxyAddress, proxyMessagePort)
{
	localChannel = (typeof(localChannel)=="undefined")?VP.CurrentChannel:localChannel; 
	return VP.SetProxy(localChannel, proxyAddress, proxyMessagePort);
}

function IsConnected(localChannel)
{
	return VP.IsConnected(localChannel);	
}

function IsServerChannelConnected(remoteChannel)
{
	return VP.IsServerChannelConnected(g_Address,g_Port,remoteChannel);
}

function Disconnect(localChannel)
{
	VP.Disconnect(localChannel);
}

function DisconnectAll()
{
	VP.DisconnectAll();
}

function AddMotionRect(localChannel, rectArray, sentryCurrentArea)
{
	VP.ClearMotionRectArray(localChannel);
	for(var i = 0; i < rectArray.length; i++)
	{
		VP.AddMotionRect(localChannel, rectArray[i].Areas);
	}
}

function SetCurrentMotionRect(localChannel, sentryCurrentArea)
{
	VP.SetCurrentMotionRect(localChannel, sentryCurrentArea);
}

function DeleteMotionRect(localChannel)
{
	var nCurrent = parseInt(VP.RemoveMotionRect(localChannel));	
	return nCurrent;	
}

function NextMotionRect(localChannel)
{
	var nIndex = VP.NextMotionRect(localChannel);
	return nIndex;
}

function ClearMotionRect(localChannel)
{
	VP.ClearMotionRectArray(localChannel);
}

function SetCurrentBrightness(localChannel, value)
{
	return VP.SetCurrentBrightness(localChannel, value);
}

function GetCurrentBrightness(localChannel)
{
	return VP.GetCurrentBrightness(localChannel);
}

function GetCurrentContrast(localChannel)
{
	return VP.GetCurrentContrast(localChannel);
}

function SetCurrentContrast(localChannel, value)
{
	return VP.SetCurrentContrast(localChannel, value);
}

function GetCurrentSaturation(localChannel)
{
	return VP.GetCurrentSaturation(localChannel);
}

function SetCurrentSaturation(localChannel, value)
{
	return VP.SetCurrentSaturation(localChannel, value);
}

function GetCurrentHue(localChannel)
{
	return VP.GetCurrentHue(localChannel);
}

function SetCurrentHue(localChannel, value)
{
	return VP.SetCurrentHue(localChannel, value);
}

function GetAudioVolume()
{
	return VP.GetAudioVolume();	
}

function SetAudioVolume(value)
{
	VP.SetAudioVolume(value);
}

function SetMuteStatus(status)
{
	VP.AudioEnabled = status;	
}

function GetDefaultVideoParams(localChannel)
{
	return {brightness:VP.GetDefaultBrightness(localChannel), 
			contrast:VP.GetDefaultContrast(localChannel), 
			saturation:VP.GetDefaultSaturation(localChannel), 
			hue:VP.GetDefaultHue(localChannel)};
}

function Snapshot()
{
	VP.Snapshot(VP.CurrentChannel, 1, "");
}

function Download()
{
	VP.Download(g_Address,g_Port,g_Username,g_Password);
}

function Playback()
{
	VP.PlayBack();	
}

function IsRecording(channel)
{
	return VP.IsRecording(channel);
}

function StartRecord(channel)
{
	return VP.StartRecord(channel);
}

function StopRecord(channel)
{
	return VP.StopRecord(channel);
}

function AddPlaybackCallback()
{
	try
	{
		VP.attachEvent("EndStream",onEndStream);
		VP.attachEvent("ChannelSwitched",onChannelSwitched);		
		VP.PicInPic = 0;
	}
	catch(error)
	{
		if(error instanceof TypeError)
		{
			return false;
		}		
	}
	
	return true;
}

function onEndStream(localChannel, isError)
{
	thisMovie("AppLoader").onEndStream(localChannel, isError);
}

function ConnectFile(localChannel, remoteChannel, strFileName, position)
{
	return VP.ConnectFile(localChannel,  g_Address, g_Port, remoteChannel, strFileName, position, g_Username, g_Password);
}

function GetRate(localChannel)
{
	return VP.GetRate(localChannel);
}

function RateDown(localChannel) 
{
	VP.RateDown(localChannel);	
}

function RateUp(localChannel)
{
	VP.RateUp(localChannel);	
}

function GetPosition(localChannel)
{
	return VP.GetRSPosition(localChannel);
}

function Pause(localChannel)
{
	VP.Pause(localChannel);	
}

function Resume(localChannel)
{
	VP.Resume(localChannel);
}

function GetServerPBInfo()
{
	return VP.GetServerPBInfo(g_Address, g_Port, g_Username, g_Password);
}
