var videoMenuUrl = "http://data.ninemsn.com.au/Services/Service.axd?ServiceName=Video&ServiceAction=GetMenu&ServiceFormat=JSONAUTO&callback=?"
var imgServer = "http://video.ninemsn.com.au"; var arrPromo = new Array(); var arrPromoName = new Array(); var arrPromoLink = new Array(); var intRdm = 0; $(document).ready(function() {

if (GetCookie("flt_var") !== null) {
	var flight = GetCookie("flt_var");
	if(parseInt(flight) < 10){
		$('#video_wide').css('display','none');
return;
	}
}

    $.getJSON(videoMenuUrl, null, function(data) {

        if (data.MenuItems) {
            var menuItems = data.MenuItems.Item; for (var i = 0; i < menuItems.length; i++) {
                var menuItemName = menuItems[i].name; if (menuItemName == "Shows") {
                    var shows = $("#header-nav-shows"); shows.find(".header-nav-count").text('(' + menuItems[i].count + ')'); shows.append(renderShows(menuItems[i])); shows.hover(function() { shows.find(".header-nav-category").css({ 'display': 'block' }); }, function() { shows.find(".header-nav-category").css({ 'display': 'none' }); })
                    shows.find(".header-nav-category>li:last").css({ 'clear': 'left' });
                } else if (menuItemName == "Channels") { var channels = $("#header-nav-channels"); channels.find(".header-nav-count").text('(' + menuItems[i].count + ')'); channels.append(renderChannels(menuItems[i])); channels.hover(function() { channels.find(".header-nav-category").css({ 'display': 'block' }); }, function() { channels.find(".header-nav-category").css({ 'display': 'none' }); }) } else if (menuItemName == "Genres") { var genres = $("#header-nav-genres"); genres.find(".header-nav-count").text('(' + menuItems[i].count + ')'); genres.append(renderGenres(menuItems[i])); genres.hover(function() { genres.find(".header-nav-category").css({ 'display': 'block' }); }, function() { genres.find(".header-nav-category").css({ 'display': 'none' }); }) }
            }
            setVideoPromo("item_2"); setVideoPromo("item_3"); if ($.browser.msie && $.browser.version <= 6) { $("#cat_hl_172165").find(".item_png").get(0).src = "/img/video/logo/logos_9news.jpg"; $("#cat_hl_172165").find(".item_png").get(1).src = "/img/video/logo/logos_mtv.jpg"; $(".videoPromo").find("a").get(0).href = "http://video.ninemsn.com.au/List.aspx?ns=ninemsn_channel&tag=National%20Nine%20News"; $(".videoPromo").find("a").get(1).href = "http://video.ninemsn.com.au/List.aspx?ns=ninemsn_channel&tag=MTV"; $("#cat_hl_172165").find(".item_png").css({ 'margin': '0px' }); $(".videoPromo").find(".contentdesc").html("See videos"); }
            SetAdTrackForTopLinks();
        }

    }); $("#cat_hl_173047>span:last").css({ 'border': 'none' }); $("#nav-search").focus(function() { this.value = ""; }).blur(function() { if (this.value == "") { this.value = "Search Video"; } }).keypress(function(e) { if (e.which == 13) submitVideoSearch(); }); $("#nav-submit").click(function() { submitVideoSearch(); }); $("#cat_hl_172165").append('<div class="video_item_tooltip"></div><div class="video_item_tooltip_left"></div>'); try { var arrFeaturedText = $("#cat_hl_172165").find(".headertext").html().split("|"); setPlayHover("item_0", 1, arrFeaturedText[0]); setPlayHoverLeft("item_8", 1, arrFeaturedText[1]); } catch (err) { } setPlayHover("item_1", 0); setPlayHover("item_4", 0); setPlayHover("item_5", 0); setPlayHover("item_6", 0); setPlayHoverLeft("item_7", 0); setPlayHoverLeft("item_9", 0); setPlayHoverLeft("item_10", 0); setPlayHoverLeft("item_11", 0); $("#cat_hl_172165").hover(function() { }, function() { $('#cat_hl_172165').find(".odd, .even").stop().animate({ 'opacity': '1' }, 500); }); $(".playBtn").click(function() { var vidItem = $(this).parent().get(0); if (vidItem.firstChild.firstChild) { if (vidItem.firstChild.firstChild.tagName == "A") { $(this).parent().children().find("a").eq(0).triggerHandler("click"); window.location = vidItem.firstChild.firstChild.href; } } }); preloadNavImage();
}); function setPlayHover(el, type, featText) {
    if (type == 0) { $('#' + el).append('<div class="playBtn"><div class="playArrow"></div>PLAY</div>'); } else {
        $('#' + el).find(".title a").prepend('<div class="playBtnFeature">' + featText + '</div>')
        var descHeight = $('#' + el).find(".content").height(); if (descHeight <= 20) { $('#' + el).find(".content").css({ 'top': '-35px', 'display': 'block' }); } else if (descHeight <= 40) { $('#' + el).find(".content").css({ 'top': '-52px', 'display': 'block' }); } else if (descHeight <= 60) { $('#' + el).find(".content").css({ 'top': '-70px', 'display': 'block' }); }
    }
    $('#' + el).hover(function() { $(".video_item_tooltip").html($(this).find(".content").html()); $(this).css({ 'z-index': '500', 'opacity': '1' }); $('#cat_hl_172165').find(".odd, .even").stop().not($(this)).animate({ 'opacity': '0.4' }, 500); var elPosX = $(this).position().left + (type == 0 ? 160 : 320); var elPosY = $(this).position().top + (type == 0 ? 2 : 90); $(".video_item_tooltip").css({ 'display': 'block', 'top': elPosY + 'px', 'left': elPosX + 'px' }); if (type == 0) { $(this).find(".playBtn").css({ 'color': '#FF7200' }); $(this).find(".playArrow").css({ 'background-position': '1px -12px' }); } else { $(this).find(".playBtnFeature").css({ 'background-color': '#FFFFFF' }); $(this).find(".title > a").css({ 'text-decoration': 'underline' }); } }, function() { $(this).css({ 'z-index': '50' }); $(".video_item_tooltip").html("").css({ 'display': 'none' }); if (type == 0) { $(this).find(".playBtn").css({ 'color': '#FFFFFF' }); $(this).find(".playArrow").css({ 'background-position': '1px 0px' }); } else { $(this).find(".title > a").css({ 'text-decoration': 'none' }); $(this).find(".playBtnFeature").css({ 'background-color': '#FF7200' }); } })
}
function setPlayHoverLeft(el, type, featText) {
    if (type == 0) { $('#' + el).append('<div class="playBtn"><div class="playArrow"></div>PLAY</div>'); } else {
        $('#' + el).find(".title a").prepend('<div class="playBtnFeature">' + featText + '</div>')
        var descHeight = $('#' + el).find(".content").height(); if (descHeight <= 20) { $('#' + el).find(".content").css({ 'top': '-35px', 'display': 'block' }); } else if (descHeight <= 40) { $('#' + el).find(".content").css({ 'top': '-52px', 'display': 'block' }); } else if (descHeight <= 60) { $('#' + el).find(".content").css({ 'top': '-70px', 'display': 'block' }); }
    }
    $('#' + el).hover(function() { $(".video_item_tooltip_left").html($(this).find(".content").html()); $(this).css({ 'z-index': '500', 'opacity': '1' }); $('#cat_hl_172165').find(".odd, .even").stop().not($(this)).animate({ 'opacity': '0.4' }, 500); var elPosX = $(this).position().left - 295; var elPosY = $(this).position().top + (type == 0 ? 2 : 90); $(".video_item_tooltip_left").css({ 'display': 'block', 'top': elPosY + 'px', 'left': elPosX + 'px' }); if (type == 0) { $(this).find(".playBtn").css({ 'color': '#FF7200' }); $(this).find(".playArrow").css({ 'background-position': '1px -12px' }); } else { $(this).find(".playBtnFeature").css({ 'background-color': '#FFFFFF' }); $(this).find(".title > a").css({ 'text-decoration': 'underline' }); } }, function() { $(this).css({ 'z-index': '50' }); $(".video_item_tooltip_left").html("").css({ 'display': 'none' }); if (type == 0) { $(this).find(".playBtn").css({ 'color': '#FFFFFF' }); $(this).find(".playArrow").css({ 'background-position': '1px 0px' }); } else { $(this).find(".playBtnFeature").css({ 'background-color': '#FF7200' }); $(this).find(".title > a").css({ 'text-decoration': 'none' }); } })
}
function setVideoPromo(el) {
    var max = arrPromo.length; if (max > 1) {
        var randomnumber = Math.floor(Math.random() * max); if (intRdm == 0) { intRdm = randomnumber; } else { while (intRdm == randomnumber) { randomnumber = Math.floor(Math.random() * max); } }
        $("#" + el).append('<span class="videoPromo"><a href="' + arrPromoLink[randomnumber] + '"><img class="item_png" src="http://video.ninemsn.com.au' + arrPromo[randomnumber] + '"></a><span class="contentdesc">See all ' + arrPromoName[randomnumber] + ' videos</span></span>'); var posTop = ($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) ? '72' : $("#" + el).height() - $("#" + el).find(".contentdesc").height() - 2); $("#" + el).find(".contentdesc").css({ 'top': posTop + 'px' }); $('#' + el).hover(function() { $(this).css({ 'z-index': '500', 'opacity': '1' }); $("#" + el).find(".contentdesc").css({ 'display': 'block' }); $('#cat_hl_172165').find(".odd, .even").stop().not($(this)).animate({ 'opacity': '0.4' }, 500); }, function() { $(this).css({ 'z-index': '50' }); $("#" + el).find(".contentdesc").css({ 'display': 'none' }); })
        $("#" + el).find(".videoPromo a").click(function() { $("#" + el + " .content a").triggerHandler("click"); }); $("#" + el).find(".contentdesc").click(function() { var vidItem = $(this).parent().get(0); if (vidItem.firstChild) { if (vidItem.firstChild.tagName == "A") { $("#" + el + " .content a").triggerHandler("click"); window.location = vidItem.firstChild.href; } } });
    }
}
function submitVideoSearch() { var x = $("#nav-search").val(); if (x != "Search Video" && x != "") { window.location = "http://video.ninemsn.com.au/List.aspx?q=" + x; } else { alert("Please enter video search term"); } }
function renderShows(menu) {
    var items = menu.SubItem; var rowMax = 8; var rowTotal = 24; var html = '<ul class="header-nav-category">'; html += '<li class="header-nav-featured">'; html += '<a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_show&tag=' + encodeURIComponent(menu.FeatureTitle) + '">'; html += '<img src="' + imgServer + menu.FeatureImage + '" alt="" border="0"/>'; html += '<div class="featured-content">'; html += '<p>Featured Show</p>'; html += '<h4>' + menu.FeatureTitle + '</h4>'; html += '<p>' + menu.FeatureBody + '</p>'; html += '</div>'; html += '</a>'; html += '</li>'; html += '<li><ul class="header-nav-panel-first">'; for (var i = 0; i < rowTotal; i++) {
        html += renderShowLi(items[i], (i + 1)); var test = (i + 1) % rowMax == 0; if ((i + 1) % rowMax == 0) {
            html += '</ul></li>'; if ((i + 1) != (rowTotal - rowMax))
                html += '<li><ul>'; else
                html += '<li><ul class="header-nav-panel-last">'
        }
    }
    html += '<li class="header-nav-footer">'; html += '<span class="fl"><img src="/img/video/layout/icon_ep.gif" class="ep" alt="EP" title="Indicates entire episodes are available" /> Indicates entire episodes are available</span>'; html += '<span class="fr"><a href="http://video.ninemsn.com.au/NSIndex.aspx?ns=ninemsn_show" class="header-nav-more">View complete list of shows</a></span>'; html += '</li></ul>'; for (var i = 0; i < items.length; i++) { if (items[i].LargeIcon && items[i].name) { arrPromo[arrPromo.length] = items[i].LargeIcon; arrPromoName[arrPromoName.length] = items[i].name; arrPromoLink[arrPromoLink.length] = "http://video.ninemsn.com.au/list.aspx?ns=ninemsn_show&tag=" + items[i].name; } }
    return html;
}
function renderShowLi(el, elnum) {
    var html = '<li><a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_show&tag=' + encodeURIComponent(el.name) + '"'; if (el.IsEpisode == "true") { html += ' class="ep"'; }
    html += ' onclick=\"AdTrack.t(this,\'NH_vidwall_tv\',' + elnum + ')\">'; html += el.name; html += '</a></li>'; return html;
}
/*
function renderChannels2(menu) {
    var html = '<ul class="header-nav-category">'; html += '<li class="header-nav-featured">'; html += '<a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_channel&tag=' + encodeURIComponent(menu.FeatureTitle) + '">'; html += '<img src="' + imgServer + menu.FeatureImage + '" alt="" />'; html += '<div class="featured-content">'; html += '<p>Featured Channel</p>'; html += '<h4>' + menu.FeatureTitle + '</h4>'; html += '<p>' + menu.FeatureBody + '</p>'; html += '</div>'; html += '</a>'; html += '</li>'; var count = 0; for (var i = 0; i < 4; i++) {
        html += '<li><ul'; if (i == 0) { html += ' class="header-nav-panel-first"'; }
        else if (i == 3) { html += ' class="header-nav-panel-last"'; }
        html += '>'; for (var j = 0; j < 5; j++) {
            if (count < menu.SubItem.length)
                html += renderChannelLi(menu.SubItem[count], (count + 1)); else
                html += '<li><a href=""><img src="/img/video/layout/channels-blank.gif" alt="" /></a></li>'
            count++;
        }
        html += '</ul></li>';
    }
    html += '<li class="header-nav-footer"><span class="fr"><a href="http://video.ninemsn.com.au/NSIndex.aspx?ns=ninemsn_channel" class="header-nav-more">View complete list of channels</a></span></li>'; html += '</ul>'; for (var i = 0; i < menu.SubItem.length; i++) {
        if (menu.SubItem[i].LargeIcon && menu.SubItem[i].name) { arrPromo[arrPromo.length] = menu.SubItem[i].LargeIcon; arrPromoName[arrPromoName.length] = menu.SubItem[i].name; arrPromoLink[arrPromoLink.length] = "http://video.ninemsn.com.au/list.aspx?ns=ninemsn_channel&tag=" + menu.SubItem[i].name; }
    }
    return html;
}

function renderChannelLi2(el, elnum) { return '<li style="width:122px;height:34px"><a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_channel&tag=' + encodeURIComponent(el.name) + '" onclick=\"AdTrack.t(this,\'NH_vidwall_channels\',' + elnum + ')\"><img src="' + el.Icon.toLowerCase().replace('.png', '.gif') + '" alt="" style="margin-left:5px;margin-top:5px;" /></a></li>'; }
*/
function renderGenres(menu) {
    var cols = 3; var rows = 5; var canDisplay = cols * rows; var total = Math.min(canDisplay, menu.SubItem.length); var count = 0; var arrCount = 0; var html = []; html[arrCount++] = '<ul class="header-nav-category">'; for (i = 0; i < cols; i++) {
        html[arrCount++] = '<li><ul'
        if (i == 0)
            html[arrCount++] = ' class="header-nav-panel-first"'; else if (i == (cols - 1))
            html[arrCount++] = ' class="header-nav-panel-last"'; html[arrCount++] = '>'; for (j = 0; j < rows; j++) {
            if (count < total)
                html[arrCount++] = '<li><a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_genre&tag=' + encodeURIComponent(menu.SubItem[count].name) + '"  onclick=\"AdTrack.t(this,\'NH_vidwall_genre\',' + (count + 1) + ')\" >' + menu.SubItem[count].name + '</a></li>'; count++;
        }
        html[arrCount++] = '</ul></li>';
    }
    html[arrCount++] = '</ul>'; var test = html.join(""); return test;
}
function preloadNavImage() { var i = 0; var imageObj = new Image(); images = new Array(); images[0] = "/img/video/layout/tooltip.gif"; images[1] = "/img/video/layout/tooltip.png"; images[2] = "/img/video/layout/nav_1_ro.gif"; images[3] = "/img/video/layout/nav_2_ro.gif"; images[4] = "/img/video/layout/nav_3_ro.gif"; for (i = 0; i < images.length; i++) { imageObj.src = images[i]; } }



function SetAdTrackForTopLinks() {

    $('.header-nav-bar a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_logo', 1);
    });

    $('#header-nav-shows a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_tv', 1);
    });

    $('#header-nav-shows ul li.header-nav-featured a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_tv_featured', 1);
    });

    $('#header-nav-channels a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_channels', 1);
    });

    $('#header-nav-channels ul li.header-nav-featured a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_channels_featured', 1);
    });


    $('#header-nav-genres a:eq(0)').click(function() {
        AdTrack.t(this, 'NH_vidwall_genres', 1);
    });

    $('#nav-submit').click(function() {
        AdTrack.t(this, 'NH_vidwall_search', 1);
    });
}


function renderChannels(menu) {
    var items = menu.SubItem; var rowMax = 10; var rowTotal = 30; var html = '<ul class="header-nav-category">'; html += '<li class="header-nav-featured">'; html += '<a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_show&tag=' + encodeURIComponent(menu.FeatureTitle) + '">'; html += '<img src="' + imgServer + menu.FeatureImage + '" alt="" border="0"/>'; html += '<div class="featured-content">'; html += '<p>Featured Show</p>'; html += '<h4>' + menu.FeatureTitle + '</h4>'; html += '<p>' + menu.FeatureBody + '</p>'; html += '</div>'; html += '</a>'; html += '</li>'; html += '<li><ul class="header-nav-panel-first">'; for (var i = 0; i < rowTotal; i++) {
        html += renderShowLi(items[i], (i + 1)); var test = (i + 1) % rowMax == 0; if ((i + 1) % rowMax == 0) {
            html += '</ul></li>'; if ((i + 1) != (rowTotal - rowMax))
                html += '<li><ul>'; else
                html += '<li><ul class="header-nav-panel-last">'
        }
    }
    html += '<li class="header-nav-footer">'; 
	//html += '<span class="fl"><img src="/img/video/layout/icon_ep.gif" class="ep" alt="EP" title="Indicates entire episodes are available" /> Indicates entire episodes are available</span>';
	html += '<span class="fr"><a href="http://video.ninemsn.com.au/NSIndex.aspx?ns=ninemsn_channel" class="header-nav-more">View complete list of Channels</a></span>'; html += '</li></ul>'; for (var i = 0; i < items.length; i++) { if (items[i].LargeIcon && items[i].name) { arrPromo[arrPromo.length] = items[i].LargeIcon; arrPromoName[arrPromoName.length] = items[i].name; arrPromoLink[arrPromoLink.length] = "http://video.ninemsn.com.au/list.aspx?ns=ninemsn_channel&tag=" + items[i].name; } }
    return html;
}

function renderChannelLi(el, elnum) { return '<li style="width:122px;"><a href="http://video.ninemsn.com.au/list.aspx?ns=ninemsn_channel&tag=' + encodeURIComponent(el.name) + '" onclick=\"AdTrack.t(this,\'NH_vidwall_channels\',' + elnum + ')\">' + el.name + '</a></li>'; }






