﻿sCurrentPage = 'nutrition';

function InitGrainGuide() {
    $('#grainCopy a').click(
        function() {
            $('#grainSources').show();
        }
    );
    
    $('#sourcesHeader a').click(
        function() {
            $('#grainSources').hide();
        }
    );
}

function PopulateAndShowCurrentGrainList() {
    // Show the product list
    $('#grainList').show();
    
    // Once we show the list, initialize our Dock
    InitializeDockGrains(1);
}

function PopulateAndShowGrainDescription(sGrain, sImageName, sInfo, sLinks) {
    var sLinksArray = unescape(sLinks).split("|");
    var sLinksHTML = "";

    // If the related product list is empty, hide that module
    if (sLinksArray[1] == " - ") {
        $('#grainProductsHeader').html('');
    }
    else {
        $('#grainProductsHeader').html('Related Products:');

        // The last index is empty so only go to length - 2
        for (var n = 0; n <= sLinksArray.length - 2; n++) {
            sLinksHTML += "<p><a href=\"" + sLinksArray[n++] + "\">" + sLinksArray[n] + "</a></p>";
        }
    }

    $('#grainImage').html("<img src=\"/Images/Grains/" + sImageName + "\" alt=\"Oats\" />");
    $('#grainName').html(sGrain);
    $('#grainInfo').html(unescape(sInfo));
    $('#grainProductLinks').html(sLinksHTML);

    $('#grainGuideHowTo').hide();
    $('#grainDescription').show();
}

function InitLabel() {
    var sCurrentTopic = "Off";
                
    $('.labelsTopic a').hover(
        function() {
            var sTopic = $(this).attr('name');
            var imgLabelsSrc = '/Images/Inner/labels_' + sTopic + '.gif';
            
            // Underline the text
            $(this).css('text-decoration', 'underline');
            
            // Swap the image
            $('#imgLabels').attr('src', imgLabelsSrc);
        }, function() {
            var imgLabelsSrc = '/Images/Inner/labels_' + sCurrentTopic + '.gif';
            
            // Remove the underline
            $(this).css('text-decoration', 'none');
            
            // Swap the image
            $('#imgLabels').attr('src', imgLabelsSrc);
        }
    );

    $('.labelsTopic a').click(
        function() {
            var sTopic = $(this).attr('name');
            var sParagraphID = '#copy' + sTopic;
            
            sCurrentTopic = sTopic;
            
            if(($(sParagraphID).css('display')) == 'none') {
                // Hide all topics
                $('#labelsCopy p').css('display', 'none');
                
                // Display selected topic
                $(sParagraphID).css('display', 'block');
            }
            else {
                $(sParagraphID).css('display', 'none');
            }
        }
    );

    $('area').hover(
        function() {
            // Check for this specific map in case more are added
            if ($(this).parent().attr('id') == 'mLabels') {
                var sTopic = $(this).attr('id');
                var imgLabelsSrc = '/Images/Inner/labels_' + sTopic + '.gif';
                $('#imgLabels').attr('src', imgLabelsSrc);
                $('#link' + $(this).attr('id')).css('text-decoration', 'underline');
            }
        }, function() {
            if ($(this).parent().attr('id') == 'mLabels') {
                var imgLabelsSrc = '/Images/Inner/labels_' + sCurrentTopic + '.gif';
                $('#imgLabels').attr('src', imgLabelsSrc);
                $('#link' + $(this).attr('id')).css('text-decoration', 'none');
            }
        }
    );
    
    $('area').click(
        function() {
            if ($(this).parent().attr('id') == 'mLabels') {
                var sTopic = $(this).attr('id');
                var pCopy = $('#copy' + sTopic);
                
                sCurrentTopic = sTopic;
                
                // Hide all topics
                $('#labelsCopy p').css('display', 'none');
                                            
                // Show the clicked paragraph
                $(pCopy).css('display', 'block');
            }
        }
    );
}
