document.write("<script type='text/javascript' src='http://mediasuite.multicastmedia.com/templates/js/swfobject.js'></script>");

function getLinkUrl ( strLink ) {
    var strLinkUrl = '';
    strLinkUrl = strLink.replace('/royce_web/','/');
    if (strLinkUrl.search(/.asp/) < 0){
        strLinkUrl = strLinkUrl + '.asp';
    }
    return strLinkUrl;
}

function toggleTab(szDivID, tabID, istyle) // 1 visible, 0 hidden
{
        var obj = document.getElementById(szDivID);
        var objtabl = document.getElementById(tabID);
        obj.style.backgroundColor = istyle;
}

function embedCode(vid_id, width, height)
{   
        //alert(video_hide_id);
        
         var curtextval = document.getElementById("videoembed");
         var setbgcolor = document.getElementById("vid_"+ vid_id );
         var setbgcolormain = document.getElementById("vid_"+ video_hide_id );
         
        
        if ( (video_hide_id != 0) && (video_hide_id != vid_id) ) {
                setbgcolormain.style.backgroundColor = "#ffffff";
        }
        
        video_hide_id = vid_id;

        setbgcolor.style.backgroundColor = "#e9f1f7";
        //setbgcolor.style.visibility = "hidden";
        //setbgcolor.style.display = "none";
            
        var sethid1 = document.getElementById("img_"+ vid_id );
            //sethid1.style.visibility = "hidden";
            //sethid1.style.display = "none";
        var sethid2 = document.getElementById("extra_"+ vid_id );
            //sethid2.style.visibility = "hidden";
            //sethid2.style.display = "none";

        curtextval.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width='" +width  + "' height='" +height  + "'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id="+vid_id+"&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id="+vid_id+"\
&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='" +width  + "' height='" +height  + "'></embed></object>"; 


}

function isiPad(){
    return ((navigator.platform.indexOf("iPad") != -1) || (navigator.platform.indexOf("iPhone") != -1));
}

function embedDelveCode(vid_id, chan_id, fullm_id, width, height)
{   
        var curtextval = document.getElementById("videoembed");
        //curtextval.innerHTML = "<object width='" + width + "' height='" + height + "' id=\"delve_player611817o\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"transparent\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashvars\" value=\"mediaId=" + vid_id +"&amp;channelId=" + chan_id + "&amp;playerForm=8bdb35f29c22449c9a93ccc2a87512bd\"/><embed src=\"http://assets.delvenetworks.com/player/loader.swf\" name=\"delve_player273703e\" wmode=\"transparent\" width='" + width + "' height='"+ height + "' allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"mediaId=" + vid_id + "&amp;channelId=" + chan_id + "&amp;playerForm=8bdb35f29c22449c9a93ccc2a87512bd\"></embed></object>"; 

 
    if(isiPad()){
        vid_id = vid_id;
        if (vid_id != '') {
            chan_id = '';
        }
        else {
            vid_id = fullm_id;
        }
    }
        
        
        document.write("<script src=\"http://assets.delvenetworks.com/player/embed.js\"></script><span class=\"LimelightEmbeddedPlayer\"><object type=\"application/x-shockwave-flash\" id=\"limelight_player_419264\" name=\"limelight_player_419264\" wmode=\"transparent\" class=\"LimelightEmbeddedPlayerFlash\" width='" + width + "' height='" + height + "'  data=\"http://assets.delvenetworks.com/player/loader.swf\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"transparent\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashVars\" value=\"deepLink=true&amp;mediaId=" + vid_id + "&amp;channelId=" + chan_id + "&amp;playerForm=6cd6683dc05443a2bfdb7f09ea8bba7f\"/></object></span><script>LimelightPlayerUtil.initEmbed('limelight_player_419264');</script>"); 
        
}


function embedDelveCodeMore()
{   
        var curtextval = document.getElementById("videoembedmore");
        curtextval.innerHTML = "<script src=\"http://assets.delvenetworks.com/player/embed.js\"></script><span class=\"LimelightEmbeddedPlayer\"><object type=\"application/x-shockwave-flash\" id=\"limelight_player_419264\" name=\"limelight_player_419264\" class=\"LimelightEmbeddedPlayerFlash\" width='480' height='321'  data=\"http://assets.delvenetworks.com/player/loader.swf\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"window\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashVars\" value=\"autoplay=false&amp;deepLink=true&amp;mediaId=&amp;channelId=73aa960647c245d8852d1ac756dafb55&amp;playerForm=6cd6683dc05443a2bfdb7f09ea8bba7f\"/></object></span><script>LimelightPlayerUtil.initEmbed('limelight_player_419264');</script>"; 
        
}

function embedKitCode(vid_id, chan_id, width, height)
{   
        var video_uuid = get_url_parse('video_uuid');
        var cat_id = get_url_parse('catid');
        var playerDiv = document.getElementById("videoembed").style;
        playerDiv.display = "inline";
        var so = new SWFObject("http://mediasuite.multicastmedia.com/templates/CUSTOM-LEGG-ROYCE-480-CAT-VT-NARROW-WS.swf", "live_player", width, height, "9", "#FFFFFF");
        so.addVariable("projectuuid", chan_id);
        so.addVariable("programid", video_uuid);
        so.addVariable("programuuid", video_uuid);
        so.addVariable("categoryid", cat_id);
        so.addVariable("useCategory", "true");
        so.addVariable("quickLoad", "true");
        so.addVariable("gfToken", "");
        so.addVariable("loadingdomain", "http://mediasuite.multicastmedia.com");
        so.addVariable("serviceURL", "http://mediasuite.multicastmedia.com/services/index.php");
        so.addVariable("doResize", "false");
        so.addParam("allowFullScreen", "true");
        so.addParam("allowScriptAccess", "always");
        so.addParam("wmode", "transparent");
        so.addParam("quality", "high");
        so.addVariable("typePlayer", "vod");
        so.write("videoembed");

}

function embedKitCodeBio(vid_id, chan_id, width, height)
{   
        
        //return "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' id='Media Player' width='" + width + "' height='" + height + "'><param name='movie' value='http://mediasuite.multicastmedia.com/templates/V16-Legg-Mason.swf?ts=&projectid=76645&projectuuid="+ chan_id+ "&loadingdomain=http://mediasuite.multicastmedia.com&pagetype=&typePlayer=vod'/><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#FFFFFF' /><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><embed src='http://mediasuite.multicastmedia.com/templates/V16-Legg-Mason.swf?ts=&projectid="+ chan_id+ "&projectuuid=&loadingdomain=http://mediasuite.multicastmedia.com&pagetype=&typePlayer=vod' quality='high' bgcolor='#FFFFFF' width='" + width + "' height='" + height + "' allowFullScreen='true' name='Media Suite Flash Media Player' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer'  wmode=\"transparent\"/></object>";
        return "<div id=\"mediaSuitePlayer_"+ chan_id+ "\"></div><script type=\"text/javascript\" src=\"http://mediasuite.multicastmedia.com/templates/js/swfobject.js\"></script><script type=\"text/javascript\" src=\"http://mediasuite.multicastmedia.com/player.js.php?p="+ chan_id+ "&target=mediaSuitePlayer_"+ chan_id+ "\"></script>";
        

}


function embedDelveCodeBio(vid_id, chan_id, width, height)
{   
        
        //return "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' id='Media Player' width='" + width + "' height='" + height + "'><param name='movie' value='http://mediasuite.multicastmedia.com/templates/V16-Legg-Mason.swf?ts=&projectid=76645&projectuuid="+ chan_id+ "&loadingdomain=http://mediasuite.multicastmedia.com&pagetype=&typePlayer=vod'/><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#FFFFFF' /><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><embed src='http://mediasuite.multicastmedia.com/templates/V16-Legg-Mason.swf?ts=&projectid="+ chan_id+ "&projectuuid=&loadingdomain=http://mediasuite.multicastmedia.com&pagetype=&typePlayer=vod' quality='high' bgcolor='#FFFFFF' width='" + width + "' height='" + height + "' allowFullScreen='true' name='Media Suite Flash Media Player' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer'  wmode=\"transparent\"/></object>";
        /*return "<div id=\"mediaSuitePlayer_"+ chan_id+ "\"></div><script type=\"text/javascript\" src=\"http://mediasuite.multicastmedia.com/templates/js/swfobject.js\"></script><script type=\"text/javascript\" src=\"http://mediasuite.multicastmedia.com/player.js.php?p="+ chan_id+ "&target=mediaSuitePlayer_"+ chan_id+ "\"></script>";*/
        
        /*return "<object type=\"application/x-shockwave-flash\" id=\"limelight_player_348982\" name=\"limelight_player_348982\" class=\"LimelightEmbeddedPlayerFlash\" width=\""+ width+ "\" height=\""+ height+ "\" data=\"http://assets.delvenetworks.com/player/loader.swf\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"window\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashVars\" value=\"deepLink=true&amp;playerForm=9c2fd7bdeb4c452ca04e7645713a0563&amp;mediaId="+ vid_id+ "&amp;channelId="+ chan_id+ "\"/></object><script>LimelightPlayerUtil.initEmbed('limelight_player_348982');</script>";*/
        
        
        return "<object width=\"242\" height=\"268\" id=\"limelight_player_933169o\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"><param name=\"movie\" value=\"http://assets.delvenetworks.com/player/loader.swf\"/><param name=\"wmode\" value=\"transparent\"/><param name=\"allowScriptAccess\" value=\"always\"/><param name=\"allowFullScreen\" value=\"true\"/><param name=\"flashvars\" value=\"channelId=5c0654367c4c4713badc097289aa77e5&amp;playerForm=9c2fd7bdeb4c452ca04e7645713a0563&amp;deepLink=true\"/><embed src=\"http://assets.delvenetworks.com/player/loader.swf\" name=\"limelight_player_933169e\" wmode=\"transparent\" width=\"242\" height=\"268\" allowScriptAccess=\"always\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"channelId=5c0654367c4c4713badc097289aa77e5&amp;playerForm=9c2fd7bdeb4c452ca04e7645713a0563&amp;deepLink=true\"></embed></object>";
        

}


// This function puts the video on the page
function embedVideo(video) {
    videoEmbedCode = video.html;
    document.getElementById('videoembed').innerHTML = unescape(video.html);
}
        
// This function goes through the clips and puts them on the page
function showThumbsAlbum1(clips) {
    var thumbs = document.getElementById('country1');
    var strHTML = '';
    thumbs.innerHTML = '';
    var strStyle = '';
    strHTML = strHTML + '<table cellpadding="0" cellspacing="0" border="0">';
    for (var i = 0; i < clips.length; i++) {
        if (clips[i].clip_id == video_hide_id) {
            //strStyle = 'hideme';
        }
        strHTML = strHTML + '<tr>';
        strHTML = strHTML + '<td style="'+strStyle+'" id="img_'+ clips[i].clip_id +'"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')"><img src="' + clips[i].thumbnail_medium + '" border="0" width="80" height="60" alt=""></a></td>';
        strHTML = strHTML + '<td class="text-video ' + strStyle + '" id="vid_'+ clips[i].clip_id +'"><div class="text-section"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')">' + clips[i].title + '</a> ' + convertToMins(clips[i].duration) + '</div></td>';            
        strHTML = strHTML + '</tr><tr><td class="' + strStyle + '" id="extra_'+ clips[i].clip_id +'" colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
    }
    strHTML = strHTML + '</table>';
    thumbs.innerHTML = strHTML;
}

function showThumbsAlbum2(clips) {
    var thumbs2 = document.getElementById('country2');
    var strHTML = '';
    thumbs2.innerHTML = '';
    strHTML = strHTML + '<table cellpadding="0" cellspacing="0" border="0">';
    for (var i = 0; i < clips.length; i++) {
        strHTML = strHTML + '<tr>';
        strHTML = strHTML + '<td><a href=#" onclick="embedCode(' + clips[i].clip_id + ')"><img src="' + clips[i].thumbnail_medium + '" border="0" width="80" height="60" alt=""></a></td>';
        strHTML = strHTML + '<td class="text-video" id="vid_'+ clips[i].clip_id +'"><div class="text-section"><a href=#" onclick="embedCode(' + clips[i].clip_id + ')">' + clips[i].title + '</a> ' + convertToMins(clips[i].duration) + '</div></td>';         
        strHTML = strHTML + '</tr><tr><td colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
    }
    
    strHTML = strHTML + '</table>';
    thumbs2.innerHTML = strHTML;
}

String.prototype.pad = function(l, s){
    return (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length) : this;
};


function convertToMins( intNumber ) {
    var secVarTemp = 0;
    if (intNumber) {
        var secVar0 = intNumber;
        var minVar = Math.floor(secVar0/60);
        var secVar = secVar0 % 60;
        secVarTemp = '<span style="color:#676767">' + minVar + ':' + secVar.toFixed().pad(2, "0") + '</span>';
    }
    return secVarTemp;
}


// This function loads the data from Vimeo
function init() {
    /*
        var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', urlalbum1);
    document.getElementsByTagName('head').item(0).appendChild(js);
    
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', urlalbum2);
    document.getElementsByTagName('head').item(0).appendChild(js);
    */
    var js2 = document.createElement('script');
    js2.setAttribute('type', 'text/javascript');
    js2.setAttribute('src', url2);
    document.getElementsByTagName('head').item(0).appendChild(js2);
} 

//New functions for Delve Video Pages
function delvePlayerCallback(playerId, eventName, data) {
    switch (eventName) {
        case 'onPlayerLoad':
        doOnPlayerLoad();
        break;
    
    case 'onChannelLoad':
        doOnChannelLoad(data);
        break;
    
    case 'onMediaLoad':
        doOnMediaLoad(data);
        break;
    
    case 'onPlayStateChanged':
        doOnPlayStateChanged(data);
        break;
    
    case 'onPlayheadUpdate':
        doOnPlayheadUpdate(data);
        break; 
    }
}

//function doOnMediaLoad(e) {
//  listChannelMedia(DelvePlayer.doGetCurrentChannel().id, DelvePlayer.doGetCurrentChannel().mediaList);
//}

function doOnChannelLoad(e) {
    
    
    if (e.id == '73aa960647c245d8852d1ac756dafb55') {
        listChannelMediaMore(e.id, e.mediaList);
    }else{
        listChannelMedia(e.id, e.mediaList);
    }
    
}

function converMilliToSeconds( intMilli ) {
    var milliseconds = parseInt(intMilli);
    var hours = Math.floor(milliseconds / 3600000);
    var minutes = Math.floor((milliseconds - (hours * 3600000)) / 60000);
    var seconds = parseInt((milliseconds - (hours * 3600000) - (minutes * 60000)) / 1000);
    if (seconds < 10){
        return minutes + ":0" + seconds;
    }
    else {
        return minutes + ":" + seconds;
    }
}

function changeBg( vid_id ) {   
    var setbgcolor = document.getElementById("vid_"+ vid_id );
    var setbgcolormain = document.getElementById("vid_"+ video_hide_id );
    
    if ( (video_hide_id != 0) && (video_hide_id != vid_id) ) {
        setbgcolormain.style.backgroundColor = "#ffffff";
    }
    video_hide_id = vid_id;
    setbgcolor.style.backgroundColor = "#e9f1f7";
    //alert(video_hide_id);
}

function listChannelMedia( channelid, arrayList ) {
    //alert('regular');
    var x;
    var style_str = '';
    if (arrayList.length > 1) {
    var strHTML = '<table cellpadding="0" cellspacing="0" border="0">';
    for (x in arrayList) {
        
        if (video_hide_id == arrayList[x].id) { 
            style_str = 'background-color:#e9f1f7';
        }
        else {
            style_str = 'background-color:#ffffff';
        }
        if (arrayList[x].title != 'undefined'){
        strHTML += '<tr>';
        strHTML += '<td style="padding:0; border:0;"><a href="javascript:DelvePlayer.doSetMedia(\'' + arrayList[x].id + '\'' + ',' + '\'1\'' + ',' + '\'\');" onclick="changeBg( \'' + arrayList[x].id + '\' )"><img src="' + arrayList[x].thumbnailUrl + '" border="0" width="80" height="60" alt="" /></a></td>';
        strHTML += '<td style="padding:0; border:0;" class="text-video" id="vid_' + arrayList[x].id + '" style="'+ style_str +'" onclick="changeBg( \'' + arrayList[x].id + '\' )">';
        if (arrayList[x].description != '') {
            //strHTML += '<div onmouseout="fadeOutMyPopup(\'pop_' + arrayList[x].id + '\');" id=\'pop_' + arrayList[x].id + '\' name=\'styled_popup\' class="video_class"><div style="padding:5px;">' +  arrayList[x].description + '</div></div>';
        }
        strHTML += '<div class="text-section"><a '; 
        if (arrayList[x].description != '') {
            //strHTML += 'onmouseover="fireMyPopup(\'pop_' + arrayList[x].id + '\')" ';
        }
        strHTML += 'href="javascript:DelvePlayer.doSetMedia(\'' + arrayList[x].id + '\'' + ',' + '\'1\'' + ',' + '\'\');">' + arrayList[x].title + '</a> <span id="video-time">' + converMilliToSeconds(arrayList[x].durationInMilliseconds) + '</span></div></td>';
        strHTML += '</tr><tr><td colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="2" alt=""></td></tr>';
        }
    }
    strHTML += '</table>';
    //alert(strHTML);
    document.getElementById('country1').innerHTML = strHTML;
    }
    else {
        //document.getElementById('video-list').style.display = 'none';
    }
}


function listChannelMediaMore( channelid, arrayList ) {
    //alert('more');
    var x;
    var style_str = '';
    if (arrayList.length >= 1) {
    var strHTML = '<table cellpadding="0" cellspacing="0" border="0">';
    for (x in arrayList) {
        
        if (video_hide_id == arrayList[x].id) { 
            style_str = 'background-color:#e9f1f7';
        }
        else {
            style_str = 'background-color:#ffffff';
        }
        if (arrayList[x].title != 'undefined'){
        strHTML += '<tr>';
        strHTML += '<td><a href="' + arrayList[x].custom_property.PageURL + '" onclick="changeBg( \'' + arrayList[x].id + '\' )"><img src="' + arrayList[x].thumbnailUrl + '" border="0" width="80" height="60" alt="" /></a></td>';
        strHTML += '<td class="text-video" id="vid_' + arrayList[x].id + '" style="'+ style_str +'" onclick="changeBg( \'' + arrayList[x].id + '\' )">';
        if (arrayList[x].description != '') {
            //strHTML += '<div onmouseout="fadeOutMyPopup(\'pop_' + arrayList[x].id + '\');" id=\'pop_' + arrayList[x].id + '\' name=\'styled_popup\' class="video_class"><div style="padding:5px;">' +  arrayList[x].description + '</div></div>';
        }
        strHTML += '<div class="text-section"><a '; 
        if (arrayList[x].description != '') {
            //strHTML += 'onmouseover="fireMyPopup(\'pop_' + arrayList[x].id + '\')" ';
        }
        strHTML += 'href="javascript:DelvePlayer.doSetMedia(\'' + arrayList[x].id + '\'' + ',' + '\'1\'' + ',' + '\'\');">' + arrayList[x].title + '</a> <span id="video-time">' + converMilliToSeconds(arrayList[x].durationInMilliseconds) + '</span></div></td>';
        strHTML += '</tr><tr><td colspan="2"><img src="/images/designelements/spacer.gif" border="0" width="0" height="10" alt=""></td></tr>';
        }
    }
    strHTML += '</table>';
    document.getElementById('country2').innerHTML = strHTML;
    }
    else {
        //document.getElementById('video-list').style.display = 'none';
    }
}

function gotoMediaUrl( intmediaid, intchannelid ) {
    window.location = 'testvideo.asp?media_id=' + intmediaid + '&channel_id=' + intchannelid;
}


// Browser safe opacity handling function
function setOpacity( value, div_id ) {
 document.getElementById('' + div_id + '').style.opacity = value / 10;
 document.getElementById('' + div_id + '').style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup(div_id) {
 for( var i = 0 ; i <= 100 ; i++ )
   setTimeout( 'setOpacity(' + (i / 10) + ',\'' + div_id + '\')' , 8 * i );
}

function fadeOutMyPopup(div_id) {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( 'setOpacity(' + (10 - i / 10) + ',\'' + div_id + '\')' , 8 * i );
 }

 setTimeout('closeMyPopup(\''+  div_id + '\')', 800 );
}

function closeMyPopup(div_id) {
 document.getElementById('' + div_id + '').style.display = "none"
}

function fireMyPopup(div_id) {
 setOpacity( 0, div_id );
 document.getElementById('' + div_id + '').style.display = "block";
 fadeInMyPopup(div_id);
}
