﻿// PFP namespace
if (typeof (PFP) == "undefined") {
    var PFP = {};
}

// Create a namespace for recipes
if (typeof (PFP.BiggestLoser) == "undefined") {
    PFP.BiggestLoser = {
        visibleSection: "",
        currentVideoURL: ""
    };
}

PFP.BiggestLoser.showSection = function() {
    //show correct section
    $j('.videos').hide();
    $j('#' + PFP.BiggestLoser.visibleSection).show();
    //show correct bottom corner image
    $j('.cornerImage').hide();
    $j('div[rel="' + PFP.BiggestLoser.visibleSection + '"]').show();

    //highlight selected left nav link
    $j('.bl-nav a').attr('class', '');
    var selectedLink = PFP.BiggestLoser.visibleSection;
    if (PFP.BiggestLoser.visibleSection == 'previous-tips')
        selectedLink = 'tips';
    if (PFP.BiggestLoser.visibleSection == 'previous-recipes')
        selectedLink = 'recipes';
    $j('.bl-nav a[rel=' + selectedLink + ']').attr('class', 'selected');

    //set the section text header
    var headerText = $j('.bl-nav a[rel=' + PFP.BiggestLoser.visibleSection + ']').html();
    if (PFP.BiggestLoser.visibleSection == 'previous-tips')
        headerText = 'Previous Weeks\' Tips';
    if (PFP.BiggestLoser.visibleSection == 'previous-recipes')
        headerText = 'Previous Weeks\' Recipes';
    $j('#video-section-header').html(headerText);

    //show content frame and set to current item or first item in list
    $j('#video-player-container').hide();
    $j('#content-container').hide();
    window.frames['video-frame'].location = "Blank.aspx";
    window.frames['content-frame'].location = "Blank.aspx";
    if (PFP.BiggestLoser.visibleSection == "on-air" || PFP.BiggestLoser.visibleSection == "exercise") {
        $j('#video-player-container').show();
        if (PFP.BiggestLoser.currentVideoURL == '') {
            window.frames['video-frame'].location = $j('#' + PFP.BiggestLoser.visibleSection + ' a:first').attr('href');
        }
        else {
            window.frames['video-frame'].location = 'Video.aspx?vid=' + PFP.BiggestLoser.currentVideoURL;
            PFP.BiggestLoser.currentVideoURL = "";
        }
    }
    if (PFP.BiggestLoser.visibleSection == "previous-tips" || PFP.BiggestLoser.visibleSection == "previous-recipes") {
        $j('#content-container').show();
        window.frames['content-frame'].location = $j('#' + PFP.BiggestLoser.visibleSection + ' a:first').attr('href');
    }

    //change height of list container to allow for bottom corner image
    if (PFP.BiggestLoser.visibleSection == "greenleaf")
        $j("#video-list-container").hide();
    else
        $j("#video-list-container").show();

    if (PFP.BiggestLoser.visibleSection == "exercise") {
        $j("#video-list-container").css("height", "245px");
    } else {
        $j("#video-list-container").css("height", "332px");
    }
    //change width of list container to give more space for previous tips/recipes
    if (PFP.BiggestLoser.visibleSection == "previous-tips" || PFP.BiggestLoser.visibleSection == "previous-recipes") {
        $j("#video-list-container").css("width", "135px");
    } else {
        $j("#video-list-container").css("width", "223px");
    }
}

$j(document).ready(function() {
    $j('.bl ul a').click(function() {
        PFP.BiggestLoser.visibleSection = $j(this).attr('rel');
        PFP.BiggestLoser.showSection();
    });

    $j('div.videos a').click(function() {
        PFP.BiggestLoser.visibleSection = $j(this).attr('rel');
        PFP.BiggestLoser.showSection();
    });
});
