function convert(inTitle) { cmCreateConversionEventTag("Document Download", "2", inTitle, "10"); }
cmSetProduction();
cmCreatePageviewTag(document.title, "Media Microsite", null);

var fullLength = 0;            // the full length of the video in seconds
var lengthWatched = 0;         // the length of the video watched before a stop/rewind/page exit
var shownComplete = false;
var started = false;
var avTitle = "";
function updateWatching(inTitle, inFullLength, inSecondsWatched)
{
    avTitle = inTitle;
    fullLength = inFullLength;
    lengthWatched = inSecondsWatched;
 //   window.status = inTitle + ", " + inFullLength + ", " + inSecondsWatched;
    if((!isNaN(fullLength))&&(!isNaN(lengthWatched)))
    {

        if(parseFloat(fullLength) > 10) {
            if((parseFloat(fullLength) < (parseFloat(lengthWatched) + 5))&&(!shownComplete))
            {
                doComplete();
            }
        }
        if(!started)
        {
            cmCreatePageElementTag(avTitle, "Audio and Video", "-_--_--_--_--_--_--_--_--_--_--_--_-0-_-0-_-" + Math.round(parseFloat(fullLength)));
            started = true;
        }
    }
}
function doComplete()
{
    shownComplete = true;
    lengthWatched = fullLength;
    sendCMElement(3);
}
function sendCMElement(inType)
{
        cmCreatePageElementTag(avTitle, "Audio and Video", "-_--_--_--_--_--_--_--_--_--_--_--_-" + inType + "-_-" + Math.round(parseFloat(lengthWatched)) + "-_-" + Math.round(parseFloat(fullLength)));
}
function videoEvent(inEvent)
{

    if(inEvent == "play") 
    {
        sendCMElement(2);
        shownComplete = false;
    }
    if(inEvent == "stop") sendCMElement(1);
    if(inEvent == "pause") sendCMElement(1);
    if(inEvent == "rewind")
    {
        lengthWatched = "0";
        sendCMElement(0);
    }
}
function sendVideoDetails()
{
    // sends coremetrics details about length of video watched.
    if((!shownComplete)&&(started)) {
		sendCMElement(1);
	}
}
// onunload
window.onunload = sendVideoDetails;
