﻿var MSNVidCat = {
    AppendScriptToHead: function(id,src)
    {
        if(arguments.length == 2 && null != id && null != src && null != document.getElementsByTagName("head"))
        {
            if(null != document.getElementById(id))
            {
                var oldScript = document.getElementById(id);
                oldScript.parent.removeChild(oldScript);
            }
            
            var theScript = document.createElement("script");
            theScript.id = id;
            theScript.src = src;
            theScript.type = "text/javascript";
                        
            document.getElementsByTagName("head")[0].appendChild(theScript);
        }
    },
    VideoByUUID: {
        Get: function(uuid)
        {
            if(arguments.length == 1 && null != uuid)
            {
                var rand = Math.ceil(Math.random() * 4);        
            
                MSNVidCat.AppendScriptToHead(new String(uuid+"Script"),"http://edge"+rand+".catalog.video.msn.com/videoByUuids.aspx?uuids="+uuid+"&rct=3&responseEncoding=json&callBackName=MSNVidCat.VideoByUUID.Set");                        
            }
        },
        Set: function(data) 
        {
            if(null != data && null != data.video && null != data.video[0])
            {
                if(null != MSNVidCat.VideoByUUID.OnData)
                {
                    MSNVidCat.VideoByUUID.OnData(data.video[0]);
                }
            }     
        },           
        OnData: null
    } 
};