﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
$(function () {
    $.fn.extend({
        "CommunityIndex": function () {
            pyindex = new Array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'w', 'x', 'y', 'z');
            closetimer = 0;
            timeout = 500;
            key = "a";
            //rendIndex
            tabs = null;
            contents = null;
            for (var i = 0; i < pyindex.length; i++) {
                this.append("<a href=\"LouPanXiaoQu.aspx?py=" + pyindex[i] + "\">" + pyindex[i].toUpperCase() + "</a>");
            }
            LoadData();

            function MouseHover(e) {
                if (contents == null || tabs == null) {
                    return;
                }
                mcancelclosetime();
                key = $(e.target).text().toLowerCase();
                contents.hide();
                $("#CommunityIndex" + key).show();
                var images = $("#CommunityIndex" + key + " img");

                images.each(function (e) {
                    var i = images[e];
                    i.src = i.img;

                });
            };
            function MouseOut(e) {
                key = $(e.target).text().toLowerCase();
                mclosetime();
            };
            function PopMouseover(e) {

                mcancelclosetime();
            };
            function PopMouseout(e) {
                mclosetime();
            };

            function mcancelclosetime() {
                if (closetimer) {
                    window.clearTimeout(closetimer);
                    closetimer = null;
                }
            };
            function mclosetime() {
                closetimer = setInterval(HideMenu, timeout);
            };

            function HideMenu() {
                $("#CommunityIndex" + key).hide();

            };
            function LoadData() {

                $.ajax({
                    type: "GET",
                    url: "/Handlers/PYIndex.ashx",
                    data: "",
                    dataType: "text",
                    success: LoadSucceed,
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //alert(errorThrown + textStatus);
                    }
                });
            };
            function LoadSucceed(data, textStatus) {
                $("#communityIndexContainner").append(data);
                tabs = $("#CommunityIndex a");
                contents = $(".communityIndexBox");
                tabs.bind("mouseover", this, MouseHover);
                tabs.bind("mouseout", this, MouseOut);
                contents.bind("mouseover", this, PopMouseover);
                contents.bind("mouseout", this, PopMouseout);

            }
        }
    });
    $("#CommunityIndex").CommunityIndex();
   
});
