
var requireLogin = false;

$(document).ready(function () {

    inputReplacement();

    /*Setup Modals*/
    $("a.modal").fancybox({ 'speedIn': 100, 'speedOut': 100, 'onComplete': function () {
        if ($('#silverlightControlHost').length > 0 && $('#silverlightControlHost').is(':visible')) {
            $('#fancybox-wrap').css('top', '0px');
        }
        if ($('#username').length > 0) {
            $('#username').focus();
        }
    }
    });

    /*Setup hover modification*/
    $('li#accountLi').hover(function () {
        if ($('#silverlightControlHost').length > 0 && $('#silverlightControlHost').is(':visible')) {
            $(this).find('ul').css({ 'width': '600px' });
        }
    }, function () {
        if ($('#silverlightControlHost').length > 0 && $('#silverlightControlHost').is(':visible')) {
            $(this).find('ul').css({ 'width': '' });
        }
    }
    );


    $('input.enter-submit').keyup(function (e) {
        if (e.keyCode == 13) { $(this).parent().find('.enter-action').first().trigger('click'); }
    });
});

$(window).load(function () {
    /*homepage scroller*/
    $('div#home-scroll').each(function () {
        var fixed_amount = 5;
        var total = $(this).find('li').length;
        var width = $(this).find('li:first').outerWidth() + 16;
        $(this).find('ul').css('width', (total * width));
        $(this).find('a#scroll-right').click(function (e) {
            e.preventDefault();
            var target = $(this).parent().find('#home-scroll-container ul');
            var left = $(target).position().left;
            if ((fixed_amount * width) < ($(target).outerWidth() + left))
                $(target).animate({ 'left': -((fixed_amount * width) - left) })
        });
        $(this).find('a#scroll-left').click(function (e) {
            e.preventDefault();
            var target = $(this).parent().find('#home-scroll-container ul');
            var left = $(target).position().left;
            if (left < 0)
                $(target).animate({ 'left': ((fixed_amount * width) + left) })
        });
    });
});

function inputReplacement() {
    /*input replacement*/
    $('.inprep').each(function () {
        var oval = $(this).val();
        $(this).css('color', '#B7B7B7').focus(function () {
            if ($(this).val() == oval) { $(this).val('').css('color', ''); }
        }).blur(function () {
            if ($(this).val() == '' && $(this).attr('type') != 'password') { $(this).css('color', '#B7B7B7').val(oval); }
        });
    });
}

function renderPaging(pageDiv, totalPage, currentPage) {
    pageDiv.empty();
    if (totalPage > 1) {
        pageDiv.each(function () {
            if (currentPage > 1) {
                $(this).append("<li><a href='#' page='1'>&lt;&lt; First page</a></li>");
                if (currentPage > 2) {
                    $(this).append("<li><a href='#' page='" + (currentPage - 1) + "'>&lt; Previous page</a></li>");
                }
            }

            var min = currentPage;
            var max = currentPage;
            for (var i = 0; i < 4; i++) {
                if (i % 2 && min - 1 >= 1) {
                    min--;
                    continue;
                }

                if (max + 1 <= totalPage) {
                    max++;
                } else if (min - 1 >= 1) {
                    min--;
                }
            }

            for (; min <= max; min++) {
                if (min == currentPage) {
                    $(this).append("<li class='activepage'>" + min + "</li>");
                } else {
                    $(this).append("<li><a href='#' page='" + min + "'>" + min + "</a></li>");
                }
            }

            if (currentPage < totalPage) {
                if (currentPage < totalPage - 1) {
                    $(this).append("<li><a href='#' page='" + (currentPage + 1) + "'>Next page &gt;</a></li>");
                }
                $(this).append("<li><a href='#' page='" + totalPage + "'>Last page &gt;&gt;</a></li>");
            }
        });
    }
}

if ('function' != typeof(onLogin)) {
	onLogin = function()
	{
	}
}

if ('function' != typeof(onLogout)) {
	onLogout = function()
	{
	}
}

