﻿/// <reference path="jquery/jquery-1.3.2.min-vsdoc.js" />
/* 
统计
Power By Goodspeed
2008-12-1
*/
function stat(code) {
    $data = new Array();
    $data.push("referrer=" + escape(document.referrer));

    $.each(code, function(i, n) {
        if (n != null) {
            $data.push("&code=" + escape(n));
        }
    });
    $.ajax({
        type: "POST",
        url: "/Stat/",
        data: $data.join(""),
//     success: function(msg) {
//         alert(msg);
//     },
//     error: function(msg) {
//         alert(msg.responseText)
//     },
        cache: false
    });
}

$(document).ready(function() {
    /* 
    调查
    Power By Goodspeed
    2008-12-1
    */
    $('.surveyForm').bind('submit', function() {
        $this = $(this);
        $(this).ajaxSubmit({
            success: function(data) {
                alert(data.message);
                if (data.status == true) {
                    var total = 0;
                    var vote = new Array();
                    $this.find(":radio").each(function() {
                        var v = parseInt($(this).attr("class"));
                        if ($(this).attr("checked") == true) {
                            v++;
                            $(this).attr("class", v);
                        }
                        vote.push(v);
                        total += v;
                    });

                    $.each(vote, function(i, n) {
                        var v = Math.round(n * 100 / total);
                        v = v.toString() + '%';
                        $($this.find(".PollGraph div").eq(i)).css("width", v);
                        $($this.find(".PollCount").eq(i)).text(v);
                    });
                }
            },
            dataType: "json"
        });
        return false; // <-- important!
    });

    /* 
    搜索
    Power By Goodspeed
    2008-12-1
    */
    $(".searchbutton").click(function() {
        var q = null;
        $(".q").each(function() {
            if ($.trim($(this).val()) != "" && q == null) {
                q = encodeURI($.trim($(this).val()));
            }
        });

        if (q != null) {
            window.location.href = "/search/" + q + ".html";
        } else {
            alert(localization.please_enter_your_search_keywords);
        }
    });


});

/* 
退出
Power By Goodspeed
2008-12-1
*/
$(document).ready(function() {
    var url = $("#logout").attr("href");
    $("#logout").attr("href", "#");

    $("#logout").click(function() {
        $.ajax({
            type: "GET",
            success: function(msg) {
                window.location.href = url;
            },
            //                error: function(msg) {
            //                    alert(msg.responseText)
            //                },
            url: "/account/Logout/"
        });

        return false;
    });
});

/* 
    菜单 
    Power By Goodspeed
    2009-8-16
*/
$(document).ready(function() {
    var timeoutID = null;

    $(".menu1>span[@class='']>a").mouseenter(function() {
        cleanMenu();
        $(".menu1>span>a").parent().removeClass("Selected");
        $(this).parent().addClass("Selected");
        $(this).nextAll("span").prependTo("#menu2");

        if ($("#menu2").children().length > 0) {
            $("#menu2").show();
            var offset = $(this).parent().offset();
            $("#menu2").css({ top: offset.top + $(this).parent().height(), left: offset.left });

            document.getElementById("menu2").obj = $(this);
        }
    });


    $("#nav2").mouseleave(function() {
        timeoutID = window.setTimeout("cleanMenu()", 1);
    });

    $("#menu2").mouseenter(function() {
        window.clearTimeout(timeoutID);
    });

    $("#menu2").mouseleave(function() {
        timeoutID = window.setTimeout("cleanMenu()", 1);
    });
});

function cleanMenu() {
    if (document.getElementById("menu2").obj != null) {
        $("#menu2").children().insertAfter(document.getElementById("menu2").obj);
    }

    $("#menu2").hide();
}