﻿$(document).ready(function() {

    var notFrontpage = $('.notfirstpage').length > 0;

    if (notFrontpage) {

        var titleEl = $('.notfirstpage .content .area-title ');
        var titleWidth = titleEl.width();
        var titleHeigth = titleEl.height();
        var mainWidth = $(".content").width() - 8;
        var rightWidth = $("#rightbar").width();
        var leftMargin = (titleWidth) + 10;
        var borderWidht = ((mainWidth) - leftMargin) + 9;

        titleEl.prev(".borderline")
            .css("width", borderWidht + "px")
            .css("border-bottom", "solid 1px black")
            .css("margin-left", leftMargin + "px")
            .css("margin-top", Math.round(titleHeigth / 2) + "px");
    }

    $(".searchbox input").keypress(function(event) {
        if (event.which == 13) {
            event.preventDefault();
            document.location = "default.aspx?did=9081652&full9081652argument=" + $('.searchbox input').val();
        }
    }).focus(function(event) {

        $('.searchbox input').val("");
    });

    //=================================================== Pager =================================================== 
    function createPager() {
        return {
            articleEl: null,
            currentPage: 1,
            firstPage: 1,
            lastPage: 0,
            prev: function() {
                if (this.currentPage > 1) this.go2(this.currentPage - 1);
            },
            next: function() {
                if (this.currentPage < this.lastPage) this.go2(this.currentPage + 1);
            },
            go2: function(pn) {
                this.currentPage = pn;

                this.articleEl.find('.gotopage').each(function() {
                    $(this).css('font-weight', ($(this).attr('id') == pn.toString()) ? 'bold' : 'normal');                       
                });

                this.articleEl.find('.article').each(function() {
                    $(this).css('display', ($(this).attr('id') == pn.toString()) ? 'block' : 'none');
                });
            }
        };
    }

    $(".nextdiv").each(function() {
        var obj = createPager();
        var el = $(this);
        obj.lastPage = el.attr('id');
        obj.articleEl = $(this).closest('.paging-container').first();

        $(this).closest('table').find('td').each(function() {
            var clsKey = $(this).attr('class');
            if (clsKey == "prev") {
                $(this).click(function() {
                    obj.prev();
                });
            } else if (clsKey == "next") {
                $(this).click(function() {
                    obj.next();
                });
            } else if (clsKey == "gotopage") {
                $(this).click(function() {
                    obj.go2($(this).attr('id'));
                });
            }
        });

        obj.go2(1);
    });




});





