﻿$(document).ready(function() {
    ScrolingSectors();
    ScrolingLocations();
    ScrolingSources();
    ScrolingJobTitles();
});

function ScrolingSectors() {
    ScrolingLinks("#tabcs", "div.tab_ctn_sec", 10, "", '<div style="float:right; width:55px;">', '</div>');
}

function ScrolingLocations() {
    ScrolingLinks("#tabcl", "div.tab_ctn_lcn", 15, "", '<div style="float:right; width:55px;">', '</div>');
}

function ScrolingSources() {
    try {
        ScrolingLinks("#" + GetUlJobSourceID(), "li", 5, "undo", "<li>", "</li>");
    }
    catch (ex) { }
}

function ScrolingJobTitles() {
    try {
        ScrolingLinks("#" + GetUlJobTitleID(), "li", 5, "undo", "<li>", "</li>");
    }
    catch (ex) { }
}

function ScrolingLinks(parentPattern, childrenPattern, countElements, className, startTag, endTag) {
    var index = 1;
    $(parentPattern + " " + childrenPattern).each(function() {
        if (index > countElements) {
            $(this).css("display", "none");
        }
        index++;
    });
    if (index - 1 > countElements) {
        var link = startTag + '<a href="javascript:void(0);" rel="nofollow" title="more" onclick="ScrolingLinksShowHide(this,\''
        + parentPattern + '\',\'' + childrenPattern + '\', ' + countElements + ');" class="' + className + '">more</a>' + endTag;
        $(parentPattern).html($(parentPattern).html() + link);
    }
}

function ScrolingLinksShowHide(el, parentPattern, childrenPattern, countElements) {
    if ($(el).text() == "more") {
        $(parentPattern + " " + childrenPattern).each(function() {
            $(this).css("display", "");
        });
        $(el).text("back");
        $(el).attr("title", "back");
    }
    else if ($(el).text() == "back") {
        var index = 1;
        $(parentPattern + " " + childrenPattern).each(function() {
            if (index > countElements) {
                $(this).css("display", "none");
            }
            index++;
        });
        $(el).text("more");
        $(el).attr("title", "more");
    }
    $(el).parent().css("display", "");
}
