if(!window.Msn){window.Msn={};} 
if(!window.Msn.VideoSL){window.Msn.VideoSL={};}
Msn.VideoSL.Inline=function(id)
{
    var that=this,t=id+"_t",p=id+"_p",m=id+"_m",a=id+"_a",pobj=id+"_pobj",events,timeout,loaded;
    this.Build=function(v,w,h,src,props,evts)
    {
        that.BuildLayout();
        that.BuildPlayer(v,w,h,src,props,evts);
    }
    this.BuildLayout=function()
    {
        var el=document.getElementById(id);
        if(el)
        {
            el.innerHTML='<div class="video1"><h3 id="'+t+'"></h3><div id="'+p+'"></div><div id="'+m+'"></div><div id="'+a+'"></div></div>';
        }
    }
    this.BuildPlayer=function(v,w,h,src,props,evts)
    {
        var vs={ifs:"true",playlistmin:"2"},i; for(i in v)vs[i]=v[i]; v=[];
        for(i in vs)if(vs[i])v.push(i+"="+vs[i].replace(/,/g,"%2C")); v=v.join(",");
        var properties={
            width: w?w:300,
            height: h?h:269,
            background: "black",
            framerate: "30",
            version: "2.0.31005",
            enableHtmlAccess: "true"};
        for(var x in props) properties[x] = props[x];
        events = evts;
        var ex={
            source: (src?src:"http://msnvideofr.vo.llnwd.net/d1//special/sl/js/inline.xap"),
            parentElement: document.getElementById(p),
            id: pobj, 
            properties: properties,
            events: {onLoad: that.OnLoad, onError: that.OnError},
            initParams: v,
            context: null};
        Silverlight.createObjectEx(ex);
        timeout = setTimeout(that.OnLoad, 100);
    }
    this.OnLoad=function(s,c,src)
    {
        if(timeout != null)
        {
            clearTimeout(timeout);
            timeout = null;
        }
        var obj = document.getElementById(pobj);
        if(obj != null && obj.IsLoaded)
        {
            if(!loaded)
            {
                loaded = true;
                var il=obj.Content.Inline;
                il.addEventListener("PropertyChanged", onIPC);
                st(il.Title);
                sb(il.Banner);
                sl(il.Links);
                if(events != null && typeof events.onLoad == "function")
                    events.onLoad(s,c,src);
            }
        }
        else
        {
            timeout = setTimeout(that.OnLoad, 100);
        }
    }
    this.OnError=function(s, args)
    {
        if(events!=null && typeof events.onError == "function")
            events.onError(s, args);
    }
    function onIPC(s,d)
    {
        var n=d.PropertyName,v=d.PropertyValue;
        if(n=="Title") st(v);
        if(n=="Banner") sb(v);
        if(n=="Links") sl(v);
    }
    function st(v)
    {
        var el=document.getElementById(t);
        if(el)el.innerHTML=(v==null)?"":v;
    }
    function sb(v)
    {
        var el=document.getElementById(a);
        if(el)el.innerHTML=(v==null)?"":'<a class="ad" href="'+v.Target+'" target="_blank"><img src="'+v.Image+'" width="300" height="60"></a>';
    }
    function sl(v)
    {
        var el=document.getElementById(m),c,css,s="";
        if(el)
        {
            for(c=0;v!=null&&c<=v.length-1;c++)
            {
                css=(c==v.length-1)?"linkback last":"linkback";
                s+='<a class="'+css+'" href="'+v[c].Uri+'" target="_blank">'+v[c].Value+'</a>';
            }
            el.innerHTML=s;
        }
    }
};
