/**
 * vxFlashPlayer.js 
 *
 * Helper functions for ROO Media Player
 *
 * (c) 2007 ROO Group
 *
 */

/**
 *	Get WindowURL on HTML Layer,
 *	On Blog's Layer, this is not yet working.
 */
function getWindowURL()
{
	var sWindowLocation = window.location;
	return sWindowLocation;
}

 
function vxLoadIMU(sURL)
{
	var IMUDiv = document.getElementById("vxFlashPlayerSyncIMUFrame");
	if( IMUDiv != null ) 
	{
		IMUDiv.innerHTML = '<iframe src="' + sURL + '" id="vxFlashPlayerIMUContent" class="vxFlashPlayerIMUContent" scrolling="no" border="0" frameborder="0" marginheight="0" marginwidth="0" noresize"></iframe>';
		IMUDiv.style.display = "block";
	}
}

function vxLoadStaticIMU(sURL)
{
	var IMUDiv = document.getElementById("vxFlashPlayerStaticIMUFrame");
	if( IMUDiv != null ) 
	{
		IMUDiv.innerHTML = '<iframe src="' + sURL + '" id="vxFlashPlayerStaticIMUContent" class="vxFlashPlayerIMUContent" scrolling="no" border="0" frameborder="0" marginheight="0" marginwidth="0" noresize"></iframe>';
		IMUDiv.style.display = "block";
	}
}

function vxCloseIMU()
{
	var IMUDiv = document.getElementById("vxFlashPlayerSyncIMUFrame");
	if( IMUDiv != null ) 
	{
		IMUDiv.style.display = "none";
		IMUDiv.innerHTML = "";
	}
}

/**
 * Shows or Hides all IMUs.  This is used during Fullscreen operation.
 */
function vxShowIMU(bShow)
{
	var sVisibility = bShow ? "visible" : "hidden";
	var IMUDiv = document.getElementById("vxFlashPlayerSyncIMUFrame");
	if( IMUDiv != null ) 
	{
		IMUDiv.style.visibility	= sVisibility;
	}
	var staticIMUDiv = document.getElementById("vxFlashPlayerStaticIMUFrame");
	if( staticIMUDiv != null ) 
	{
		staticIMUDiv.style.visibility	= sVisibility;
	}
}

function vxSetPlayerSize(w, h)
{
	var vxp = document.getElementById("vxFlashPlayerContent");
	vxp.style.width = w + 'px';
	vxp.style.height = h + 'px';			
	
	// call our client initialization callback (if it exists) to let our client know that the vxFlashPlayer has beed loaded.
	if( typeof(vxClientInitialize) == "function" ) 
	{
		vxClientInitialize();
	}
}


function vxSetIMUSizeAndPosition(x, y, w, h)
{
	vxSetSizeAndPosition(document.getElementById("vxFlashPlayerSyncIMUFrame"), x, y, w, h);	
	vxSetSizeAndPosition(document.getElementById("vxFlashPlayerStaticIMUFrame"), x, y, w, h);
	
	// save our IMU position so that we can recalculate when browser window resizes
	_vxIMUPos_x = x;
	_vxIMUPos_y = y;
}


/**
 * Sets an objects position relative to vxFlashPlayerContent div.
 */
function vxSetSizeAndPosition(obj, x, y, w, h)
{
	if( obj != null ) 
	{
		var baseCoords = vxFindPos(document.getElementById("vxFlashPlayerContent"));
		obj.style.left = (baseCoords[0]+x) + 'px';
		obj.style.top = (baseCoords[1]+y) + 'px';
		obj.style.width = w + 'px';
		obj.style.height = h + 'px';			
	}
}

/**
 * Returns the page position of an object
 */
function vxFindPos(obj) {
	var curleft = 0;
	var curtop 	= 0;

	if (obj.offsetParent) {
		if( !(g_vxIEOffsetFix && vxIsMSIE()) ) 
		{
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
		}
		//while (obj = obj.offsetParent) {
		//	curleft += obj.offsetLeft;
		//	curtop += obj.offsetTop;
		//}
	}
	
	return [curleft,curtop];
}

/**
 * Callback for window.onresize event
 */
function vxOnResize()
{
	vxRepositionIMUs();
}

function vxRepositionIMUs()
{
	var newPos = vxFindPos(document.getElementById("vxFlashPlayerContent"));
	
	var IMUDiv = document.getElementById("vxFlashPlayerSyncIMUFrame");
	if( IMUDiv != null ) 
	{
		IMUDiv.style.left = (newPos[0]+_vxIMUPos_x) + 'px';
		IMUDiv.style.top = (newPos[1]+_vxIMUPos_y) + 'px';
	}	
	
	var staticIMUDiv = document.getElementById("vxFlashPlayerStaticIMUFrame");
	if( staticIMUDiv != null ) 
	{
		staticIMUDiv.style.left = (newPos[0]+_vxIMUPos_x) + 'px';
		staticIMUDiv.style.top = (newPos[1]+_vxIMUPos_y) + 'px';
	}	
}

function openFullscreenPlayer(siteId,channel,clipId,volume,bitrate)
{
	window.open("vxFullscreen.aspx?vxSiteId="+siteId+"&vxChannel="+channel+"&vxClipId="+clipId+"&vxVolume="+volume+"&vxBitrate="+bitrate,"rooFullscreen","fullscreen","true");
}

function vxGetPlayer()
{
	return vxIsMSIE() ? window['vxFlashPlayerEmbed'] : document['vxFlashPlayerEmbed'];
}

function vxIsMSIE()
{
	return navigator.userAgent.indexOf("MSIE") != -1;
}

// position of IMUs.  Values are set via a call to vxSetIMUSizeAndPosition from Flash and they are saved to that
// we can correctly reposition IMUs when the browser window resizes.
var _vxIMUPos_x = 0;
var _vxIMUPos_y = 0;

// Call back to our parent
vxMain();
