var player;
var currentclip;
var FlashBlock;


//For postbacks where the return value don't matter (EG: Views)
//Warning: IE caches like a mofo - attach a random
function DoPostback(URL)
{
    xmlhttp = null;
    //Check different ajax possibilities for differnet browsers
    
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    
    if (xmlhttp == null)
    {
        xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }
    
    try
    {
        xmlhttp.open("GET",URL,true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Connection", "close");
        xmlhttp.send("");
    }
    catch(e)
    {
        alert(e);
        //So what? I can't do anything
    }
}

function onFlowPlayerReady()
{
    if(document.getElementById("FlashBlock0") != null)
	    player = document.getElementById("FlashBlock0")
    else if(document.getElementById("FlashBlock1") != null)
	    player = document.getElementById("FlashBlock1")
	else if (document.getElementById("FlashBlock2") != null)
	    player = document.getElementById("FlashBlock2")
	else if (document.getElementById("FlashBlock3") != null)
	    player = document.getElementById("FlashBlock3")
	else if (document.getElementById("FlashBlock4") != null)
	    player = document.getElementById("FlashBlock4")
	else if (document.getElementById("FlashBlock5") != null)
	    player = document.getElementById("FlashBlock5")
}

function AddCues()
{
	player.addCuePoints([
	   { name: 'viewevent', time: 5 }
	]);
}

function onCuePoint(cuePoint)
{
    //Match the main clip only and get the id's from it
    var matches = currentclip.name.match('main,([0-9]+),([0-9]+)')
	if (matches.length == 3)
	{
		DoPostback('/flash/LogEvent.ashx?mid=' + matches[1] + "&aid=" + matches[2] + "&time=" + (new Date().getTime()));
	}
}

function onClipChanged(clip)
{
	currentclip = clip;
	AddCues();
}

function onPlay(clip)
{
    currentclip = clip;
    AddCues();
}