// prints milb headlines from array
function milbHeadlines(numHeads) {
    if (!headlines) { return ; }
    if (headlines[0]) { 
        document.write('<ul class=\"headlines\">');
        for (i=0; i<numHeads; i++) {
            if (headlines[i]) {
                document.write('<li>' + headlines[i] + '</li>');
            }
        }
        document.write('</ul>');
    }
}

function writeSelect(arr, name, onchange, cssClass, initialElementlabel, selectedValue) {
    var d=document;
    d.writeln("<select onchange=\""+onchange+"\" class=\""+cssClass+"\" name=\""+name+"\">");
    if (initialElementlabel!=null) {
        d.writeln("<option value=\"\">"+initialElementlabel+"</option>");
    }
    if (name=="clubs") {
        d.writeln("<option value=\"\" disabled>----------</option>");
        d.writeln("<option value=\"/app/milb/info/affiliations.jsp\">By Affiliation</option>");
        d.writeln("<option value=\"/app/milb/info/classifications.jsp\">By Class</option>");
        d.writeln("<option value=\"/app/milb/info/geographical.jsp\">By Geography</option>");
        d.writeln("<option value=\"\" disabled>----------</option>");
    }
    
    for (var i=0; i<arr.length; i++) {
        d.writeln("<option "+(selectedValue!=null && arr[i][0]==selectedValue?"selected":"")+" value=\""+arr[i][0]+"\">"+arr[i][1]+"</option>");
    }
    d.writeln("</select>");
}

function getClubPage(selectObj) {
    if (selectObj.options[selectObj.selectedIndex].value!="") {
        if (selectObj.options[selectObj.selectedIndex].value.indexOf("/")!=0) {
            location.href="/app/clubs/index.jsp?cid="+selectObj.options[selectObj.selectedIndex].value;
        }
        else {
            location.href=selectObj.options[selectObj.selectedIndex].value;
        }
    }
    else {
        selectObj.selectedIndex=0;
    }
}

function getLeaguePage(selectObj) {
    if (selectObj.options[selectObj.selectedIndex].value!="") {
        if (selectObj.options[selectObj.selectedIndex].value.indexOf("/")!=0) {
            location.href="/app/leagues/index.jsp?lid="+selectObj.options[selectObj.selectedIndex].value;
        }
        else {
            location.href=selectObj.options[selectObj.selectedIndex].value;
        }
    }
    else {
        selectObj.selectedIndex=0;
    }
}

function sortDropdown(a,b) { 	 
     // sort VSL/DSL to bottom of team list only 	 
     if (a[0].substring(0,1) == "t") { 	 
         if (properties.clubs[a[0]].league_id == "l130") { return 1 }; 	 
         if (properties.clubs[a[0]].league_id == "l134") { return 1 }; 	 
         if (properties.clubs[b[0]].league_id == "l130") { return -1 }; 	 
         if (properties.clubs[b[0]].league_id == "l134") { return -1 }; 	 
     } 	 
     // otherwise sort by name 	 
     if (a[1] > b[1]) { return  1 }; 	 
     if (a[1] < b[1]) { return -1 }; 	 
     return 0; 	 
}

if (MPlayer) { 
    MPlayer.preLaunch = function(o){
        
        var arl_w_video = "mms://a1272.v10869.g.vm.akamaistream.net/7/1272/10869/v0001/mlb.download.akamai.com/10869";
        var arl_w_audio = "mms://a1272.v10869.g.vm.akamaistream.net/7/1272/10869/v0001/mlb.download.akamai.com/14668";
        var live_arl_w  = "mms://a1503.l10869[PORT].c10869.g.lm.akamaistream.net/D/1503/10869/v0001/reflector:[PORT]";
        
        if( o["w"] && o["w"].indexOf("reflector:")>-1 ){
            var reflector = o.w.match(/reflector\:(\d{5})/);
            var url = live_arl_w.replace(/\[PORT\]/g, reflector[1]);
            o.w = url;
        } else if ((o.w) && (o.w.indexOf("://")<0)) {   // if we have url w/o a server in the path add on the 'magic string'!
            if (o.type) { 
                if (o.type == "v_free") { o.w = arl_w_video + o.w; }
                if (o.type == "a_free") { o.w = arl_w_audio + o.w; }
            } 
        }
        return true;
        
    }
}


