﻿/**
 * 自建模块初始化方法
 */
function module_custom_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_custom", self);
    var scrollable = container.attr("scroll").toLowerCase() == "true";

    if (!scrollable) {
        return;
    }

    var speed = parseInt(container.attr("speed"));
    var height = parseInt(container.attr("height"));

    container.wrapInner("<ul class=\"scroll-item\"><li></li></ul>");

    if (height > $("li:first", container).height()) {
        return;
    }

    container.css({
        "overflow": "hidden",
        "height": height + "px"
    });
    $(">ul>li:first", container).clone().appendTo($(">ul", container));

    var ul = $(">ul", container)[0];
    var clip2 = $(">li:eq(1)", ul)[0];
    var clip1 = $(">li:eq(0)", ul)[0];
    function marquee() {
        var offset = Math.abs(parseInt($(ul).css("margin-top").replace("px", "")));
        if (offset >= clip1.offsetHeight) {
            ul.style.marginTop = offset - clip1.offsetHeight + "px";
        }
        else {
            ul.style.marginTop = -(offset + 1) + "px";
        }
    }
    var scrolling = setInterval(marquee, speed);
    ul.onmouseover = function() {
        clearInterval(scrolling);
    }
    ul.onmouseout = function() {
        scrolling = setInterval(marquee, speed);
    }
};

/**
 * 导航模块初始化方法
 */
function module_navigator_init(id) {
    var self = $("#" + id);
    $(".aw_m_navigator li:has(ul)", self).addClass("sub");
    $(".aw_m_navigator li", self).mouseover(function() {
        var $this = $(this);
        var ul = $(">ul", this);
        if (ul.size() > 0 && !ul.is(":visible")) {
            $(">ul:visible", $this.siblings("li").removeClass("sub_down")).slideUp();

            ul.slideDown("fast")
            $(this).addClass("sub_down");
        }
        return false;
    });
};

/**
 * 时钟模块初始化方法
 */
function module_clock_init(id) {
    var self = $("#" + id);
    var src = $(".aw_m_clock", self).attr("src");
    var w = $(".item-content", self).innerWidth();
    $(".aw_m_clock", self).flash({
        swf: src,
        width: w,
        height: w,
        params: {
            wmode: "transparent"
        }
    });
};
function module_clock_reset(id) {
    module_clock_init(id);

    var self = $("#" + id);
    $("object, embed", self).css("visibility", "visible");
}

/**
 * 日历模块初始化方法
 */
function module_calendar_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_calendar", self);
    var culture = container.attr("culture");
    if (culture == "en") {
        culture = '';
    }
    var option = $.datepicker.regional[culture];
    container.datepicker(option);
    $(".item-content", self).css("overflow", "visible");
};

/**
 * TabView模块初始化方法
 */
function module_tabview_init(id) {
    var self = $("#" + id);
    var moduleId = id.split("-")[1];
    var tabs = $(".aw_m_tabview>ul.tabs>li.tab-item", self);
    var panels = $(".aw_m_tabview>div>ul.panels>li.panel-item", self);

    if ($.browser.IE6) {
        $(".aw_m_tabview>div>ul.panels", self).css({
            "height": $(".aw_m_tabview>ul.tabs", self).height()
        });
    }
    else {
        $(".aw_m_tabview>div>ul.panels", self).css({
            "min-height": $(".aw_m_tabview>ul.tabs", self).height()
        });
    }

    tabs.each(function() {
        var item = $(this);
        item.click(function() {
            tabs.removeClass("active");

            $(this).addClass("active");
            activePanel();
            return false;
        });

        if (app_vars.design) {
            var itemid = $("a.link", item).attr("rel");
            var editlink = $(document.createElement("a")).attr({
                "href": window.location.protocol + "//" + window.location.host + app_vars.sitePath + "controlpanel/tabview/entryeditor.aspx?moduleid=" + moduleId + "&id=" + itemid,
                "target": "_blank",
                "class": "edit ui-icon ui-icon-wrench ui-corner-all"
            }).nyroModal({
                //debug: true,
                modal: true
            });
            var deletelink = $(document.createElement("a")).attr({
                "href": "#",
                "class": "delete ui-icon ui-icon-closethick ui-corner-all"
            }).click(function() {
                if (!confirm("您确定要删除此条目吗？")) {
                    return false;
                }
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: app_vars.sitePath + "controlpanel/tabview/ajaxhandler.ashx?action=DeleteEntry",
                    data: { "id": itemid },
                    global: false,
                    success: function(result) {
                        if (result.success) {
                            $.success({
                                message: result.message
                            });
                            body.reloadModule(id);
                        }
                        else {
                            $.error({
                                message: result.message
                            });
                        }
                    }
                });
                return false;
            });
            $("span.action", item).append(editlink).append(deletelink).find("a").hover(function() {
                $(this).addClass("ui-state-default");
            }, function() {
                $(this).removeClass("ui-state-default");
            });
        }
    });

    tabs.eq(0).trigger("click");

    $(".quickbar .clear a", self).click(function() {
        if (!confirm("您确定要清空所有条目吗？")) {
            return false;
        }
        $.ajax({
            type: "post",
            dataType: "json",
            url: app_vars.sitePath + "controlpanel/tabview/ajaxhandler.ashx?action=ClearEntries",
            data: { "moduleId": moduleId },
            global: false,
            success: function(result) {
                if (result.success) {
                    $.success({
                        message: result.message
                    });
                    body.reloadModule(id);
                }
                else {
                    $.error({
                        message: result.message
                    });
                }
            }
        });
        return false;
    });

    function activePanel() {
        var index = tabs.index(tabs.filter(".active"));
        panels.hide().eq(index).show();
    };
};

/**
 * RSS订阅模块初始化方法
 */
function module_rssreader_init(id) {
    var self = $("#" + id);
    var ajaxlistview = $(".ajaxlistview", self);

    var rssfeed = ajaxlistview.attr("rssfeed");
    var pagesize = ajaxlistview.attr("pagesize");
    var encoding = ajaxlistview.attr("encoding");
    var titleonly = ajaxlistview.attr("titleonly").toLowerCase() == "true";
    var showtime = ajaxlistview.attr("showtime").toLowerCase() == "true";

    ajaxlistview.append("<div class=\"loading\"></div>");

    $.getFeed({
        url: app_vars.appPath + "AjaxProxy.axd",
        data: {
            "url": rssfeed,
            "encoding": encoding
        },
        global: false,
        success: function(data) {
            if (data.items.length == 0) {
                $(">.loading", ajaxlistview).removeClass(".loading").addClass("failture");
                return;
            }
            data.items = $.grep(data.items, function(n, i) {
                if (n.pubDate) {
                    n.updated = n.pubDate;
                }
                return i < pagesize;
            });
            //console.log(data.items);
            data.total = data.items.length;
            ajaxlistview_init(ajaxlistview, {
                datasource: data,
                pagesize: pagesize,
                pagebuttoncount: 5,
                showpagination: false,
                onajaxloaded: function(container) {

                    $(".updated", self).each(function() {
                        var updated = new Date($(this).text()).toLocaleDateString();
                        //console.log(updated.toString());
                        if (updated.toString() == "Invalid Date" || updated.toString() == "NaN") {
                            updated = $(this).text();
                        }
                        $(this).text(updated);
                    });

                    if (titleonly) {
                        $(".title", self).css("font-weight", "400");
                        $(".description", self).hide();
                    }

                    if (!showtime) {
                        $(".updated", self).hide();
                    }

                    $(">.loading", ajaxlistview).remove();
                },
                paramname: {
                    pageindex: "pageindex",
                    pagesize: "pagesize",
                    recordcount: "total"
                }
            });
        }
    });
};

/**
* 留言簿模块初始化方法
*/
function module_guestbook_init(id) {
    var self = $("#" + id);
    var ajaxlistview = $(".ajaxlistview", self);

    var submitbutton = $(".poster .submit", self);
    if (!submitbutton.attr("binded")) {
        submitbutton.click(function() {
            submitbutton.attr("binded", "true");
            module_guestbook_post(id);
            return false;
        });
    }
    if (!submitbutton.attr("themed")) {
        submitbutton.button();
    }
    var pagesize = ajaxlistview.attr("pagesize");

    ajaxlistview_init(ajaxlistview, {
        datasource: app_vars.sitePath + "ControlPanel/GuestBook/AjaxHandler.ashx?action=GetList",
        pagesize: pagesize,
        pagebuttoncount: 5,
        onajaxloaded: function(container) {
            if (app_vars.design) {
                $(".action", container).show();
                $(".postby .ip", container).show();

                if ($(".action a.delete", container).size() > 0) {
                    $(".action a.delete", container).click(function() {
                        var tid = $(this).attr("rel");
                        module_guestbook_delete(id, tid);
                        return false;
                    });
                }
                if ($(".action a.reply", container).size() > 0) {
                    $(".action a.reply", container).click(function() {
                        var tid = $(this).attr("rel");
                        var reply = $(".reply-area", container);
                        if (reply.size() == 0) {
                            reply = $(document.createElement("div")).addClass("reply-area");
                        }
                        var li = $(this).closest("li");
                        var reply_body = $(".reply-body", li);
                        var reply_content = "";
                        $(".reply-body", container).show();
                        if (reply_body.size() > 0) {
                            reply_content = $.trim(reply_body.clone().find("span").remove().end().text());
                            reply_body.hide();
                        }
                        $(".content-body", li).after(reply);
                        var textarea = $(document.createElement("textarea")).val(reply_content).focus().click(function() {
                            return false;
                        });
                        var submiter = $(document.createElement("input")).val("提交").attr({
                            type: "button"
                        }).click(function() {
                            module_guestbook_reply(id, tid, textarea.val());
                            return false;
                        });
                        reply.empty().append(textarea).append("<br>").append(submiter);

                        $(document).one("click", function() {
                            reply.remove();
                            $(".reply-body", container).show();
                        });
                        return false;
                    });
                }
            }

            $(".pagination a, .pagination span", self).addClass(id + " x-border-color");
        },
        paramname: {
            pageindex: "pageindex",
            pagesize: "pagesize",
            recordcount: "total"
        }
    });
};

/**
 * 留言簿模块回复方法
 */
function module_guestbook_reply(id, postId, val) {
    if (!id || !postId) {
        return;
    }
    if (!val) {
        val = "";
    }
    //alert(1);
    $.ajax({
        type: "post",
        dataType: "json",
        url: app_vars.sitePath + "ControlPanel/GuestBook/AjaxHandler.ashx?action=Reply",
        data: { "postId": postId, "reply": val },
        global: false,
        success: function(result) {
            if (result.success) {
                module_guestbook_init(id);
                $.success({
                    message: result.message
                });
            }
            else {
                $.error({
                    message: result.message
                });
            }
        }
    });
};

/**
 * 留言簿模块删除方法
 */
function module_guestbook_delete(id, postId) {
    if (!id || !postId) {
        return;
    }
    if (!confirm("您确定要删除这条信息吗？")) {
        return;
    }
    //alert(id);
    $.ajax({
        type: "post",
        dataType: "json",
        url: app_vars.sitePath + "ControlPanel/GuestBook/AjaxHandler.ashx?action=Delete",
        data: { "postId": postId },
        global: false,
        success: function(result) {
            if (result.success) {
                module_guestbook_init(id);
                $.success({
                    message: result.message
                });
            }
            else {
                $.error({
                    message: result.message
                });
            }
        }
    });
};

/**
 * 留言簿模块发布留言方法
 */
function module_guestbook_post(id) {
    var self = $("#" + id);

    var postbox = $(".poster", self);

    var username = $(".username input", postbox).val();
    var email = $(".email input", postbox).val();
    var content = $(".content textarea", postbox).val();

    if ($.trim(username).length == 0) {
        $.error({ message: "请输入您的大名！" });
        return;
    }

    if ($.trim(email).length > 0) {
        if (!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(email)) {
            $.error({ message: "请输入正确的邮件地址，或者留空。" });
            return;
        }
    }

    if ($.trim(content).length == 0) {
        $.error({ message: "请输入留言内容！" });
        return;
    }

    if ($.trim(content).length > 2000) {
        $.error({ message: "请留言内容请保持在2000个字符以内！" });
        return;
    }

    setTimeout(function() {
        var data = {
            username: username,
            email: email,
            content: content
        };

        $.ajax({
            type: "post",
            dataType: "json",
            url: app_vars.sitePath + "ControlPanel/GuestBook/AjaxHandler.ashx?action=Post",
            data: data,
            global: false,
            cache: false,
            success: function(result) {
                if (result.success) {
                    try {
                        $(".module-item[id^='GuestBook-']").each(function() {
                            module_guestbook_init(this.id);
                        });
                    }
                    catch (e) { }
                    $.success({
                        message: result.message
                    });
                    $(".username input", self).val($(".username input", self)[0].defaultValue);
                    $(".email input", self).val("");
                    $(".content textarea", self).val("");
                }
                else {
                    $.error({
                        message: result.message
                    });
                }
            }
        });
    }, 10);

    return false;
};

/**
 * 留言发布模块初始化方法
 */
function module_guestbookposter_init(id) {
    var self = $("#" + id);
    $(".poster .submit", self).click(function() {
        module_guestbook_post(id);
        return false;
    });
};

/**
 * 整箱运价模块初始化方法
 */
function module_shipperfcl_init(id) {
    setTimeout(function() { shipper_common_init(id, "GetFCLList") }, 10);
};

/**
 * 推荐整箱运价模块初始化方法
 */
function module_shipperfclrecommended_init(id) {
    setTimeout(function() { shipper_common_init(id, "GetRecommendedFCLList") }, 10);
};

/**
 * 拼箱运价模块初始化方法
 */
function module_shipperlcl_init(id) {
    setTimeout(function() { shipper_common_init(id, "GetLCLList") }, 10);
};

/**
 * 运价模块通用初始化方法
 */
function shipper_common_init(id, action) {

    var self = $("#" + id);
    var ajaxlistview = $(".ajaxlistview", self);
    var pagesize = ajaxlistview.attr("pagesize");

    ajaxlistview_init(ajaxlistview, {
        datasource: app_vars.sitePath + "ControlPanel/Shipper/AjaxHandler.ashx?action=" + action,
        pagesize: pagesize,
        pagebuttoncount: 5,
        showpagination: (action !== "GetRecommendedFCLList"),
        onajaxloaded: function(container) {
            $("a.inlinebox", container).nyroModal({
                //debug: true
            });

            $(".pagination", self).addClass(id + " x-border-color");
            $(".pagination a, .pagination span", self).addClass(id + " x-border-color");
        },
        paramname: {
            pageindex: "pageindex",
            pagesize: "pagesize",
            recordcount: "total"
        }
    });
};

/**
 * 公司新闻模块初始化方法
 */
function module_orgnews_init(id) {
    setTimeout(function() { org_common_init(id, "GetOrgNewsList") }, 10);
};
/**
 * 公司通知模块初始化方法
 */
function module_orgnotice_init(id) {
    setTimeout(function() { org_common_init(id, "GetOrgNoticeList") }, 10);
};
/**
 * 公司模块通用初始化方法
 */
function org_common_init(id, action) {

    var self = $("#" + id);
    var ajaxlistview = $(".ajaxlistview", self);
    var pagesize = parseInt( ajaxlistview.attr("pagesize"));

    var scrollable = ajaxlistview.attr("scroll").toLowerCase() == "true";
    var speed = parseInt(ajaxlistview.attr("speed"));
    var line = parseInt(ajaxlistview.attr("line"));
    var timer = parseInt(ajaxlistview.attr("timer"));
    var showtime = ajaxlistview.attr("showtime").toLowerCase() == "true";

    ajaxlistview_init(ajaxlistview, {
        datasource: app_vars.sitePath + "ControlPanel/Shipper/AjaxHandler.ashx?action=" + action,
        pagesize: scrollable ? pagesize * 3 : pagesize,
        pagebuttoncount: 5,
        showpagination: !scrollable,
        onajaxloaded: function(container) {
            $("a.inlinebox", container).nyroModal();

            $(".pagination", self).addClass(id + " x-border-color");
            $(".pagination a, .pagination span", self).addClass(id + " x-border-color");

            if (scrollable && $("li", container).size() > line) {
                var height = $("li:first", container).height() * line;
                container.height(height).css({
                    "overflow": "hidden"
                });
                container.textSlider({ line: line, speed: speed, timer: timer });
            }

            if (!showtime) {
                $(".time", container).hide();
            }
        },
        paramname: {
            pageindex: "pageindex",
            pagesize: "pagesize",
            recordcount: "total"
        }
    });
};

/**
 * 登录入口
 */
function module_orglogin_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_orglogin", self);
    
    insertIFrame(container, self);
};
//插入iFrame
function insertIFrame(container, module) {
    var src = container.attr("src");

    var iframe = $("<iframe allowtransparency=\"true\" width=\"100%\" frameborder=\"0\" scrolling=\"no\"></iframe>")
        .appendTo(container);
    resizeIFrame(iframe[0]);
    iframe.attr({
        "src": polishSrc(src, getModuleStyle(module))
    });
};
//修饰路径
function polishSrc(src, color, widthRandom) {
    var path = src;

    if (src.indexOf("?") > -1) {
        path += "&";
    }
    else {
        path += "?";
    }
    if (widthRandom) {
        color["_"] = $.randomKey();
    }
    path += $.param(color);

    return path;
};
//获取样式
function getModuleStyle(module) {
    return {
        fontColor: $.RGBToHex($(".item-content", module).css("color")).replace("#", ""),
        bgColor: $.RGBToHex(module.css("background-color")).replace("#", ""),
        fontTitle: $.RGBToHex($(".item-title", module).css("color")).replace("#", ""),
        bgTitle: $.RGBToHex($(".item-title", module).css("background-color")).replace("#", "")
    };
};
/**
 * 运费预算
 */
function module_shippercarriagebudget_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_shippercarriagebudget", self);

    insertIFrame(container, self);
};
/**
 * 运价查询
 */
function module_shippercarriagequery_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_shippercarriagequery", self);

    insertIFrame(container, self);
};
/**
 * 货物追踪
 */
function module_shippergoodstrack_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_shippergoodstrack", self);

    insertIFrame(container, self);
};
/**
 * 网上营业厅
 */
function module_shipperservicehall_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_shipperservicehall", self);

    var src = container.attr("src");

    var iframe = $("iframe", container);
    resizeIFrame(iframe[0]);
    iframe.attr({
        "src": polishSrc(src, getModuleStyle(self))
    });

    //console.log("service hall inited!");
};
/**
 * 网上营业厅导航
 */
function module_shipperservicehallnav_init(id) {
    var self = $("#" + id);
    var container = $(".aw_m_shipperservicehallnav", self);

    function createUL(data, istop) {
        if (!istop) {
            istop = false;
        }
        var ul = $("<ul></ul>");
        if (!istop) {
            ul.hide();
        }
        //console.log(data);

        $.each($.grep(data, function(n, i) {
            return i > 2;
        }), function(i, n) {
            ul.append(createLI(n, istop));
        });

        return ul;
    }
    function createLI(data, istop) {
        if (!istop) {
            istop = false;
        }
        //data[0] // name
        //data[1] // path
        //data[2] // icon
        //data[3] // sub
        var li = $("<li></li>");

        if (typeof data == 'undefined') {
            return;
        }
        var path = data[1];
        if (path) {
            path = polishSrc(path, getModuleStyle(self), true);
        }
        else {
            path = "#";
        }

        var link = $("<a></a>").text(data[0]).attr({
            "href": path,
            "target": "serviceHall"
        }).appendTo(li).click(function() {
            if (path != "#") {
                $.overlay();
                $("#serviceHall").attr("src", path).one("load", function() {
                    $.unOverlay();
                });
            }
            //return false;
        });

        if (typeof data[3] != 'undefined') {
            li.append(createUL(data));
        }

        return li;
    }

    $.ajax({
        type: "get",
        url: container.attr("src"),
        cache: false,
        global: false,
        dataType: "json",
        success: function(data) {
            if (data) {
                $(".loading", container).remove();
                container.append(createUL(data, true));

                //console.log("menu created!");
                //延迟初始化
                module_shipperservicehall_init($("#serviceHall").closest(".module-item").attr("id"));

                $("li:has(ul),li ul", container).addClass("sub");
                $(">ul", container).addClass("nav");
                $("li", container).addClass("item").find("a").click(function() {
                    var $this = $(this).closest("li");
                    var ul = $(">ul", $this);
                    if (ul.size() > 0 && !ul.is(":visible")) {
                        $(">ul:visible", $this.siblings("li").removeClass("sub_down")).slideUp();

                        ul.slideDown("fast")
                        $this.addClass("sub_down");
                    }
                    return false;
                });
            }
        },
        error: function() {
            $(".loading", container).removeClass(".loading").addClass("failture");
        }
    });

    if (!app_vars.design) {
        var col = container.closest("[id^='column']");
        var x = col.width() - 143;
        var col2 = $("#serviceHall").closest("[id^='column']");

        col.width(143);
        col2.css("margin-left", parseInt(col2.css("margin-left").replace("px", "")) - x);
    }
};

/**
* 相册模块初始化方法
*/
function module_imagegallery_init(id) {
    var self = $("#" + id);
    $("a.gallery-item", self).nyroModal();
};

/**
 * 幻灯相册模块初始化方法
 */
function module_imageslider_init(id) {
    var self = $("#" + id);
    var moduleId = id.split("-")[1];
    var w = $(".item-content", self).innerWidth();
    var h = w * 3 / 4;
    var cw = w * 0.5;
    $(".aw_m_image-slider", self).gallery({ json: app_vars.sitePath + "ControlPanel/ImageGallery/AjaxHandler.ashx?action=GetGalleryImageList&moduleId=" + moduleId + "&pageId=" + app_vars.pageId,
        sw: 60, sh: 45, pw: w, ph: h, cw: cw, mode: 1, easing: 'BounceEaseOut'
    });
};

/**
 * 滚动相框模块初始化方法
 */
function module_imagescroller_init(id) {
    var self = $("#" + id);
    var w = $(".item-content", self).innerWidth();

    var horizontal = ($(".aw_m_image-scroller", self).attr("horizontal") == "true");

    // 取第一张图片的大小为统一的尺寸
    if (!horizontal) {
        $("<img/>").hide().appendTo("body").load(function() {
            var h = $(this).height() * w / $(this).width();
            //alert(h);
            $(".aw_m_image-scroller ul, .aw_m_image-scroller .simply-scroll, .aw_m_image-scroller .simply-scroll .simply-scroll-clip", self).height(h);
            $(this).remove();
        }).attr("src", $(".aw_m_image-scroller ul li:first img", self).attr("src"));
    }

    $(".aw_m_image-scroller ul", self).simplyScroll({
        autoMode: 'loop',
        horizontal: horizontal
    });
};
function module_imagescroller_reset(id) {
    var self = $("#" + id);
    var w = $(".item-content", self).innerWidth();
    
    var horizontal = ($(".aw_m_image-scroller", self).attr("horizontal") == "true");
    
    // 取第一张图片的大小为统一的尺寸
    if (!horizontal) {
        $("<img/>").hide().appendTo("body").load(function() {
            var h = $(this).height() * w / $(this).width();
            $(".aw_m_image-scroller ul, .aw_m_image-scroller .simply-scroll, .aw_m_image-scroller .simply-scroll .simply-scroll-clip", self).height(h);
            $(this).remove();
        }).attr("src", $(".aw_m_image-scroller ul li:first img", self).attr("src"));
    }
};

/**
 * 轮换相框模块初始化方法
 */
function module_imagerotateslider_init(id) {
    var self = $("#" + id);
    var w = $(".item-content", self).innerWidth();

    $(".aw_m_image-rotate-slider ul", self).s3Slider({
        timeOut: 3000
    });

    // 取第一张图片的大小为统一的尺寸
    $("<img/>").hide().appendTo("body").load(function() {
        var h = $(this).height() * w / $(this).width();
        $(".aw_m_image-rotate-slider, .aw_m_image-rotate-slider li span.left, .aw_m_image-rotate-slider li span.right", self).height(h);
        $(".aw_m_image-rotate-slider, .aw_m_image-rotate-slider img", self).width(w).height(h);
        $(this).remove();
    }).attr("src", $(".aw_m_image-rotate-slider ul li:first img", self).attr("src"));
};

/**
 * 轮换相框模块初始化方法
 */
function module_imagecrossslider_init(id) {
    var self = $("#" + id);
    var moduleId = id.split("-")[1];

    $.ajax({
        url: app_vars.sitePath + "ControlPanel/ImageGallery/AjaxHandler.ashx?action=GetGalleryImageList&moduleId=" + moduleId + "&pageId=" + app_vars.pageId,
        dataType: "json",
        global: false,
        cache: false,
        success: function(data) {
            init(data);
        }
    });

    function init(data) {
        var container = $('.aw_m_image-cross-slider', self);
        var w = $(".item-content", self).innerWidth();
        var h = w * 3 / 4;
        container.width(w).height(h);

        var options = [
            { from: '100% 80% 1x', to: '100% 0% 1.7x', time: 3 },
            { from: 'top left', to: 'bottom right 1.5x', time: 2 },
            { from: '100% 80% 1.5x', to: '80% 0% 1.1x', time: 2 },
            { from: '100% 50%', to: '30% 50% 1.5x', time: 2}];

        var list = new Array();

        for (var i = 0; i < data.length; i++) {
            var option = options[parseInt($.random(0, 3))];
            list.push({
                src: data[i].image,
                from: option.from,
                to: option.to,
                time: option.time
            });
        }
        container.crossSlide({
            //sleep: 1,
            fade: 1
        }, list);
    };
};

/**
 * 客户端数据绑定及分页通用方法
 */
function ajaxlistview_init(element, options, pageindex) {
    var settings = $.extend({}, {
        datasource: "",
        pagesize: 10,
        pagebuttoncount: 9,
        showpagination: true,
        paramname: {
            pageindex: "pageindex",
            pagesize: "pagesize",
            recordcount: "recordcount"
        },
        onajaxloaded: null,
        onpagechanging: null,
        onpagechanged: null
    }, options);

    if ($(".container", element).size() == 0) {
        $('<div class="container"><div class="loading"></div><div class="datalist" style="display: none;"></div></div><div class="pagination" style="display: none;"></div>').appendTo(element);
    }
    settings.template = $(".template", element);
    settings.loading = $(".loading", element);
    settings.container = $(".datalist", element);
    settings.pagination = $(".pagination", element);

    if (!pageindex) {
        pageindex = 1;
    }

    var data = {};
    data[settings.paramname.pageindex] = pageindex;
    data[settings.paramname.pagesize] = settings.pagesize;

    if ((typeof settings.datasource).toLowerCase() == "string") {
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: settings.datasource,
            data: data,
            cache: false,
            global: false,
            success: function(data) {
                render(data);
            }
        });
    }
    else {
        //console.log(settings.datasource);
        render(settings.datasource);
    }

    function render(data) {

        if (data[settings.paramname.recordcount] > 0) {
            settings.container.setTemplateElement(settings.template[0].id);
            settings.container.processTemplate(data);

            //console.log(settings.template[0].id);
            //console.log(data);

            if (settings.showpagination) {
                settings.pagination.show().pagination(data[settings.paramname.recordcount], {
                    num_edge_entries: 1,
                    num_display_entries: options.pagebuttoncount,
                    items_per_page: settings.pagesize,
                    current_page: pageindex - 1,
                    callback: function(currentPage) {
                        if ($.isFunction(settings.onpagechanging)) {
                            settings.onpagechanging(settings.container, currentPage);
                        }
                        settings.pagechanged = true;
                        ajaxlistview_init(element, settings, currentPage + 1);

                        return false;
                    }
                });
            }

            settings.loading.hide();
        }
        else {
            settings.loading.removeClass(".loading").addClass("failture").show();
        }
        settings.container.show();

        //onajaxloaded
        if ($.isFunction(settings.onajaxloaded)) {
            settings.onajaxloaded(settings.container);
        }
        if (settings.pagechanged && $.isFunction(settings.onpagechanged)) {
            settings.onpagechanged(settings.container, pageindex);
        }
    };
};


/*
 * jquery.jfeed.js
 */jQuery.getFeed=function(a){a=jQuery.extend({url:null,data:null,success:null,global:true},a);if(a.url){$.ajax({type:"GET",url:a.url,data:a.data,dataType:"xml",global:a.global,success:function(b){var c=new JFeed(b);if(jQuery.isFunction(a.success)){a.success(c)}}})}};function JFeed(a){if(a){this.parse(a)}}JFeed.prototype={type:"",version:"",title:"",link:"",description:"",parse:function(a){if(jQuery("channel",a).length==1){this.type="rss";var b=new JRss(a)}else{if(jQuery("feed",a).length==1){this.type="atom";var b=new JAtom(a)}}if(b){jQuery.extend(this,b)}}};function JFeedItem(){}JFeedItem.prototype={title:"",link:"",description:"",updated:"",id:""};function JAtom(a){this._parse(a)}JAtom.prototype={_parse:function(a){var b=jQuery("feed",a).eq(0);this.version="1.0";this.title=jQuery(b).find("title:first").text();this.link=jQuery(b).find("link:first").attr("href");this.description=jQuery(b).find("subtitle:first").text();this.language=jQuery(b).attr("xml:lang");this.updated=jQuery(b).find("updated:first").text();this.items=new Array();var c=this;jQuery("entry",a).each(function(){var d=new JFeedItem();d.title=jQuery(this).find("title").eq(0).text();d.link=jQuery(this).find("link").eq(0).attr("href");d.description=jQuery(this).find("content").eq(0).text();d.updated=jQuery(this).find("updated").eq(0).text();d.id=jQuery(this).find("id").eq(0).text();c.items.push(d)})}};function JRss(a){this._parse(a)}JRss.prototype={_parse:function(a){if(jQuery("rss",a).length==0){this.version="1.0"}else{this.version=jQuery("rss",a).eq(0).attr("version")}var b=jQuery("channel",a).eq(0);this.title=jQuery(b).find("title:first").text();this.link=jQuery(b).find("link:first").text();this.description=jQuery(b).find("description:first").text();this.language=jQuery(b).find("language:first").text();this.updated=jQuery(b).find("lastBuildDate:first").text();this.items=new Array();var c=this;jQuery("item",a).each(function(){var d=new JFeedItem();d.title=jQuery(this).find("title").eq(0).text();d.link=jQuery(this).find("link").eq(0).text();d.description=jQuery(this).find("description").eq(0).text();d.updated=jQuery(this).find("pubDate").eq(0).text();d.id=jQuery(this).find("guid").eq(0).text();c.items.push(d)})}};

/**
 * pop gallery
 *
 */(function($){$.fn.gallery=function(o){var J=this;var cw=300;var pw=800;var ph=500;var sw=80;var sh=50;var total=0;var index=0;var pc=0;var per=0;var data=null;var thumbs=[];var cursor=1;var cstate=1;var mode=0;var easing="";var gallerydoor,gallerydoorbody,gallerycontrol,galleryphotos,gallerywin,gallerybar,gallerycontrolimg,gallerycount,galleryname,D;J.easing=function(sth){easing=sth};J.gotoIndex=function(i){i=Math.floor(i);index=i;if(i>total-1||i<0){return false}gallerycount.text(i+1);galleryname.text(D[i].title);index=i;image(i);per=(i*(sw+5)-((pw-10)-(sw+5))/2)/pc;if(pc+5>pw){hi()}};J.preLoad=function(){for(var i=total-1;i>=0;i--){D[i].win=new Image();D[i].win[0]=i;D[i].win.onload=function(){if(this[0]==index){J.resize()}};if(mode==1&&i!=0){D[i].win.src=D[i].image}}J.gotoIndex(0)};function image(i){gallerywin.css("opacity",0.3);D[i].win.src=D[i].image;if(mode==0){if(index+1<total){D[index+1].win.src=D[index+1].image}if(index>0){D[index-1].win.src=D[index-1].image}}}J.resize=function(){gallerywin.attr("src",D[index].image).height("auto").width("100%").css("opacity",1);if(gallerywin.height()>ph){gallerywin.width("auto").height("100%")}};J.next=function(){if(index>total-2){return false}J.gotoIndex(++index)};J.prev=function(){if(index<1){return false}J.gotoIndex(--index)};function hi(){per=per<(1/total)?0:per;per=per>(1-1/total)?1:per;galleryphotos.animate({left:-pc*per},{queue:false,duration:1000,easing:easing});gallerycontrolimg.animate({left:cw*per},{queue:false,duration:1000})}function loaddata(){if(o.xml!=null){data=[];D=data;$.ajax({url:o.xml,dateType:"xml",global:false,error:function(){alert("Failed in loading XML.")},success:function(msg){$(msg).find("item").each(function(){D.push({title:$("title",this).text(),thumb:$("thumb",this).text(),image:$("image",this).text()});total++});construction()}})}else{if(o.json!=null){$.ajax({url:o.json,dataType:"json",global:false,cache:false,success:function(json){data=eval(json);D=data;total=D.length;construction()}})}else{alert("parm xml/json missed!");return false}}}function construction(){J.html('<img class="gallerywin" src="'+app_vars.appPath+'res/images/gallery.ajax.gif" />                <div class="gallerydoor">                  <span class="gallerybar">&nbsp;</span>                  <div class="gallerydoorbody">                    <div class="galleryinfo">                      <div class="gallerycontrol"><span class="gallerycontrolimg"></span></div>                      <span class="gallerycount"><strong>1</strong>/'+total+'</span>                      <span class="galleryname"></span>                    </div>                    <div class="galleryphotos"></div>                  </div>                </div>').addClass("galleryshowbox");design();sizetogallery();datafill();J.preLoad();galleryevent()}function sizetogallery(){if(o==null){o={}}easing=o.easing==null?"":o.easing;mode=o.mode==null?0:1;J.width(pw=o.pw==null?pw:o.pw).height(ph=o.ph==null?ph:o.ph);gallerydoor.width(J.width());gallerycontrol.width(cw=o.cw==null?cw:o.cw);galleryphotos.find("span").width(sw=o.sw==null?sw:o.sw).height(sh=o.sh==null?sh:o.sh).end().width(pc=total*(sw+5)).height(sh);pc-=pw-10}function datafill(){var _b=sw/sh,_t=thumbs;for(var i=0;i<total;i++){$("<span />").width(sw).height(sh).appendTo(galleryphotos).html("<img rel='"+i+"' style='display:none'/>");_t[i]=new Image();_t[i][0]=$("img:eq("+i+")",galleryphotos);_t[i].onload=function(){var _this=this;if(this.width/this.height>_b){this[0].attr("src",_this.src).height("100%").show().parent().css("background","")}else{this[0].attr("src",_this.src).width("100%").show().parent().css("background","")}};_t[i].src=D[i].thumb}}function galleryevent(){gallerywin.mousemove(function(e){if(e.pageX-$(this).offset().left>$(this).width()/2){cursor=0}else{cursor=1}if(index==total-1){cursor=1}if(index==0){cursor=0}if(cursor==0&&cstate==1){$(this).css("cursor",app_vars.appPath+"res/images/gallery.next.ani");cstate=0}if(cursor==1&&cstate==0){$(this).css("cursor",app_vars.appPath+"res/images/gallery.pre.ani");cstate=1}}).click(function(){if(cursor==0){J.next()}else{J.prev()}});$("span",galleryphotos).click(function(){var _this=$(this).find("img");if(_this.attr("src")==""){return false}J.gotoIndex(_this.attr("rel"))});gallerybar.toggle(function(){gallerydoorbody.hide();$(this).addClass("show")},function(){gallerydoorbody.show();$(this).removeClass("show")});gallerycontrol.mousedown(function(e){per=(e.pageX-$(this).offset().left)/cw;hi()});J.mousewheel(function(e,v){if(document.addEventListener){e.preventDefault()}else{event.returnValue=false}if(per==0&&v>0){return false}if(per==1&&v<0){return false}per-=v/total;hi()})}function design(){gallerydoor=$(".gallerydoor",J);gallerydoorbody=$(".gallerydoorbody",gallerydoor);gallerycontrol=$(".gallerycontrol",gallerydoorbody);galleryphotos=$(".galleryphotos",gallerydoor);gallerywin=$(".gallerywin",J);gallerybar=$(".gallerybar",gallerydoor);gallerycontrolimg=$(".gallerycontrolimg",gallerycontrol);gallerycount=$(".gallerycount strong",gallerydoorbody);galleryname=$(".galleryname",gallerydoorbody)}loaddata();return J}})(jQuery);

/** 
 *  
 * credits for this plugin go to brandonaaron.net *
 * unfortunately his site is down *
 * @param {Object} up
 * @param {Object} down
 * @param {Object} preventDefault 
 *
 */jQuery.fn.extend({mousewheel:function(a,c,b){return this.hover(function(){jQuery.event.mousewheel.giveFocus(this,a,c,b)},function(){jQuery.event.mousewheel.removeFocus(this)})},mousewheeldown:function(b,a){return this.mousewheel(function(){},b,a)},mousewheelup:function(b,a){return this.mousewheel(b,function(){},a)},unmousewheel:function(){return this.each(function(){jQuery(this).unbind("mouseover").unbind("mouseout");jQuery.event.mousewheel.removeFocus(this)})},unmousewheeldown:jQuery.fn.unmousewheel,unmousewheelup:jQuery.fn.unmousewheel});jQuery.event.mousewheel={giveFocus:function(c,a,d,b){if(c._handleMousewheel){jQuery(c).unmousewheel()}if(b==window.undefined&&d&&d.constructor!=Function){b=d;d=null}c._handleMousewheel=function(e){if(!e){e=window.event}if(b){if(e.preventDefault){e.preventDefault()}else{e.returnValue=false}}var f=0;if(e.wheelDelta){f=e.wheelDelta/120;if(window.opera){f=-f}}else{if(e.detail){f=-e.detail/3}}if(a&&(f>0||!d)){a.apply(c,[e,f])}else{if(d&&f<0){d.apply(c,[e,f])}}};if(window.addEventListener){window.addEventListener("DOMMouseScroll",c._handleMousewheel,false)}window.onmousewheel=document.onmousewheel=c._handleMousewheel},removeFocus:function(a){if(!a._handleMousewheel){return}if(window.removeEventListener){window.removeEventListener("DOMMouseScroll",a._handleMousewheel,false)}window.onmousewheel=document.onmousewheel=null;a._handleMousewheel=null}};

/**
 * simplyScroll 1.0.3 - a scroll-tastic jQuery plugin
 *
 * http://logicbox.net/jquery/simplyscroll
 * http://logicbox.net/blog/simplyscroll-jquery-plugin
 * http://plugins.jquery.com/project/simplyScroll
 *
 * Copyright (c) 2009 Will Kelly - http://logicbox.net
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Last revised: 21/02/2009 00:34
 *
 */(function(d){d.fn.simplyScroll=function(a){return this.each(function(){new d.simplyScroll(this,a)})};var c={className:"simply-scroll",frameRate:24,speed:1,horizontal:true,autoMode:"off",loopOverload:0,pauseOnHover:true,localJsonSource:"",flickrFeed:"",jsonImgWidth:240,jsonImgHeight:180};d.simplyScroll=function(b,a){var f=this;this.o=d.extend({},c,a||{});this.auto=this.o.autoMode!=="off"?true:false;this.$list=d(b);if(!this.o.horizontal){this.o.className+=" vert"}this.$list.addClass("simply-scroll-list").wrap('<div class="simply-scroll-clip"></div>').parent().wrap('<div class="'+this.o.className+' simply-scroll-container"></div>');if(!this.o.auto){this.$list.parent().parent().prepend('<div class="simply-scroll-forward"></div>').prepend('<div class="simply-scroll-back"></div>')}if(this.o.flickrFeed){d.getJSON(this.o.flickrFeed+"&format=json&jsoncallback=?",function(e){json=[];d.each(e.items,function(j,i){json.push({src:i.media.m,title:i.title,link:i.link})});f.renderData(json)})}else{if(this.o.localJsonSource){d.getJSON(this.o.localJsonSource,function(e){f.renderData(e)})}else{d(window).load(function(){f.init()});if(d.browser.msie){f.init();}}}};d.simplyScroll.fn=d.simplyScroll.prototype={};d.simplyScroll.fn.extend=d.simplyScroll.extend=d.extend;d.simplyScroll.fn.extend({init:function(){this.$items=this.$list.children();this.$clip=this.$list.parent();this.$container=this.$clip.parent();if(!this.o.horizontal){this.itemMax=this.$items.eq(0).height();this.clipMax=this.$clip.height();this.dimension="height";this.moveBackClass="simply-scroll-btn-up";this.moveForwardClass="simply-scroll-btn-down"}else{this.itemMax=this.$items.eq(0).width();this.clipMax=this.$clip.width();this.dimension="width";this.moveBackClass="simply-scroll-btn-left";this.moveForwardClass="simply-scroll-btn-right"}this.posMin=0;this.posMax=this.$items.length*this.itemMax;this.$list.css(this.dimension,this.posMax+"px");if(this.o.autoMode=="loop"){var a=Math.ceil(this.clipMax/this.itemMax)+this.o.loopOverload;this.$items.slice(0,a).clone(true).appendTo(this.$list);this.posMax+=(this.clipMax-this.o.speed);this.$list.css(this.dimension,this.posMax+(this.itemMax*a)+"px")}this.interval=null;this.intervalDelay=Math.floor(1000/this.o.frameRate);while(this.itemMax%this.o.speed!==0){this.o.speed--;if(this.o.speed===0){this.o.speed=1;break}}var b=this;this.trigger=null;this.funcMoveBack=function(){b.trigger=this;b.moveBack()};this.funcMoveForward=function(){b.trigger=this;b.moveForward()};this.funcMoveStop=function(){b.moveStop()};this.funcMoveResume=function(){b.moveResume()};if(this.auto){if(this.o.pauseOnHover){this.$clip.hover(this.funcMoveStop,this.funcMoveResume)}this.moveForward()}else{this.$btnBack=d(".simply-scroll-back",this.$container).addClass("simply-scroll-btn "+this.moveBackClass+" disabled").hover(this.funcMoveBack,this.funcMoveStop);this.$btnForward=d(".simply-scroll-forward",this.$container).addClass("simply-scroll-btn "+this.moveForwardClass).hover(this.funcMoveForward,this.funcMoveStop)}},moveForward:function(){var a=this;this.movement="forward";if(this.trigger!==null){this.$btnBack.removeClass("disabled")}a.interval=setInterval(function(){if(!a.o.horizontal&&a.$clip[0].scrollTop<(a.posMax-a.clipMax)){a.$clip[0].scrollTop+=a.o.speed}else{if(a.o.horizontal&&a.$clip[0].scrollLeft<(a.posMax-a.clipMax)){a.$clip[0].scrollLeft+=a.o.speed}else{if(a.o.autoMode=="loop"){a.resetPos()}else{a.moveStop(a.movement)}}}},a.intervalDelay)},moveBack:function(){var a=this;this.movement="back";if(this.trigger!==null){this.$btnForward.removeClass("disabled")}a.interval=setInterval(function(){if(!a.o.horizontal&&a.$clip[0].scrollTop>0){a.$clip[0].scrollTop-=a.o.speed}else{if(a.o.horizontal&&a.$clip[0].scrollLeft>0){a.$clip[0].scrollLeft-=a.o.speed}else{if(a.o.autoMode=="loop"){a.resetPos()}else{a.moveStop(a.movement)}}}},a.intervalDelay)},moveStop:function(a){clearInterval(this.interval);if(this.trigger!==null){if(typeof a!="undefined"){d(this.trigger).addClass("disabled")}this.trigger=null}if(this.auto){if(this.o.autoMode=="bounce"){a=="forward"?this.moveBack():this.moveForward()}}},moveResume:function(){this.movement=="forward"?this.moveForward():this.moveBack()},resetPos:function(){if(!this.o.horizontal){this.$clip[0].scrollTop=0}else{this.$clip[0].scrollLeft=0}},renderData:function(a){if(a.length>0){var b=this;d.each(a,function(h,g){d("<img/>").attr({src:g.src,title:g.title,alt:g.title,width:b.o.jsonImgWidth,height:b.o.jsonImgHeight}).appendTo(b.$list)});this.init()}}})})(jQuery);
 
/* ------------------------------------------------------------------------
 * s3Slider
 * 	
 * Developped By: Boban Karišik -> http://www.serie3.info/
 * CSS Help: Mészáros Róbert -> http://www.perspectived.com/
 * Version: 1.0
 * 	
 * Copyright: Feel free to redistribute the script/modify it, as
 * long as you leave my infos at the top.
 * ------------------------------------------------------------------------
 */(function(b){b.fn.s3Slider=function(p){var s=this;var a=(p.timeOut!=undefined)?p.timeOut:4000;var q=null;var t=null;var m=true;var r=false;var o=b(">li",s);var v=b(">li span",s);o.each(function(c){b(o[c]).mouseover(function(){r=true});b(o[c]).mouseout(function(){r=false;u(true)})});var u=function(c){var d=(c)?(a/2):a;d=(m)?10:d;if(o.length>0){t=setTimeout(n,d)}else{}};var n=function(){q=(q!=null)?q:o[(o.length-1)];var c=jQuery.inArray(q,o)+1;c=(c==o.length)?0:(c-1);var d=b(s).width()*c;if(m==true){if(!r){b(o[c]).fadeIn((a/6),function(){if(b(v[c]).css("bottom")==0){b(v[c]).slideUp((a/6),function(){m=false;q=o[c];if(!r){u(false)}})}else{b(v[c]).slideDown((a/6),function(){m=false;q=o[c];if(!r){u(false)}})}})}}else{if(!r){if(b(v[c]).css("bottom")==0){b(v[c]).slideDown((a/6),function(){b(o[c]).fadeOut((a/6),function(){m=true;q=o[(c+1)];if(!r){u(false)}})})}else{b(v[c]).slideUp((a/6),function(){b(o[c]).fadeOut((a/6),function(){m=true;q=o[(c+1)];if(!r){u(false)}})})}}}};n()}})(jQuery);

/*
 * Copyright 2007-2009 by Tobia Conforto <tobia.conforto@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Versions: 0.1    2007-08-19  Initial release
 *                  2008-08-21  Re-released under GPL v2
 *           0.1.1  2008-09-18  Compatibility with prototype.js
 *           0.2    2008-10-15  Linkable images, contributed by Tim Rainey <tim@zmlabs.com>
 *           0.3    2008-10-22  Added option to repeat the animation a number of times, then stop
 *           0.3.1  2008-11-11  Better error messages
 *           0.3.2  2008-11-11  Fixed a couple of CSS bugs, contributed by Erwin Bot <info@ixgcms.nl>
 *           0.3.3  2008-12-14  Added onclick option
 *           0.3.4  2009-03-12  Added shuffle option, contributed by Ralf Santbergen <ralf_santbergen@hotmail.com>
 *           0.3.5  2009-03-12  Fixed usage of href parameter in 'Ken Burns' mode
 */jQuery.fn.crossSlide=function(c,f){var a=this,e=this.width(),b=this.height();function d(j){for(var h=1;h<arguments.length;h++){j=j.replace(new RegExp("\\{"+(h-1)+"}","g"),arguments[h])}return j}function g(){arguments[0]="crossSlide: "+arguments[0];throw d.apply(null,arguments)}(function(j){var h=0;function i(l,k){k.onload=function(m){h++;f[l].width=k.width;f[l].height=k.height;if(h==f.length){j()}};k.src=f[l].src;if(l+1<f.length){i(l+1,new Image())}}i(0,new Image())})(function(){function u(y){var i=1;var p=y.replace(/^\s*|\s*$/g,"").split(/\s+/);if(p.length>3){throw new Error()}if(p[0]=="center"){if(p.length==1){p=["center","center"]}else{if(p.length==2&&p[1].match(/^[\d.]+x$/i)){p=["center","center",p[1]]}}}if(p.length==3){i=parseFloat(p[2].match(/^([\d.]+)x$/i)[1])}var z=p[0]+" "+p[1];if(z=="left top"||z=="top left"){return{xrel:0,yrel:0,zoom:i}}if(z=="left center"||z=="center left"){return{xrel:0,yrel:0.5,zoom:i}}if(z=="left bottom"||z=="bottom left"){return{xrel:0,yrel:1,zoom:i}}if(z=="center top"||z=="top center"){return{xrel:0.5,yrel:0,zoom:i}}if(z=="center center"){return{xrel:0.5,yrel:0.5,zoom:i}}if(z=="center bottom"||z=="bottom center"){return{xrel:0.5,yrel:1,zoom:i}}if(z=="right top"||z=="top right"){return{xrel:1,yrel:0,zoom:i}}if(z=="right center"||z=="center right"){return{xrel:1,yrel:0.5,zoom:i}}if(z=="right bottom"||z=="bottom right"){return{xrel:1,yrel:1,zoom:i}}return{xrel:parseInt(p[0].match(/^(\d+)%$/)[1])/100,yrel:parseInt(p[1].match(/^(\d+)%$/)[1])/100,zoom:i}}function j(y,i){switch(i){case 1:var z=0;break;case 2:var z=w/(y.time_ms+2*w);break;case 3:var z=1-w/(y.time_ms+2*w);break;case 4:var z=1;break}return{left:Math.round(y.from.left+z*(y.to.left-y.from.left)),top:Math.round(y.from.top+z*(y.to.top-y.from.top)),width:Math.round(y.from.width+z*(y.to.width-y.from.width)),height:Math.round(y.from.height+z*(y.to.height-y.from.height))}}if(!c.fade){g("missing fade parameter.")}if(c.speed&&c.sleep){g("you cannot set both speed and sleep at the same time.")}var w=Math.round(c.fade*1000);if(c.sleep){var v=Math.round(c.sleep*1000)}if(c.speed){var k=c.speed/1000,q=Math.round(w*k)}a.empty().css({overflow:"hidden",padding:0});if(!a.css("position").match(/absolute|relative|fixed/)){a.css({position:"relative"})}if(!a.width()||!a.height()){g("container element does not have its own width and height")}if(c.shuffle){f.sort(function(){return Math.random()-0.5})}for(var n=0;n<f.length;++n){var h=f[n];if(!h.src){g("missing src parameter in picture {0}.",n+1)}if(k){switch(h.dir){case"up":h.from={xrel:0.5,yrel:0,zoom:1};h.to={xrel:0.5,yrel:1,zoom:1};var s=h.height-b-2*q;break;case"down":h.from={xrel:0.5,yrel:1,zoom:1};h.to={xrel:0.5,yrel:0,zoom:1};var s=h.height-b-2*q;break;case"left":h.from={xrel:0,yrel:0.5,zoom:1};h.to={xrel:1,yrel:0.5,zoom:1};var s=h.width-e-2*q;break;case"right":h.from={xrel:1,yrel:0.5,zoom:1};h.to={xrel:0,yrel:0.5,zoom:1};var s=h.width-e-2*q;break;default:g('missing or malformed "dir" parameter in picture {0}.',n+1)}if(s<=0){g("picture number {0} is too short for the desired fade duration.",n+1)}h.time_ms=Math.round(s/k)}else{if(!v){if(!h.from||!h.to||!h.time){g("missing either speed/sleep option, or from/to/time params in picture {0}.",n+1)}try{h.from=u(h.from)}catch(r){g('malformed "from" parameter in picture {0}.',n+1)}try{h.to=u(h.to)}catch(r){g('malformed "to" parameter in picture {0}.',n+1)}if(!h.time){g('missing "time" parameter in picture {0}.',n+1)}h.time_ms=Math.round(h.time*1000)}}if(h.from){jQuery.each([h.from,h.to],function(y,p){p.width=Math.round(h.width*p.zoom);p.height=Math.round(h.height*p.zoom);p.left=Math.round((e-p.width)*p.xrel);p.top=Math.round((b-p.height)*p.yrel)})}var t;if(h.href){t=jQuery(d('<a href="{0}"><img src="{1}"/></a>',h.href,h.src))}else{t=jQuery(d('<img src="{0}"/>',h.src))}if(h.onclick){t.click(h.onclick)}t.appendTo(a)}k=undefined;var o=a.find("img").css({position:"absolute",visibility:"hidden",top:0,left:0,border:0});o.eq(0).css({visibility:"visible"});if(!v){o.eq(0).css(j(f[0],2))}var x=c.loop;function l(K,p){if(K%2==0){if(v){var A=K/2,O=(A-1+f.length)%f.length,L=o.eq(A),I=o.eq(O);var H=function(){I.css("visibility","hidden");setTimeout(p,v)}}else{var D=K/2,O=(D-1+f.length)%f.length,N=o.eq(D),I=o.eq(O),B=f[D].time_ms,J=j(f[D],3);var H=function(){I.css("visibility","hidden");N.animate(J,B,"linear",p)}}}else{if(v){var z=Math.floor(K/2),C=Math.ceil(K/2)%f.length,M=o.eq(z),y=o.eq(C),P={},G={visibility:"visible"},F={};if(C>z){G.opacity=0;F.opacity=1}else{P.opacity=0}var H=function(){y.css(G);if(P.opacity!=undefined){M.animate(P,w,"linear",p)}else{y.animate(F,w,"linear",p)}}}else{var z=Math.floor(K/2),C=Math.ceil(K/2)%f.length,M=o.eq(z),y=o.eq(C),P=j(f[z],4),G=j(f[C],1),F=j(f[C],2);if(C>z){G.opacity=0;F.opacity=1}else{P.opacity=0}G.visibility="visible";var H=function(){M.animate(P,w,"linear");y.css(G);y.animate(F,w,"linear",p)}}}if(c.loop&&K==f.length*2-2){var E=H;H=function(){if(--x){E()}}}if(K>0){return l(K-1,H)}else{return H}}var m=l(f.length*2-1,function(){return m()});m()});return a};

/**
 * @author feiwen
 */
(function($) {
    $.fn.textSlider = function(settings) {
        settings = jQuery.extend({
            speed: "normal",
            line: 2,
            timer: 1000
        }, settings);
        return this.each(function() {
            $.fn.textSlider.scllor($(this), settings);
        });
    };
    $.fn.textSlider.scllor = function($this, settings) {
        //alert($this.html());
        var ul = $("ul:eq(0)", $this);
        var timerID;
        var li = ul.children();

        var liHight = $(li[0]).height();
        var upHeight = 0 - settings.line * liHight;
        var scrollUp = function() {
            ul.animate({ marginTop: upHeight }, settings.speed, function() {
                for (i = 0; i < settings.line; i++) {
                    //$(li[i]).appendTo(ul);
                    ul.find("li:first").appendTo(ul);
                    // alert(ul.html());
                }
                ul.css({ marginTop: 0 });
            });
        };
        var scrollDown = function() {
            ul.css({ marginTop: upHeight });
            for (i = 0; i < settings.line; i++) {
                ul.find("li:last").prependTo(ul);
            }
            ul.animate({ marginTop: 0 }, settings.speed, function() {
            });
        };
        var autoPlay = function() {
            timerID = window.setInterval(scrollUp, settings.timer);
            //alert(settings.timer);
        };
        var autoStop = function() {
            window.clearInterval(timerID);
        };
        ul.hover(autoStop, autoPlay).mouseout();
    };
})(jQuery);

