﻿function thisMovie(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[movieName];
	}
	else
	{
		return document[movieName];
	}
}

function changeSubChannel(value)
{
	//TODO jQuery?
	if(document.getElementById("FlashContent").sectionChange)
	{
		document.getElementById("FlashContent").sectionChange("#" + value);
	}
}

var _loadAssetTerval;
var _assetAry;
var _currentAssetID;

function loadAsset(assetsAry, currentAssetID)
{
	_assetAry = assetsAry;
	_currentAssetID = currentAssetID;
	_loadAssetTerval = setInterval(assetInterval, 500);
}

function assetInterval()
{
	if(document.getElementById("FlashContent"))
	{
		var result = -1;
		
		if(document.getElementById("FlashContent").loadAsset)
		{
			result = document.getElementById("FlashContent").loadAsset(_assetAry, _currentAssetID);
		}
		
		if(result != -1)
		{
			clearInterval(_loadAssetTerval);
		}
//		console.log("	Result: " + result);
//		console.log("	Array lenght: " + _assetAry.length);
	}
}

function changeMultiMediaItem(itemID)
{
	//alert(itemID);
	var itemName = $("img[assetItemID='"+itemID+"']").attr("id");
	if(itemName.length > 0)
	{
		var aryName = $("img[assetItemID='"+itemID+"']").attr("assetArray");
		AssetClick("MediaAsset" + itemID, aryName);
	}	
}

function showCarousel()
{
	//TODO jQuery?
	document.getElementById("FlashContent").showCarousel();
}

function showThumbnails()
{
	//TODO jQuery?
	document.getElementById("FlashContent").showThumbnails();
}

//This is called from Flash, chaning the hash should result
//in function PageChange begin called
function SectionChange(value)
{
    if (value.substring(0,4).toLowerCase() == 'http')
   	{
	    clearInterval(_timerID);
	    window.location = value;
    }
    else
    {
	    document.location.hash = value;
    }
}

var flashHeight = -1;
var targetSize = 100;
var flashReszieIncrement = 10;
var flashResizeIntervalDuration = 20;
var flashResizeTerval;

function updateFlashSize()
{
	//Determine if we're growing or shrinking
	if(flashHeight > targetSize)
	{
		flashHeight = flashHeight - flashReszieIncrement;
	}
	else
	{
		flashHeight = flashHeight + flashReszieIncrement;
	}
	
	//If we're close just stop
	if(Math.abs(flashHeight - targetSize) < flashReszieIncrement)
	{
		flashHeight = targetSize;
		clearInterval(flashResizeTerval);
	}
	
	//Update
	$("#FlashContent").height(flashHeight);
}

function animateFlashArea(targetHeight)
{	
	/*
	
	TO CONFIRM: Flash stays the same size.  Html columns are layered on top.
	
	if(targetHeight)
	{
		if(flashHeight < 0)
		{
			flashHeight = $("#FlashContent").height();
		}
		if(flashHeight != targetHeight)
		{
			targetSize = targetHeight;
			clearInterval(flashResizeTerval);
			flashResizeTerval = setInterval(updateFlashSize, flashResizeIntervalDuration);
		}
	}
	*/
}

function FlashDragToShare(itemID)
{
	//TODO
	//alert(itemID);	
}

function MultiMediaLoad(itemHeight)
{
    ContentAreaAnimateTop(itemHeight, function(){})
	//alert(itemHeight);
}
