var containerForTabs;
    containerForTabs = document.getElementById("videoList");

    // appends the video icon
    $("#cat_hl_220524 .title a.linkItem").append("<span class='playButton' style='margin-left:5px;padding-left:15px;'>Play</span> ");

    // modifies the URL
    var totalLinksToChange = $("#cat_hl_220524 .odd, #cat_hl_220524 .even");

    for (i = 0; i < totalLinksToChange.length; i++) {
        var currentDiv = totalLinksToChange[i];
        var currentLink = $(currentDiv).find(".image a");
        var currentURLToSplit = $(currentLink).attr("href");
        var splitURL = currentURLToSplit.split("=");
        var currentVideoId = splitURL[1];
        $(currentLink).attr("href", "#");
        $(currentLink).attr("id", currentVideoId);
        $(currentLink).click(function() {
            playVideoUUID(this.id);
        });
        var currentTitleLink = $(currentDiv).find(".title a");
        $(currentTitleLink).attr("href", "#");
        $(currentTitleLink).attr("id", currentVideoId);
        $(currentTitleLink).click(function() {
            playVideoUUID(this.id);
        });
    }
    // appends the video icon
    $("#cat_hl_220525 .title a.linkItem").append("<span class='playButton' style='margin-left:5px;padding-left:15px;'>Play</span> ");

    // modifies the URL
    var totalLinksToChange = $("#cat_hl_220525 .odd, #cat_hl_220525 .even");

    for (i = 0; i < totalLinksToChange.length; i++) {
        var currentDiv = totalLinksToChange[i];
        var currentLink = $(currentDiv).find(".image a");
        var currentURLToSplit = $(currentLink).attr("href");
        var splitURL = currentURLToSplit.split("=");
        var currentVideoId = splitURL[1];
        $(currentLink).attr("href", "#");
        $(currentLink).attr("id", currentVideoId);
        $(currentLink).click(function() {
            playVideoUUID(this.id);
        });
        var currentTitleLink = $(currentDiv).find(".title a");
        $(currentTitleLink).attr("href", "#");
        $(currentTitleLink).attr("id", currentVideoId);
        $(currentTitleLink).click(function() {
            playVideoUUID(this.id);
        });
    }



// render the show title and links
var ShowTitle = document.getElementById("TvShowTitle");
var Title = ShowTitle.appendChild(document.createElement("h1"));
Title.innerHTML = TvShow.Show;

var TitleSpan = ShowTitle.appendChild(document.createElement("span"));
var TitleLink = TitleSpan.appendChild(document.createElement("a"));
TitleLink.innerHTML = "Visit " + TvShow.Show + " homepage";
TitleLink.href = TvShow.URL;


// render the show tabs
for (i = 0; i < TvShow.Clips.split("/").length; i++) {
    try {
        var FeedURL = VIDEO_INITIAL_OVERRIDE;
        FeedURL = (i == 0) ? FeedURL : FeedURL + "&ns=Duration&tag=Short";
        var ShowListTab = containerForTabs.appendChild(document.createElement("li"));
        var ShowListAnchor = ShowListTab.appendChild(document.createElement("a"));
        ShowListAnchor.innerHTML = ((!(i == 0)) ? "Full Episode" : "Short Clips");
        CompleteFeed = FeedURL;
        paramsArray.push(FeedURL)
        $(ShowListTab).click(function() {
            selectTab(this);
            loadVideos(FeedURL);
        });
    }
    catch (ex) { alert(ex.description); }
}

//Returns the value for a given key (qsKey) in the query string
function getQueryParam(qsKey) {

    var queryParams = window.location.href.split("?");

    if (queryParams.length < 2) {
        return null;
    }

    var paramPairs = queryParams[1].split("&");
    for (var i = 0; i < paramPairs.length; i++) {
        var keyValue = paramPairs[i].split("=");
        if (keyValue[0].toUpperCase() == qsKey.toUpperCase()) {
            return keyValue[1];
        }
    }
    return null;
}


var tabNumber = queryString('tab');
if (tabNumber != "false") {
    if (parseInt(tabNumber) <= paramsArray.length) {
        selectTabNum(tabNumber - 1);
        loadVids(tabNumber);
    }
}
else {
    selectTabNum(0);
    loadVideos(paramsArray[0]);
}

function loadVids(tabNumber) {
    var videoId = queryString('videoid');
    if (videoId != "false") {
        loadVideos(paramsArray[tabNumber - 1]);
    }
    else {
        loadVideos(paramsArray[tabNumber - 1], true);
    }
}


var isMSNVideoClickEnabled = false;

function updateVideoData(videoItem, hlCatId) {
    var manualLinksData = window["vidManualLinks_" + hlCatId];
    for (var i = 0; i < manualLinksData.length; i++) {
        var link = manualLinksData[i];
        if (link.uuid.toLowerCase() == videoItem.uuid.$.toLowerCase()) {
            link.title = link.title ? link.title : videoItem.title.$;
            link.imgUrl = link.imgUrl ? link.imgUrl : getThumbnailUrl(videoItem, hlCatId);
        }
    }
}

function renderManualVideoLinks(hlCatId) {
    var manualLinksDiv = document.getElementById("vidManualLinks_" + hlCatId);
    var manualLinksData = window["vidManualLinks_" + hlCatId];
    var innerHTML = "";
    for (var i = 0; i < manualLinksData.length; i++) {
        var link = manualLinksData[i];
        innerHTML += "<div class='videoItem'>";
        innerHTML += "	<div class='image'><img src='" + link.imgUrl + "' alt='" + link.title + "' /></div>";
        innerHTML += "	<div class='description'>";
        innerHTML += "		" + link.title;
        innerHTML += "		<span class='playIcon'>Play</span>";
        innerHTML += "	</div>";
        innerHTML += "</div>";
    }

    manualLinksDiv.className = "loaded";
    manualLinksDiv.innerHTML = innerHTML;

    $(".videoManualPlayer .videoItem").click(function() {
        var indexPosition = $(this).parent().find(".videoItem").index(this);
        document.getElementById("MSNVideoPlayer_pobj").vidPlayId(manualLinksData[indexPosition].uuid);
    });
}

/**
* Returns the correct thumbnail url to use for the specified video.  Will return the image with the 2009 formatCode th
* Author: Domagoj Filipovic
* Date: 28/04/08
* Notes:	The image with a formatCode of "2009" is the 300 x 400 image supplied by ninemsn and should be used in
*			conjunction with the ninemsn resizer if found.  If not found, the "2007" format should be used.  The "2007"
*			has 2 variants:
*				1. Ninemsn supplied image (this should be passed through the ninemsn resizer)
*				2. MSN resized thumbnail (this SHOULD NOT be passed through the ninemsn resizer).
*/
function getThumbnailUrl(videoData, hlCatId) {
    var videoThumbnailSrc = "";
    var resizerUrl = "";
    var strImageSize = window["strImageSize_" + hlCatId];

    if (!strImageSize) {
        resizerUrl = "http://images.ninemsn.com.au/resizer.aspx?width=92&url=";
    }
    else {
        resizerUrl = "http://images.ninemsn.com.au/resizer.aspx?width=" + strImageSize + "&url=";
    }

    if (videoData && videoData.files && videoData.files.file) {
        for (var i = 0; i < videoData.files.file.length; i++) {
            var imgFile = videoData.files.file[i];
            if (imgFile.$formatCode == "2001") {//if 2001 format is found, use it with the resizer
                videoThumbnailSrc = resizerUrl + escape(imgFile.uri.$);
                break;
            }
            else if ((imgFile.$formatCode == "2009" || imgFile.$formatCode == "2007") && (imgFile.uri.$.toLowerCase().indexOf("catalog.video.msn.com") == -1)) {//if 2007 or 2009 format is found and the location is on netshow, use it with the resizer
                videoThumbnailSrc = resizerUrl + escape(imgFile.uri.$);
                break;
            }
        }

        if (!videoThumbnailSrc && videoData.providerId && videoData.providerId.$) {//couldn't find suitable thumbnail, construct it manualy
            videoThumbnailSrc = resizerUrl + buildVideoPath(videoData);
        }
    }

    return videoThumbnailSrc;
}

//Gets additional information for the video logo once it is loaded
Msn.Video.OnVideoTitle = function(text, id) {
    //first, set the title for the player
    if (text && id) {
        $("#" + id + "_t").html(text);
        $("#" + id + "_mail").html("E-mail '" + text + "' video to your friends and family");
        $("#" + id + "_mail").show();
        if (text == "Advertisement") {
            $("#" + id + "_mail").hide();
        }
        if (!isMSNVideoClickEnabled) {
            $("#" + id + "_mail").click(function() {
                var vidObj = document.getElementById(id + "_pobj");
                if (vidObj) {
                    var link = (window.location.protocol + "//" + window.location.hostname + window.location.pathname + window.location.search).toLowerCase();

                    //first, get rid of any existing videoid QS parameter
                    var startVideoId = link.indexOf("videoid=");
                    if (startVideoId > -1) {
                        var endVideoId = link.indexOf("&", startVideoId);
                        var qsToRemove = link.substring(startVideoId - 1, (endVideoId == -1 ? link.length : endVideoId));
                        link = link.replace(qsToRemove, "");

                        //Next, fix the url to have a leading ? before any & in the QS
                        var firstInstanceOfAnd = link.indexOf("&");
                        var firstInstanceOfQuestionMark = link.indexOf("?");
                        if (firstInstanceOfAnd < firstInstanceOfQuestionMark || (firstInstanceOfQuestionMark == -1 && firstInstanceOfAnd > -1)) {
                            link = link.replace("&", "?");
                        }
                    }

                    //Construct new URL
                    link = escape(link + (link.indexOf("?") > -1 ? "&" : "?") + "videoid=" + vidObj.vidGetId());
                    window.location = "mailto:?subject=" + vidObj.vidGetTitle() + "&body=This video appears in channelnine.ninemsn.com.au and I thought you should see it. " + link + "%0A%0AIf you cannot click on the link above, copy and paste the entire address below into your web browser." + link + "%0A%0AFor all the latest videos around the globe, check out at http%3A//channelnine.ninemsn.com.au";
                }
            });
            isMSNVideoClickEnabled = true;
        }
    }

    var vidObj = document.getElementById(id + "_pobj");
    if (vidObj) {
        //fetch the details for this video to get the source
        $.getJSON("http://edge1.catalog.video.msn.com/videoByUuid.aspx?uuid=" + vidObj.vidGetId() + "&responseEncoding=json&callbackName=?", function(videoData) {
            var logoImg = document.getElementById("srcManVidImgLogo");
            if (logoImg) {
                logoImg.src = "http://content3.catalog.video.msn.com/e2/ft/share8/dbbb/0/ENNZ_MTV.gif";
                logoImg.alt = videoData.source.$friendlyName;
                logoImg.style.visibility = "visible";
            }

            /*next get the logoUrl if one exists
            $.getJSON("http://edge1.catalog.video.msn.com/getcontentsource.aspx?csid=au_ninemsn&name=" + videoData.source.$ + "&responseEncoding=json&callbackName=?", function(results) {
            var logoImg = document.getElementById("srcManVidImgLogo");
            if (logoImg) {
            if (results && results.contentSource && results.contentSource.$logoUrl && results.contentSource.$logoUrl != "http://img.video.msn.com/video/i/src/AU_ninemsn.gif") {//get image src from results. If it contains anything, update the image. Ignore the default ninemsn image
            logoImg.src = results.contentSource.$logoUrl;
            logoImg.alt = results.contentSource.$friendlyName;
            }

                    //Make image visable
            logoImg.style.visibility = "visible";
            }
            });
            */
        });
    }
}





