﻿///<Summary>
/// Parse the keywords and try to find them in the content
///</Summary>
function keywordFound(content, keywords)
{
    var _content = content.toLowerCase();
    var _keywords = keywords.toLowerCase().split('/'); // parse the keywords so we can have multiple keywords per condition
    var _result = false;
    
    $.each($(_keywords), function(index, keyword){
        // DEBUG: alert(_content + " |||| " + keyword + " |||| " + _content.indexOf(keyword));
        if(_content.indexOf(keyword) >= 0)
            _result = true;
    });
    
    return _result;
}

///<Summary>
/// Initialize accordion for the side navigation. This is used for the products
///</Summary>
function initializeAccordion(element)
{
    $(element).accordion({
        autoheight: false,
        active: false, 
        animated: 'easeslide',
        event: 'mouseover',
        header: '.head', 
        navigation: true
    });
}

///<Summary>
///
///</Summary>
function initializeSlideShow(element)
{
    $(element).cycle({
        fx:     'fade', 
        speed:  'fast', 
        timeout: 5000, 
        pager:  '#slidenav',
        next: '#next',
        prev: '#prev'
    });
}

function initializeSideNavigation()
{
    // Do we want to add the tabs here?
    $("ul.tabs").tabs("div.panes > div");

    $("li a[href$='<%= BlogEngine.Core.Page.GetPage(this.Page.Parent).AbsoluteLink %>']").addClass("select");

    // Go through each condition and highlight them if they are mentioned in the body text
    var _bodyText;
    $.each($("#page p"), function(id, paragraph){
        _bodyText += paragraph.innerHTML;
    });
    
    $.each( $("#conditions li a"), function(index, value) {
        if(keywordFound(_bodyText, value.text)) {
            $(value).addClass("highlight");
        }
    });

    $.each($("li.level2 a"), function(index, value) {
        if(keywordFound(_bodyText, value.text)) {
            $(value).addClass("highlight");
        }
    });            
}
