var imgPre="images";
var meetsReqs=true;
var indefli=false;
var serviceid=0;
var rpsub=false;
var pcontr=false;



function SF(func) { 
try { 
if(eval('window.' + func) != null) { 
return true; 
} else { 
return false; 
} 
} 
catch(e) { 
alert('Failed exec:'+code+'\r\n'+e.description); 
} 
return false; 
}
function GE(v) {	
if(document.all) { 
return document.all[v]; 
} 
return document.getElementById(v); 
}
window.name='mobile_content';



if(window.sdd){
sHS();
}


window.onunload = Rsn; 
function Rsn() {
window.name = 'mobile_content';
} 
if(SF('SetupRatings')) SOL(SetupRatings); 
if(SF('cklnch')) SOL(cklnch); 
if(SF('chkbb')) SOL(chkbb);






var isUserLoggedInEnv = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><IsUserLoggedIn xmlns=\"http://entertainment.msn.com/ns\" /></soap:Body></soap:Envelope>";
// login token
var LIT = "loginHereNow=1";
var SLIT = "secureHereNow=1";


function CheckWmp10()
{
    try
    {
        var ver = GetWmpVer();
        var idx = -1;
        
        if(ver != null && ver.length > 0)
            idx = ver.indexOf(".");

        if (idx != -1) 
        {
            var numVer = parseInt(ver.substr(0, idx));
            if (numVer >= 10) 
            {
                return true;
            }
        }
    }
    catch(e)
    {
    }
            
    return false;
}


// Clips in page code
var CurrentPlayImage;
var timeHandle = -1;
var skipFlag = 0;

function StopPlayer()
{
    if(GE('ClipPlayer') != null)
    {
        GE('ClipPlayer').controls.stop();
        GE('ClipPlayer').settings.setMode("loop", wmplp);
        GE('ClipPlayer').settings.setMode("shuffle", wmpsh);
    }
        
    if(CurrentPlayImage != null)
    {
        var item = CurrentPlayImage;

        var tmp = CurrentPlayImage.children[0].alt;
        tmp = tmp.replace("Stop", "Play");

        CurrentPlayImage.children[0].alt = tmp;
        
        CurrentPlayImage = null;
        clpot(item);
    }
}
function StopPlayerNow()
{
    skipFlag = 1;
    
    if(GE('ClipPlayer') != null)
    {
        GE('ClipPlayer').controls.stop();
        GE('ClipPlayer').settings.setMode("loop", wmplp);
        GE('ClipPlayer').settings.setMode("shuffle", wmpsh);
    }
}
function ClipPlayState(NewState)
{
    if(skipFlag == 1)
        return;
        
    if(timeHandle != -1)
    {
        window.clearTimeout(timeHandle);
        timeHandle = -1;
    }
    
    if(NewState == 3 && CurrentPlayImage != null)
    {
        CurrentPlayImage.children[0].isLoading = false;
        CurrentPlayImage.children[0].src = imgPre + "/bt_stop.gif";

        var tmp = CurrentPlayImage.children[0].alt;
        tmp = tmp.replace("Play", "Stop");

        CurrentPlayImage.children[0].alt = tmp;
    }
    
    if(NewState == 1)
        StopPlayer();
        
    if(NewState == 10 && CurrentPlayImage != null)
    {
        timeHandle = window.setTimeout(StopPlayer, 1000);
    }
}
function CreatePlayer(redir)
{
    if(GE('ClipPlayer') == null)
    {
        try
        {
            var doc = GE("clipSpan");

            var tag = '<object id="ClipPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="0" height="0">';
            tag += '<param name="autoStart" value="false">';
            tag += '<param name="uimode" value="invisible">';
            tag += '<param name="enableContextMenu" value="false">';
            tag += '</object>';
            tag += '<script for="ClipPlayer" event="PlayStateChange(NewState)" language="javascript">ClipPlayState(NewState);</script>';
            tag += '<script for="ClipPlayer" event="error()" language="javascript">StopPlayer();</script>';
            
            doc.innerHTML = tag;
            doc.style.display = 'none';
            
            var idx = -1;
            var ver = GE('ClipPlayer').versionInfo;

            if(ver != null && ver.length > 0)
            {
                idx = ver.indexOf(".");
            }
            else
            {
                throw "wrong version";
            }

            if(idx != -1 && parseInt(ver.substr(0, idx)) < 7)
            {
                throw "wrong version";
            }
        }
        catch(e)
        {
            if(redir == true)
                //location.href = "/help/requirements.aspx";
                
            return;
        }
    }
}

var wmplp = false;
var wmpsh = false;

function PlayClip(url, id)
{
    if(CurrentPlayImage.children[0]) 
    {
        CurrentPlayImage.children[0].isLoading = true;
        CurrentPlayImage.children[0].src = imgPre + "/bt_load.gif";
    }
    
    var cp = GE('ClipPlayer');
    if(cp == null)
    {
        CreatePlayer(true);
        cp = GE('ClipPlayer');
    }
    
    if(!CheckWmp10())
        window.onbeforeunload = StopPlayerNow;

    if(cp != null)
    {
        wmplp = cp.settings.getMode("loop");
        wmpsh = cp.settings.getMode("shuffle");
        cp.settings.setMode("loop", false);
        cp.settings.setMode("shuffle", false);
//alert(url);
        cp.URL = url;
        cp.controls.play();
    }
}

function clpot(item)
{
	//alert(item);
    if(item == CurrentPlayImage)
    {
        if(CurrentPlayImage.children[0].isLoading != true)
            CurrentPlayImage.children[0].src = imgPre + "/bt_stop.gif";
    }
    else if(item.children[0])
        item.children[0].src = imgPre + "/bt_play.gif";
}

function clpup(item, id)
{
    if(event != null && event.button > 1)
        return;

    if(item.clipid == null)
    {
        var len = document.all.length;
        var fnd = false;
        
        for(var x = 0; x < len; x++)
        {
            var ele = document.all[x];
            
            if(ele.tagName.toLowerCase() == "a" && ele.clipid == id)
            {
                item = ele;
                fnd = true;
                break;
            }
        }
        
        if(fnd == false)
            return;
    }
    
    if(item == CurrentPlayImage)
    {
        var tmp = CurrentPlayImage.children[0].alt;
        tmp = tmp.replace("Stop", "Play");

        CurrentPlayImage.children[0].alt = tmp;

        GE('ClipPlayer').controls.stop();
        GE('ClipPlayer').settings.setMode("loop", wmplp);
        GE('ClipPlayer').settings.setMode("shuffle", wmpsh);

        CurrentPlayImage = null;
        clpot(item);
        
        return;
    }
    
    if(CurrentPlayImage != null)
    {
        var tmp = CurrentPlayImage;
        var tmps = CurrentPlayImage.children[0].alt;
        tmps = tmps.replace("Stop", "Play");

        GE('ClipPlayer').settings.setMode("loop", wmplp);
        GE('ClipPlayer').settings.setMode("shuffle", wmpsh);

        CurrentPlayImage.children[0].alt = tmps;
        CurrentPlayImage = null;
        clpot(tmp);
    }

    CurrentPlayImage = item;
    clpot(item);
    PlayClip(item.clipurl, id);
}

