
var blnGoTop = false;
var timerShowFriendly = null;
var timerHideFriendly = null;
var ityEarlier_PageIndex = 0;
var ityEarlier_PageCount = 0;

$(document).ready(function () {

    adjustPosition();

    $(window).bind("resize", adjustPosition);

    if ($(".gTop").get(0)) {
        $(".top").click(function () {
            blnGoTop = true;
            $('html,body').animate({
                scrollTop: 0
            }, 500, function () {
                blnGoTop = false;
            });
            $(".gTop").fadeOut(300);
        });
        showGoTop();
        $(window).bind("resize scroll", showGoTop);
    }

    $("a").focus(function () {
        $(this).blur();
    });

    $(".searchbanner input[type='text']").focus(function () {
        this.select();
    });

    if ($("#MainMenu").get(0)) {
        $(function () {
            $("#MainMenu").lavaLamp({
                fx: "backout",
                speed: 500,
                click: function (event, menuItem) {
                    return true;
                }
            });
        });
    }

    if ($(".rssbanner").get(0)) {
        $(".share").click(function () {
            openShareWindow(this);
        });
        $(".rss").click(function () {
            $(".rss_box").show();
        });
        $(".popbox").hover(function () {
            $("input[type='text']", $(this)).eq(0).focus();
        }, function () {
            $(this).hide();
        });
        $(".bigbox").hover(function () {
        }, function () {
            $(this).hide();
        });
    }

    $(".for_friendlylink").click(function () {
        timerShowFriendly = null;
        timerHideFriendly = null;
        $(".ifriendlylink").toggle();
    }).hover(function () {
        timerHideFriendly = null;
        timerShowFriendly = setTimeout(function () {
            $(".ifriendlylink").show();
        }, 1000);
    }, function () {
        timerShowFriendly = null;
        timerHideFriendly = setTimeout(function () {
            if (timerHideFriendly) $(".ifriendlylink").hide();
        }, 1000);
    });

    $(".ifriendlylink").hover(function () {
        timerHideFriendly = null;
    }, function () {
        timerShowFriendly = null;
        timerHideFriendly = null;
        $(".ifriendlylink").hide();
    });

    if ($(".ity-earlier").get(0)) {
        var len = $(".ity-earlier #HiddenList li").length;
        if (len <= 12) {
            ityEarlier_PageCount = 1;

            $(".ity-earlier ul.pages").prepend($(".ity-earlier #HiddenList li"));
            $(".ity-earlier ul.pages img.loading").each(function () { $(this).attr("src", $(".ity-hid a", $(this).parent().parent().parent()).attr("href")).removeClass("loading"); });

            $(".ity-earlier .pagebutton a").attr("disabled", true);
            $(".ity-earlier .pagebutton span:first").attr("className", "prev-disabled");
            $(".ity-earlier .pagebutton span:last").attr("className", "next-disabled");
        }
        else {
            ityEarlier_PageCount = Math.floor(len / 12) + 1;

            $(".ity-earlier ul.pages").height(ityEarlier_PageCount * 374);

            $(".ity-earlier ul.pages").append($(".ity-earlier #HiddenList li:lt(12)"));
            $(".ity-earlier ul.pages img.loading").each(function () { $(this).attr("src", $(".ity-hid a", $(this).parent().parent().parent()).attr("href")).removeClass("loading"); });

            $(".ity-earlier .pagebutton a:first").attr("disabled", true);
            $(".ity-earlier .pagebutton a:last").attr("disabled", false);
            $(".ity-earlier .pagebutton span:last").attr("class", "next");
        }

        ityEarlier_PageIndex = 0;

        $(".ity-earlier .pagebutton a:first").click(function () {
            if (ityEarlier_PageIndex > 0) {
                ityEarlier_PageIndex--;
                $(".ity-earlier ul.pages").animate({ top: (ityEarlier_PageIndex * (-388)) + 'px' }, 400, function () {
                    if (ityEarlier_PageIndex == 0) {
                        $(".ity-earlier .pagebutton a:first").attr("disabled", true);
                        $(".ity-earlier .pagebutton span:first").attr("class", "prev-disabled");
                    }
                });
            }
            else {
                $(".ity-earlier .pagebutton a:first").attr("disabled", true);
                $(".ity-earlier .pagebutton span:first").attr("class", "prev-disabled");
            }

            if (ityEarlier_PageCount > 1) {
                $(".ity-earlier .pagebutton a:last").attr("disabled", false);
                $(".ity-earlier .pagebutton span:last").attr("class", "next");
            }
            else {
                $(".ity-earlier .pagebutton a:last").attr("disabled", true);
                $(".ity-earlier .pagebutton span:last").attr("class", "next-disabled");
            }
        });
        $(".ity-earlier .pagebutton a:last").click(function () {
            var len = $(".ity-earlier #HiddenList li").length;
            if (len > 0) {
                $(".ity-earlier ul.pages").append($(".ity-earlier #HiddenList li:lt(12)"));
            }
            if (ityEarlier_PageIndex + 1 < ityEarlier_PageCount) {
                ityEarlier_PageIndex++;
                $(".ity-earlier ul.pages").animate({ top: (ityEarlier_PageIndex * (-388)) + 'px' }, 400, function () {
                    $(".ity-earlier ul.pages img.loading").each(function () { $(this).attr("src", $(".ity-hid a", $(this).parent().parent().parent()).attr("href")).removeClass("loading"); });

                    if (ityEarlier_PageIndex + 1 >= ityEarlier_PageCount) {
                        $(".ity-earlier .pagebutton a:last").attr("disabled", true);
                        $(".ity-earlier .pagebutton span:last").attr("class", "next-disabled");
                    }
                });
            }
            else {
                $(".ity-earlier .pagebutton a:last").attr("disabled", true);
                $(".ity-earlier .pagebutton span:last").attr("class", "next-disabled");
            }

            if (ityEarlier_PageIndex > 0) {
                $(".ity-earlier .pagebutton a:first").attr("disabled", false);
                $(".ity-earlier .pagebutton span:first").attr("class", "prev");
            }
            else {
                $(".ity-earlier .pagebutton a:first").attr("disabled", true);
                $(".ity-earlier .pagebutton span:first").attr("class", "prev-disabled");
            }
        });
    }

    if ($(".ity-c-frm").get(0)) {
        $(".ity-c-frm #ActivityName").val($(".ity-d .the-name").text());
        $(".ity-c-frm #MemberInfo .is_text").each(function () {
            $(this).val($(this).attr("rvalue")).focus(function () {
                if ($(this).val() == $(this).attr("rvalue")) {
                    $(this).val("").addClass("is_text_t");
                }
            }).blur(function () {
                if ($(this).val() == "" || $(this).val() == $(this).attr("rvalue")) {
                    $(this).val($(this).attr("rvalue")).removeClass("is_text_t");
                }
            });
        });
    }

    if ($(".ity-d-frm").get(0)) {
        $(".ity-d-frm #ActivityName").val($(".ity-d .the-name").text());
        $(".ity-d-frm #MemberInfo .is_text").each(function () {
            $(this).val($(this).attr("rvalue")).focus(function () {
                if ($(this).val() == $(this).attr("rvalue")) {
                    $(this).val("").addClass("is_text_t");
                }
            }).blur(function () {
                if ($(this).val() == "" || $(this).val() == $(this).attr("rvalue")) {
                    $(this).val($(this).attr("rvalue")).removeClass("is_text_t");
                }
            });
        });
        $(".ity-d-frm .is_textarea").each(function () {
            $(this).val($(this).attr("rvalue")).focus(function () {
                if ($(this).val() == $(this).attr("rvalue")) {
                    $(this).val("").addClass("is_textarea_t");
                }
            }).blur(function () {
                if ($(this).val() == "" || $(this).val() == $(this).attr("rvalue")) {
                    $(this).val($(this).attr("rvalue")).removeClass("is_textarea_t");
                }
            });
        });
    }

    if ($(".ipj .labels").get(0)) {
        $(".ipj .labels span").each(function () {
            $(this).click(function () {
                $(".ipj .searchbanner #word").val($(this).text());
                $(".ipj .searchbanner form").trigger("submit");
            });
        });
    }

    if ($(".ipj .tasters").get(0)) {
        $(".ipj .tasters li:first a").addClass("top1");
    }

    if ($(".pj-comment-edit").get(0)) {

        $(".pj-comment-r0 #Title").val($(".pj-title").text());
        $(".pj-comment-edit .is_text").add(".pj-comment-edit .is_vcode").each(function () {
            $(this).val($(this).attr("rvalue")).focus(function () {
                $("#" + $(this).attr("id") + "_msg").hide();
                if ($(this).val() == $(this).attr("rvalue")) {
                    $(this).val("").addClass("is_text_t");
                }
            });
        });
        $(".pj-comment-edit .is_textarea").each(function () {
            $(this).val($(this).attr("rvalue")).focus(function () {
                $("#" + $(this).attr("id") + "_msg").hide();
                if ($(this).val() == $(this).attr("rvalue")) {
                    $(this).val("").addClass("is_textarea_t");
                }
            }).blur(function () {
                if ($(this).val() == "" || $(this).val() == $(this).attr("rvalue")) {
                    $(this).val($(this).attr("rvalue")).removeClass("is_textarea_t");
                }
            });
        });
        $(".pj-comment-edit #Content_msg").add(".pj-comment-edit #MemberName_msg").add(".pj-comment-edit #validateCode_msg").click(function () {
            $(this).hide();
        });
    }
});

function adjustPosition() {

    var idle_w = $(window).width() - 973;
    if (idle_w > 0) {
        $("td.tcol_1").width(idle_w / 2);
        $("td.tcol_3").width(idle_w / 2);
    }
}

function showGoTop() {
    if (blnGoTop) return;
    if ($(document).scrollTop() > 100) {
        $(".gTop").fadeIn(300);
    }
    else {
        $(".gTop").fadeOut(300);
    }
}

function copyUrl() {
    try {
        var clipBoardContent = $(".rss_box #rss").val();
        window.clipboardData.setData("Text", clipBoardContent);
        $(".rss_box").hide();
    }
    catch (e) {
    }
}

function openShareWindow(obj) {
    $(".share_box", $(obj).parent()).show();
}

function decodeURI(html) {
    if (html.indexOf("http://") >= 0) {
        return window.decodeURI(html);
    }
    return html;
}


/*/
/*
/* jQuery¹ØÓÚcookieµÄ²Ù×÷
/*
/*/
jQuery.cookie = function (name, value, options) {

    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value == null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '; path=/';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
