﻿//Scroll List
$(function() {
    $.fn.scrollList = function() {
        var ul = $(this).find("ul");
        var li = $(ul).find("li");
        var start = 0;
        var moveLeft = function(startNum) {
            for (var i = 0; i < startNum; i++) {
                var lw = -$(li).eq(startNum).outerWidth(true) + 'px';
                $(ul).animate({ left: lw }, {
                    duration: 200,
                    complete: function() {
                        $(ul).append($(ul).find("li:first"));
                        $(ul).css("left", "0");
                    }
                });
            }
        }
        //Init actived item
        if ($(li).length > 4) {
            for (var i = 0; i < $(li).length; i++) {
                var s = $(li).eq(i).find(".active")[0];
                if (s != undefined) {
                    start = i;
                    moveLeft(start);
                    break;
                }
            }
            $(this).find(".lkLeft").click(function() {
                moveLeft(1);
            });

            $(this).find(".lkRight").click(function() {
                var rw = -$(li).eq($(li).length - 1).outerWidth(true) + 'px';
                $(ul).animate({ left: 0 }, {
                    duration: 200,
                    complete: function() {
                        $(ul).prepend($(ul).find("li:last"));
                        $(ul).css("left", rw);
                    }
                });
            });
        }
    }
});

jQuery.fn.emptyDialog = function(dialogId, initWidth) {
    var docWidth = document.documentElement.clientWidth;
    var docHeight = $(document).height();
    var scrHeight = document.documentElement.clientHeight;
    var popPosition = "fixed";
    var topHeight = (scrHeight - $(dialogId).height()) / 2 - 20;
    if ($.browser.msie && $.browser.version == 6.0) {
        popPosition = "absolute";
        topHeight = topHeight + document.documentElement.scrollTop;
    }
    var pDiv = '<div id="pop-overlay" class="pop-overlay"></div>';
    $(pDiv).appendTo($("#mainFoot"));

    $('#pop-overlay').css({
        width: docWidth,
        height: docHeight,
        opacity: 0,
        display: "block"
    }).animate({ opacity: 0.5 }).bgiframe();

    $(dialogId).css({
        position: popPosition,
        width: initWidth,
        left: (docWidth - initWidth) / 2,
        top: topHeight,
        opcity: 1,
        display: "block"
    });

    function close() {
        $('#pop-overlay').hide(0, function() { $('#pop-overlay').remove() });
        $(dialogId).hide();
    }

    $('.pop-title a').click(function() {
        close();
    })
}
