﻿function GetNews(catGuid, currLink) {
    $('#titlePnl2 ul.nav li').removeClass('sel sel2 sel3');

    $('#titlePnl2 dl').fadeTo(0.1, 0, function() {
        $(this).remove();
        var newDiv = $('<div></div>').addClass('preloader').hide();
        $('#titlePnl2 ul.nav').after(newDiv);
        newDiv.fadeIn(0.1, function() { AppendNews(catGuid) });
    });

    if ($(currLink).parent().next().length == 0) {
        $('#titlePnl2 h3').removeClass('lastChild firstChild');
        $('#titlePnl2 h3').addClass('lastChild');
        $(currLink).parent().addClass('sel3');
    }
    else if ($(currLink).parent().prev().length == 0) {
        $('#titlePnl2 h3').removeClass('lastChild firstChild');
        $('#titlePnl2 h3').addClass('firstChild');
        $(currLink).parent().addClass('sel');
    }
    else {
        $('#titlePnl2 h3').removeClass();
        $(currLink).parent().addClass('sel2');
    }
    return false;
}

function AppendNews(catGuid) {
    var ret = NewsAjax.RetrieveNews(currentLanguageId, currentWebSiteId, catGuid);
    if (ret.value != "") {
        $('div.preloader').remove();
        var newDefList = $(ret.value);
        newDefList.hide();
        $('#titlePnl2 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
    else {
        $('div.preloader').remove();
        var newDefList = $('<dl></dl>').hide();
        $('#titlePnl2 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
}

function GetEvent(catGuid, currLink) {
    $('#titlePnl1 ul.nav li').removeClass('sel sel2 sel3');

    $('#titlePnl1 dl').fadeTo(0.1, 0, function() {
        $(this).remove();
        var newDiv = $('<div></div>').addClass('preloader').hide();
        $('#titlePnl1 ul.nav').after(newDiv);
        newDiv.fadeIn(0.1, function() { AppendEvent(catGuid) });
    });

    $(currLink).parent().addClass('sel'); //Set clicked link class to active
    if ($(currLink).parent().next().length == 0) {
        $('#titlePnl1 h3').removeClass('lastChild firstChild');
        $('#titlePnl1 h3').addClass('lastChild');
    }
    else if ($(currLink).parent().prev().length == 0) {
        $('#titlePnl1 h3').removeClass('lastChild firstChild');
        $('#titlePnl1 h3').addClass('firstChild');
    }
    else {
        $('#titlePnl1 h3').removeClass();
    }
    return false;
}

function AppendEvent(catGuid) {
    var ret = EventAjax.RetrieveEvent(currentLanguageId, currentWebSiteId, catGuid);
    if (ret.value != "") {
        $('div.preloader').remove();
        var newDefList = $(ret.value);
        newDefList.hide();
        $('#titlePnl1 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
    else {
        $('div.preloader').remove();
        var newDefList = $('<dl></dl>').hide();
        $('#titlePnl1 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
}

function GetTraining(catGuid, currLink) {
    $('#titlePnl3 ul.nav li').removeClass('sel sel2 sel3');

    $('#titlePnl3 ul:last-child').fadeTo(0.1, 0, function() {
        $(this).remove();
        var newDiv = $('<div></div>').addClass('preloader').hide();
        $('#titlePnl3 ul.nav').after(newDiv);
        newDiv.fadeIn(0.1, function() { AppendTraining(catGuid) });
    });


    if ($(currLink).parent().next().length == 0) {
        $('#titlePnl3 h3').removeClass('lastChild firstChild');
        $('#titlePnl3 h3').addClass('lastChild');
        $(currLink).parent().addClass('sel3');
    }
    else if ($(currLink).parent().prev().length == 0) {
        $('#titlePnl3 h3').removeClass('lastChild firstChild');
        $('#titlePnl3 h3').addClass('firstChild');
        $(currLink).parent().addClass('sel');
    }
    else {
        $('#titlePnl3 h3').removeClass();
        $(currLink).parent().addClass('sel2');
    }
    return false;
}

function AppendTraining(catGuid) {
    var ret = TrainingAjax.RetrieveTraining(currentLanguageId, currentWebSiteId, catGuid);
    if (ret.value != "") {
        $('div.preloader').remove();
        var newDefList = $(ret.value);
        newDefList.hide();
        $('#titlePnl3 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
    else {
        $('div.preloader').remove();
        var newDefList = $('<ul></ul>').hide();
        $('#titlePnl3 ul.nav').after(newDefList);
        newDefList.fadeIn(0.1);
    }
}