/**
 * This file is included in each page and includes generic event handlers for the UI,
 * callbacks for the Brightcove player, Utility functions and handles the Ad Integration.
 * 
 * @author Jesse Streb
 */

/************************************************************************************
 * Global variables and player configurations.
 ************************************************************************************/
/*If you would like change the click through url set it here*/
var DEFAULT_BANNER_CLICK_THROUGH_URL = "/site/order/index.do?source=acq_shocom_video";


/*Different columns in the UI can change.  If they grow we track it so that we can gurantee that it will shrink cross-browser*/
var bc_prevHeight = null;
var bc_gCurrentTitleId = null;
var bc_gCount = 0;
var bc_gArrayOfSeriesIds = new Array();
var BC_API_URL = "http://api.brightcove.com/services/library";
var BC_TOKEN = escape("FE3OTYO94Tzdw42TKsz9IAXXqEf8ERJqPPPD22wq364.");
var bc_isIE = (navigator.appVersion.toLowerCase().indexOf('msie') != -1);

/*10-22-2008 Adding a fix in to not allow a user to skip an ad*/
var bc_gAdPlaying = false;

/************************************************************************************
 * Universal event handlers.
 ************************************************************************************/
/*
 * Register the onload event for each of the pages, where we do any safari specific changes.
 */
window.onload = function () { 
    try {
        if(BrowserDetect.browser.toLowerCase() == "safari") {
            document.getElementById('footerPadding').style.height = "80px";
        }
    } catch (e) {

    }
    
    //If there is a new click through url for the default banner ad set it now. Since the audio page does not have a banner ad this is in a try catch
    if(DEFAULT_BANNER_CLICK_THROUGH_URL != null) {
        try {
            document.getElementById('bc_adUnit').innerHTML = "<a href='" + DEFAULT_BANNER_CLICK_THROUGH_URL +"' target='_blank'><img src='../images/defaultBanner.jpg' border='0' alt='banner'/></a>";
        } catch (e) {}
    }
    
    
    //Allow each pages .js file to do its own page configuration on load by calling this function which they can implement.
    bc_onLoadExtended();
}

//To be extended by other javascript files
function bc_onLoadExtended() {

}

/**
 * An event fired by the Brightcove Player.  Since we have a custom ad integration we register the correct ad formats.
 * @param {Object} message
 */
 function onTemplateLoaded() {
    player = brightcove.getExperience("myExperience");
    experience = player.getModule(APIModules.EXPERIENCE);
    social = player.getModule(APIModules.SOCIAL);
    bc_gVideo = player.getModule(APIModules.VIDEO_PLAYER);
    bc_gVideo.addEventListener("streamStart", bc_onMediaStart);
    experience.addEventListener(BCExperienceEvent.CONTENT_LOAD, onContentLoaded);
    experience.addEventListener(BCExperienceEvent.TEMPLATE_READY, onTemplateReady);
    
    adModule = player.getModule(APIModules.ADVERTISING);
    adModule.addEventListener(BCAdvertisingEvent.AD_START, bc_onAdStart);
    adModule.addEventListener(BCAdvertisingEvent.AD_COMPLETE, bc_onAdComplete);
    adModule.enableAdFormats(0, 2, 14);
}

function onContentLoaded() {
    adModule.addEventListener(BCAdvertisingEvent.EXTERNAL_AD, onExternalAd);
}

function onTemplateReady() {
    try {
        adModule.enableExternalAds(true);
        if(location.href.indexOf('series/home.do') > -1) {
            social.setLink(location.href);
        } else {
            social.setLink(location.href.split("?")[0] + "?bcpid=" + bc_gPlayerId + "&bclid=" + bc_gPlaylistId + "&bctid=" + bc_gVideoID );
        }
        
        bc_gVideo.cueVideo(bc_gVideoID);
    } catch (e) {

    }
}

function bc_onMediaStart(evt) {
    bc_gAdPlaying = false;
    var pTitleDTO = bc_gVideo.getCurrentVideo();
    if(bc_gCurrentTitleId != null) {
        document.getElementById("bc_thumb_" + bc_gCurrentTitleId).style.borderColor = "#cccccc";
        document.getElementById("bc_now_playing_" + bc_gCurrentTitleId).style.display = "none";
     }
     document.getElementById("bc_thumb_" + pTitleDTO.id).style.borderColor = "#9c0000";
     document.getElementById("bc_now_playing_" + pTitleDTO.id).style.display = "block";
     document.getElementById("bc_titleName").innerHTML = pTitleDTO.displayName;
     document.getElementById("bc_titleDesc").innerHTML = (pTitleDTO.shortDescription == "ignore") ? " " : pTitleDTO.shortDescription;
     bc_gCurrentTitleId = pTitleDTO.id;

     setGetLink(pTitleDTO.id);
}

function setGetLink(pId) {
     social.setLink(experience.getExperienceURL());
}

function bc_playTitle(pTitleId) {
    if(!bc_gAdPlaying) {
        bc_gVideo.loadVideo(pTitleId);
    }
}

function bc_onAdStart(pEvent) {
    bc_gAdPlaying = true;
}

function bc_onAdComplete(pEvent) {
    bc_gAdPlaying = false;
}


/**
 * Handle the mouseover event for the top navigation.
 * @param {Object} pElem - The html element that fired teh mouseover event.
 */
function bc_handleTabOver(pElem) {
    var images = pElem.getElementsByTagName('img');
    try {
        images[0].style.display = "none";
        images[1].style.display = "block";
    } catch (e) {
        //gulp
    }
} 

/**
 * Handle the mouseout event for the top navigation.
 * @param {Object} pElem - The html element that fired the mouseout event.
 */
function bc_handleTabOut(pElem) {
    var images = pElem.getElementsByTagName('img');
    try {
        images[0].style.display = "block";
        images[1].style.display = "none";
    } catch (e) {
        //gulp
    }
}

/**
 * If there are more titles then there is space for we allow the user to scroll through these titles.  This is the onclick event fired by the 
 * left arrow.
 */
function bc_handleScrollLeft() {
    if((bc_currentClip) > (bc_gNumOfVidsInScrollArea * 2)) {
        bc_prepSlideElement(document.getElementById("bc_lineupThumbnailsContainer"), 500, bc_getNum(document.getElementById('bc_lineupThumbnailsContainer').style.left) + (bc_gNumOfVidsInScrollArea * 125), "left");
        bc_currentClip = bc_currentClip - bc_gNumOfVidsInScrollArea;
        document.getElementById("bc_rightArrow").className = "bc_rightArrowOn";
    } else {
        bc_prepSlideElement(document.getElementById("bc_lineupThumbnailsContainer"), 500, 0, "left");
        bc_currentClip = bc_gNumOfVidsInScrollArea;
        document.getElementById("bc_leftArrow").className = "bc_leftArrowOff";
        document.getElementById("bc_rightArrow").className = "bc_rightArrowOn";
    }
}

/**
 * If there are more titles then there is space for, we allow the user to scroll through these titles.  This is the onclick event fired by the 
 * right arrow.
 */
function bc_handleScrollRight() {
    if((bc_numClips - bc_currentClip) > bc_gNumOfVidsInScrollArea) {
        bc_prepSlideElement(document.getElementById("bc_lineupThumbnailsContainer"), 500, bc_getNum(document.getElementById('bc_lineupThumbnailsContainer').style.left) - (bc_gNumOfVidsInScrollArea * 125), "left");
        bc_currentClip = bc_currentClip + bc_gNumOfVidsInScrollArea;
        document.getElementById("bc_leftArrow").className = "bc_leftArrowOn";
    } else if(bc_numClips != bc_currentClip){
        bc_prepSlideElement(document.getElementById("bc_lineupThumbnailsContainer"), 500, bc_getNum(document.getElementById('bc_lineupThumbnailsContainer').style.left) - ((bc_numClips - bc_currentClip) * 125), "left");
        bc_currentClip = bc_numClips;
        document.getElementById("bc_rightArrow").className = "bc_rightArrowOff";
        document.getElementById("bc_leftArrow").className = "bc_leftArrowOn";
    }
}

/**
 * mouseover event for a title container.  Here we make the border red if it isn't the current playing title.
 * @param {Object} pId
 */
function bc_titleMouseOver(pId) {
    if(bc_gCurrentTitleId != pId) {
        document.getElementById("bc_thumb_" + pId).style.borderColor = "#9c0000";
    }
}

/**
 * mouseout event for a title container.  Here we make the border grey if it isn't the current playing title.
 * @param {Object} pId
 */
function bc_titleMouseOut(pId) {
    if(bc_gCurrentTitleId != pId) {
        document.getElementById("bc_thumb_" + pId).style.borderColor = "#cccccc";
    }
}


/************************************************************************************
 * Utility functions used throughout the pages.
 ************************************************************************************/

/**
 * calls the API method for finding videos by campaign id, using the constants for the publisher and campaign
 * 
 */ 
 function bc_getPlaylists(pPlayerId) {
    var findVideosURL = BC_API_URL  + "?command=find_playlists_for_player_id&player_id=" + pPlayerId + "&token=" + BC_TOKEN  + "&callback=bc_playlistsResults&page_size=100&fields=id,referenceId,name,shortDescription,videoIds,videos";
    var scriptElem = document.createElement('script');
    scriptElem.setAttribute('src', findVideosURL);
    scriptElem.setAttribute('type','text/javascript');
    document.getElementsByTagName('head')[0].appendChild(scriptElem);
}

function bc_playlistsResults(pObj) {
    //We will add an element to the page to be able to check the size of the text.
    if(document.getElementById('bc_width') == null) {
        var div = document.createElement('div');
        div.id = 'bc_width';
        div.style.width = "170px";
        div.style.fontSize = "11px";
        div.style.fontWeight = "bold";
        document.body.appendChild(div);
    }

    //On our first call we need to get a list of all of the shows, which are actually lineups.  This builds that list.
    if(bc_gArrayOfSeriesIds.length == 0) {
        var arrayOfPlaylists = pObj.items;
        for(var i=0; i<arrayOfPlaylists.length; i++) {
            var obj = new Object();
            obj.id = arrayOfPlaylists[i].referenceId;
            obj.name = arrayOfPlaylists[i].name;
            bc_gArrayOfSeriesIds[i] = obj;  
        }
        bc_getPlaylists(bc_gArrayOfSeriesIds[bc_gCount].id);
        bc_gCount++;
    } else {
        var arrayOfPlaylists = pObj.items;
        for(var i=0; i<arrayOfPlaylists.length; i++) {
            for(var j=0; j<arrayOfPlaylists[i].videoIds.length; j++) {
                if(bc_gVideosId[arrayOfPlaylists[i].videoIds[j]]) {
                    bc_linkUpNewestVideos(bc_gArrayOfSeriesIds[(bc_gCount - 1)].id, bc_gArrayOfSeriesIds[(bc_gCount - 1)].name, arrayOfPlaylists[i].id, arrayOfPlaylists[i].name, arrayOfPlaylists[i].videoIds[j]);
                    bc_linkUpPopularVideos(bc_gArrayOfSeriesIds[(bc_gCount - 1)].id, bc_gArrayOfSeriesIds[(bc_gCount - 1)].name, arrayOfPlaylists[i].id, arrayOfPlaylists[i].name, arrayOfPlaylists[i].videoIds[j]);
                    bc_linkUpRelatedVideos(bc_gArrayOfSeriesIds[(bc_gCount - 1)].id, bc_gArrayOfSeriesIds[(bc_gCount - 1)].name, arrayOfPlaylists[i].id, arrayOfPlaylists[i].name, arrayOfPlaylists[i].videoIds[j]);
                }
            }   
        }
        if(bc_gArrayOfSeriesIds[bc_gCount]) {
            bc_getPlaylists(bc_gArrayOfSeriesIds[bc_gCount].id);
            bc_gCount++;
        }
    }
}

function bc_linkUpNewestVideos(pPlayerId, pShowName, pLineupId, pEpisodeName, pTitleId) {
    try {
        if(document.getElementById('bc_new_episode_' + pTitleId) != null) {
            pShowName = formatShowName(pShowName);
            //document.getElementById('bc_new_show_' + pTitleId).innerHTML = "<a href='./title.do?bcpid=" + pPlayerId + "'>" + pShowName + "</a>";
            var episodeName = ellipse(document.getElementById('bc_width'), pShowName + " " + bc_formatEpisode(pEpisodeName), 150);
            document.getElementById('bc_new_episode_' + pTitleId).innerHTML = "<a href='./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "'>"+ episodeName +"</a>";
            var name = document.getElementById('bc_new_title_' + pTitleId).innerHTML;
            document.getElementById('bc_new_title_' + pTitleId).innerHTML = "<a href='./title.do?bcpid="+ pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId + "'>" + name + "</a>";
            document.getElementById('bc_new_thumb_' + pTitleId).onclick = function () {location.href="./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId };
        }
    } catch (e) {

    }
}

function bc_linkUpPopularVideos(pPlayerId, pShowName, pLineupId, pEpisodeName, pTitleId) {
    try {
        if(document.getElementById('bc_pop_episode_' + pTitleId) != null) {
            //document.getElementById('bc_pop_show_' + pTitleId).innerHTML = "<a href='./title.do?bcpid=" + pPlayerId + "'>" + pShowName + "</a>";
            pShowName = formatShowName(pShowName);
            var episodeName = ellipse(document.getElementById('bc_width'), pShowName + " " + bc_formatEpisode(pEpisodeName), 150);
            document.getElementById('bc_pop_episode_' + pTitleId).innerHTML = "<a href='./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "'>" + episodeName + "</a>";
            document.getElementById('bc_pop_title_' + pTitleId).innerHTML = "<a href='./title.do?bcpid="+ pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId + "'>" + 
            document.getElementById('bc_pop_title_' + pTitleId).innerHTML + "</a>";
            document.getElementById('bc_pop_thumb_' + pTitleId).onclick = function () {location.href="./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId };
        }
    } catch (e) {
        
    }
}

function bc_linkUpRelatedVideos(pPlayerId, pShowName, pLineupId, pEpisodeName, pTitleId) {
    try {
        pShowName = formatShowName(pShowName);
        document.getElementById('bc_relatedTitle_' + pTitleId).innerHTML = "<a href='./title.do?bcpid="+ pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId + "'>" + 
        document.getElementById('bc_relatedTitle_' + pTitleId).innerHTML + "</a>";
        document.getElementById('bc_related_lineup_' + pTitleId).innerHTML = "<a href='./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "'>" + pShowName + " " + bc_formatEpisode(pEpisodeName) + "</a>";
        document.getElementById('bc_relatedThumbBorder_' + pTitleId).onclick = function () {location.href="./title.do?bcpid=" + pPlayerId + "&bclid=" + pLineupId + "&bctid=" + pTitleId };
    } catch (e) {
        
    } 
}

function formatShowName(pShowName) {
	if(pShowName.indexOf('-category') > -1) {
		try {
			return pShowName.substring(0, pShowName.indexOf('-category'));
		} catch (e) {
			//gulp - not a fatal error so just swallow it
		}
	}	
	return pShowName;
}

function ellipse(pElem, pText, pWidth) {
   pElem.innerHTML = '<span id="ellipsisSpan" style="white-space:nowrap;">' + pText + '</span>';
   var inSpan = document.getElementById('ellipsisSpan');
   inSpan.innerHTML = pText;
   if(inSpan.offsetWidth > pWidth)
   {
      var i = 1;
      inSpan.innerHTML = '';
      while(inSpan.offsetWidth < (pWidth) && i < pText.length)
      {
         inSpan.innerHTML = pText.substr(0,i) + '...';
         i++;
      }
               
      returnText = inSpan.innerHTML;
      pElem.innerHTML = '';
      return returnText;
   }
   return pText;
}

/**
 * A helper function to get the query parameters for this url.  
 * @ returned - an array that contains the name value pairs for this array.
 */
function bc_getArgs() {
    var args = new Object( );
    var query = location.search.substring(1);
    if(query === "")
        return null;
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');
        if (pos == -1)
        continue;
    
        var argname = pairs[i].substring(0,pos);
        var value = pairs[i].substring(pos+1);
        args[argname] = unescape(value);
    }
    return args;
}

function bc_formatEpisode(pName) {
    try {
        var array = pName.split('_');
        return array[2] + ", " + array[0];
    } catch (e) {
        return pName;
    }
}

/**
 * A helper function to prep for the actual transistion of sliding the elements.
 * @param {Object} pElementToMove - The element that we are going to move on the screen.
 * @param {Object} pTimeToTake - How long we have to make this transistion.
 * @param {Object} pMoveEnd - Where we want this element to end up.
 * @param {Object} pType - What type of move this is.  So top in this case.
 */
function bc_prepSlideElement(pElementToMove, pTimeToTake, pMoveEnd, pType) {
    var moveStart = bc_getNum(pElementToMove.style[pType]);
    var amountToMove = pMoveEnd - moveStart;
    var timeStart = new Date().getTime ();
    var timeEnd = timeStart + pTimeToTake;
    bc_doSlideElement(pElementToMove, pType, amountToMove, moveStart, pTimeToTake, timeEnd);
  }

/**
 * A helper function do the actual slide down.  This based off of time to make the transistion as
 * clean as possible.
 * 
 * @param {Object} pElementToMove - The element that is goign to be slid
 * @param {Object} pType - What we changing on this element to move.  In this case top.
 * @param {Object} pAmountToMove - How much we have to move.
 * @param {Object} pMoveStart - A starting position.
 * @param {Object} pTimeToTake - How much time we have to complete this move.
 * @param {Object} pTimeEnd - When we have to complete this move by.
 */
function bc_doSlideElement(pElementToMove, pType, pAmountToMove, pMoveStart, pTimeToTake, pTimeEnd) {
    var currentTime = new Date().getTime();
    var timeRemaining = Math.max(0, pTimeEnd - currentTime);
    var currentMove = parseInt(pAmountToMove - (Math.pow(timeRemaining, 3) / Math.pow(pTimeToTake, 3)) * pAmountToMove);
    pElementToMove.style[pType] = (pMoveStart + currentMove) + "px";
    if (timeRemaining > 0) {
      setTimeout(function () { bc_doSlideElement(pElementToMove, pType, pAmountToMove, pMoveStart, pTimeToTake, pTimeEnd); }, 10);
    }
}

/**
 * A helper function to get a number if from a style.  This is to handle the case where we set the height
 * of a div to 100px and need to get rid of the px.
 * @param {Object} num - the string or number to check.
 */
function bc_getNum(num) {
    if(num.indexOf('px') > -1) {
        return parseInt(num.substring(0, num.indexOf('px')));
    } else {
        return parseInt(num);
    }
}

/**
 * A helper function to check the height of the left nav and if it has grown past the size of the
 * body then to change the height of the body.
 */
function bc_checkHeight() {
    if((document.getElementById('bc_leftColumnContainer').offsetHeight + 30) > document.getElementById('bc_rightColumnContainer').offsetHeight) {
        bc_prevHeight = document.getElementById('bc_rightColumnContainer').offsetHeight;
        document.getElementById('bc_rightColumnContainer').style.height = document.getElementById('bc_leftColumnContainer').offsetHeight + 50 + "px";
    } else if(bc_prevHeight != null && bc_prevHeight > document.getElementById('bc_leftColumnContainer').offsetHeight) {
        document.getElementById('bc_rightColumnContainer').style.height = bc_prevHeight + "px";
    }
}

/************************************************************************************
 * Functions to handle the custom ad integration
 ************************************************************************************/

function onExternalAd(pXML) {
try {
    var externalAd = new External_Ad(pXML.ad);
    var ad = externalAd.getVideoAd();
    adModule.showAd(externalAd.getVideoAd());
    document.getElementById('bc_adUnit').innerHTML = externalAd.getCollapsedAd();
} catch (e) {
    adModule.resumeAfterExternalAd();
}
    
    //document.getElementById('promo').innerHTML = externalAd.getExpandedAd();
}

/**
 * Sets the innerHTML of this element to the banner ad that was passed to it.
 * @param {Object} pAUrl - The url to the swf or image url.
 * @param {Object} pClickUrl - The url that is opened if the user clicks on the ad.
 */
function bc_show300Ad(pAdUrl, pClickUrl) {
    if(pAdUrl.substr((pAdUrl.length -3), 3) == "swf") {
        var objectTag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="60" id="expandedBanner" align="middle">';
        objectTag += '<param name="allowScriptAccess" value="always" />';
        objectTag += '<param name="movie" value="' + pAdUrl + '" />';
        objectTag += '<param name="quality" value="high" />';
        objectTag += '<param name="bgcolor" value="#ffffff" />';
        objectTag += '<param name="FlashVars" value="clickTag=' + pClickUrl + '" />';
        objectTag += '<embed src="' + pAdUrl + '" quality="high" bgcolor="#ffffff" width="300" height="60" name="collapsedBanner" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="clickTag=' + pClickUrl + '" />';
        objectTag += '</object>';
        document.getElementById('bc_adUnit').innerHTML = objectTag; //writes out the object tag we just built to the expandedBanner div
    } else {
        document.getElementById('bc_adUnit').innerHTML = "<a href='" + pClickUrl + "' target='_blank' ><img border='0' src='" + pAdUrl + "' /></a>"; //writes out the regular anchor/tag to the expandedBanner div
    }
}

/************************************************************************************
 * Functions to handle the Social bookmarking links.
 ************************************************************************************/
function fbs_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }
    t=document.title;

    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=no,resizable=yes,status=0,width=626,height=436');

    return false;
}

function google_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }
    t=document.title;

    window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'sharer','scrollbar=yes,toolbar=no,resizable=yes,status=0,width=800,height=436');

    return false;
}

function technorati_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }
    t=document.title;

    window.open('http://technorati.com/faves?add='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=no,resizable=yes,status=0,width=980,height=436');

    return false;
}

function furl_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }
    t=document.title;

    window.open('http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=no,resizable=yes,status=0,width=626,height=436');

    return false;
}
function digg_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }
    window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(document.title), 'digg','toolbar=no,resizable=yes');
    return false;
}

function del_click() {
    var fbsurl = '';            
    if(location.href.indexOf("#") !=-1){
        fbsurl = location.href.split("#");
        u = fbsurl[0];
    }else{
        u=location.href;
    }               
    window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,resizable=yes,width=700,height=400');
    return false;
}

function stumble_click() {
    var stumbleurl = '';            
    if(location.href.indexOf("#") !=-1){
        stumbleurl = location.href.split("#");
        u = stumbleurl[0];
    }else{
        u=location.href;
    }           
    window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(document.title), 'stumbleUpon','toolbar=no,resizable=yes,width=750,height=500');
    return false;
}

/*************************************************************************
 * These function are used by the Ad Translator to get data from the page
 * such as the current section and the playlist name.
 ************************************************************************/
 
function getPlayerName() {
   return bc_gPlayerName;
}

function getShowName() {
    return bc_gSeriesName;
}

function getPlaylistName() {
    return bc_gEpisodeName;
}