﻿/*
author:chen yi hong
date:2011/8/24
*/

var isIE = (document.all) ? true : false;

var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
}

var Class = {
    create: function () {
        return function () { this.initialize.apply(this, arguments); }
    }
}
var Bind = function (object, fun) {
    return function () { fun.apply(object, arguments); }
}

var Extend = function (destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
}

function AddEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    }
    else {
        oTarget["on" + sEventType] = fnHandler;
    }

}


function RemoveEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = null;
    }
};

var BindAsEventListener = function (object, fun) {
    var args = Array.prototype.slice.call(arguments).slice(2);
    return function (event) {
        return fun.apply(object, [event || window.event].concat(args));
    }
}



function $G() {
    var Url = top.window.location.href;
    var u, g, StrBack = '';
    if (arguments[arguments.length - 1] == "#")
        u = Url.split("#");
    else
        u = Url.split("?");
    if (u.length == 1) g = '';
    else g = u[1];
    if (g != '') {
        gg = g.split("&");
        var MaxI = gg.length;
        str = arguments[0] + "=";
        for (i = 0; i < MaxI; i++) {
            if (gg[i].indexOf(str) == 0) {
                StrBack = gg[i].replace(str, "");
                break;
            }
        }
    }
    return StrBack;
}


var CurrentStyle = function (element) {
    return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}
var showlist = new Array(); var signlist = new Array(); var stopit = new Array();
var datamenu0;
var datamenu1;
var datamenu2;
var datamenu3;
var datamenu4;
var datamenu5;
var datamenu6;
var menuslist = Class.create();
menuslist.prototype = {
    initialize: function (obj, options) {

        this.menu1 = new Array();
        this.menu2 = new Array();
    },
    OnInit0: function (a) {
        this.datamenu0 = eval(a);
    },
    OnInit1: function (a) {
        this.datamenu1 = eval(a);
    },
    OnInit2: function (a) {
        this.datamenu2 = eval(a);
    },
    OnInit3: function (a) {
        this.datamenu3 = eval(a);
    },
    OnInit4: function (a) {
        this.datamenu4 = eval(a);
    },
    OnInit5: function (a) {
        this.datamenu5 = eval(a);
    },
    OnInit6: function (a) {
        this.datamenu6 = eval(a);
    },
    Onload: function () {
        var ml = new menulist("maincontianer", { mydata0: this.datamenu0, mydata1: this.datamenu1, mydata2: this.datamenu2, mydata3: this.datamenu3, mydata4: this.datamenu4, mydata5: this.datamenu5, mydata6: this.datamenu6 })
    }

}
var texlist = new Array();
var menulist = Class.create();
menulist.prototype = {
    initialize: function (obj, options) {
        this.container = $(obj);
        this.SetOptions(options);
        var color0 = "#f06000";
        var color1 = "#f69701";
        if (!isIE) { color1 = " #f7a001" } var color2 = "#e9b706";
        if (!isIE) { color2 = " #ebbe09" }
        var color3 = "#87b411";
        var color4 = "#1d9a70";
        var color5 = "#0c90a7";
        var color6 = "#0e7da8";
        var item0 = new childmenu(obj, { index: 0, img: "sign0", msg: "  ", width: 120, top: 0, left: 0, mycolor: color0, mydata: this.options.mydata0
        });
        var item1 = new childmenu(obj, { index: 1, img: "sign1", msg: "  ", width: 138, top: 0, left: 121, mycolor: color1, mydata: this.options.mydata1
        });
        var item2 = new childmenu(obj, { index: 2, img: "sign2", msg: " ", width: 138, top: 0, left: 260, mycolor: color2, mydata: this.options.mydata2
        });

        var item3 = new childmenu(obj, { index: 3, img: "sign3", msg: " ", width: 138, top: 0, left: 399, mycolor: color3, mydata: this.options.mydata3
        });
        var item4 = new childmenu(obj, { index: 4, img: "sign4", msg: " ", width: 138, top: 0, left: 538, mycolor: color4, mydata: this.options.mydata4
        });
        var item5 = new childmenu(obj, { index: 5, img: "sign5", msg: " ", width: 138, top: 0, left: 677, mycolor: color5, mydata: this.options.mydata5
        });
        var item6 = new childmenu(obj, { index: 6, img: "sign6", msg: " ", width: 123, top: 0, left: 817, mycolor: color6, mydata: this.options.mydata6
        });
    },
    SetOptions: function (options) {
        this.options = {
            mydata0: "", mydata1: "", mydata2: "", mydata3: "", mydata4: "", mydata5: "", mydata6: ""
        };
        Extend(this.options, options || {});
    }

}
var isdone = false;
var childmenu = Class.create();
childmenu.prototype = {
    initialize: function (obj, options) {

        this._fM = BindAsEventListener(this, this.OnMouserOver);
        this._fS = Bind(this, this.OnMouserOut);

        this.container = $(obj);
        this.div = document.createElement("div");
        this.SetOptions(options);
        this.div.style.position = "absolute";
        this.div.style.width = (parseInt(this.options.width) - 60) + "px";
        this.div.style.height = "23px";


        this.div.style.top = this.options.top + "px";
        this.div.style.left = this.options.left + "px";
        //this.div.style.backgroundImage = "url(res/" + this.options.img + ".png)";
        this.div.style.background = this.options.mycolor;
        this.div.style.zIndex = 5;
        this.div.style.cursor = "hand";
        this.div.innerHTML = this.options.mydata[0].name;
        this.div.style.fontSize = "13px";
        this.div.style.color = "#fff";
        this.div.style.paddingLeft = "40px";
        this.div.style.paddingRight = "20px";
        this.div.style.paddingTop = "8px";
        this.container.appendChild(this.div);

        this.childdiv = document.createElement("div");

        this.signdiv = document.createElement("div");
        this.signdiv.style.position = "absolute";
        this.signdiv.style.width = "28px";
        this.signdiv.style.top = "2px";
        this.signdiv.style.left = "10px";
        this.signdiv.zIndex = 6;
        this.signdiv.style.height = "27px"; this.signdiv.style.backgroundImage = "url(res/" + this.options.img + ".png)";

        var type = $G("t");
        if (type != "") {
            if (this.options.index == type) {
                this.signdiv.style.height = "27px"; this.signdiv.style.backgroundImage = "url(res/sign" + type + ".png)";

                this.div.appendChild(this.signdiv);
            }
        }
        AddEventHandler(this.div, "mouseover", BindAsEventListener(this, this.OnMouserOver));
        AddEventHandler(this.div, "mouseout", BindAsEventListener(this, this.OnMouserOut));
        AddEventHandler(this.div, "click", BindAsEventListener(this, this.onMyClick));


    },

    SetOptions: function (options) {
        this.options = {
            index: "", width: "", img: "", msg: "", top: "", left: "", mycolor: "", mydata: "", tar: ""
        };
        Extend(this.options, options || {});
    },
    OnMouserOut: function (evt) {
        isdone = false;

    },
    OnMouserOver: function (evt) {

        for (var i = 0; i < showlist.length; i++) {
            try {
                showlist[i].div.removeChild(showlist[i].signdiv);
                showlist[i].div.removeChild(showlist[i].childdiv);

            } catch (e) { }
            showlist = new Array();
        }
        for (var i = 0; i < texlist.length; i++) {
            try {
                this.container.removeChild(texlist[i].textdiv);
            } catch (e) { }
        }
        try {
            this.div.appendChild(this.signdiv);
        } catch (e) { }

        stopit = new Array();
        this.childdiv.style.background = this.options.mycolor;
        this.childdiv.style.position = "absolute";
        this.childdiv.style.width = this.options.width + "px";
        this.childdiv.style.overflow = "visible";
        this.childdiv.style.height = "31px";
        if (this.options.mydata.length > 1) {
            this.childdiv.style.top = "31px";
        } else {
            this.childdiv.style.top = "0px";
        }
        //        if (this.options.img == "sign4") {
        //            this.childdiv.style.left = "-96px";
        //        } else {
        this.childdiv.style.left = "0px";
        //        }
        this.childdiv.style.zIndex = 50;
        this.childdiv.style.cursor = "hand";
        this.childdiv.style.textDecoration = "none";
        showlist[showlist.length] = this;
        try { this.div.appendChild(this.childdiv); } catch (e) { }
        isdone = false;


        var index = 0;
        texlist = new Array();
        var newwidth = 0;
        var newmarrleft = 0;
        if (this.options.img == "sign5") {
            newmarrleft = 186;
        }
        for (var i = 1; i < this.options.mydata.length; i++) {

            texlist[texlist.length] = new nextchildmenu(this.childdiv, { marrleft: parseInt(this.div.style.left) - newmarrleft, marrtop: 30, msg: this.options.mydata[i].name, url: this.options.mydata[i].url, top: 10, left: 10 + parseInt(index), tar: this.options.mydata[i].tar });

            this.textsigndiv = document.createElement("div");
            this.textsigndiv.style.backgroundImage = "url(res/split3.png)";
            this.textsigndiv.style.width = "1px";
            this.textsigndiv.style.height = "12px";
            this.textsigndiv.style.position = "absolute";
            this.textsigndiv.style.top = 10 + "px";

            this.textsigndiv.style.left = parseInt(index) + "px";

            this.textsigndiv.style.zIndex = 61;
            if (index != 0) {
                this.childdiv.appendChild(this.textsigndiv);
            }
            newwidth += 80;
            index += 80;
        }
        this.childdiv.style.width = this.options.width + newwidth - parseInt(this.options.width) + "px";

        if (this.options.img == "sign5") {
            var sin5w = parseInt(this.childdiv.style.left) - parseInt(this.childdiv.style.width) + 138;
            this.childdiv.style.left = sin5w + "px";
        }
        this.zoomindex = 0;
        //this.childdiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=0,finishOpacity=0";
        //this._timerV = setInterval(BindAsEventListener(this, this.Zoom), 10);

    },
    Zoom: function () {
        // if (parseInt(this.childdiv.style.width) >= this.options.width) {
        if (this.zoomindex >= 100) {
            this.childdiv.style.width = this.options.width + "px";
            clearInterval(this._timerV);
        }
        else {
            this.childdiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=" + this.zoomindex + ",finishOpacity=100";
            //newMask.style.filter = "alpha(opacity=40)";
            this.childdiv.style.opacity = "0.40";

            this.childdiv.style.width = this.zoomindex + "px";
            this.zoomindex += 10;
        }
        this.ok100 = true;
    },
    onMyClick: function () {
        if (this.options.mydata[0].tar == "open") {
            window.open(this.options.mydata[0].url, "_blank");
        } else {

            window.location.href = this.options.mydata[0].url;
        }
    }



}


var nextchildmenu = Class.create();
nextchildmenu.prototype = {
    initialize: function (obj, options) {
        this.container = $("maincontianer");
        this.textdiv = document.createElement("div");
        this.textdiv.style.position = "absolute";

        this.textdiv.style.width = "100px";
        this.textdiv.style.height = "20px";

        this.textdiv.style.zIndex = 800;
        this.textdiv.style.color = "#fff";
        this.textdiv.style.cursor = "hand";
        this.SetOptions(options);
        this.textdiv.style.top = this.options.marrtop + this.options.top + "px";
        this.textdiv.style.left = this.options.marrleft + this.options.left + "px";
        this.textdiv.innerHTML = this.options.msg;

        this.textdiv.style.fontSize = "13px";

        this.container.appendChild(this.textdiv);
        AddEventHandler(this.textdiv, "click", BindAsEventListener(this, this.onMyTextClick));
        AddEventHandler(this.textdiv, "mouseout", BindAsEventListener(this, this.onMyTextOut));
        AddEventHandler(this.textdiv, "mouseover", BindAsEventListener(this, this.onMyTextOver));


    },
    onMyTextOver: function () {
        stopit[0] = "abc";
    },
    onMyTextOut: function () {
        stopit = new Array();
        this._timerMenu = setTimeout(BindAsEventListener(this, this.CloseMenu), 2000);
    },
    CloseMenu: function (e) {
        if (stopit.length > 0) { return false; }
        for (var i = 0; i < showlist.length; i++) {
            try {
                showlist[i].div.removeChild(showlist[i].signdiv);
                showlist[i].div.removeChild(showlist[i].childdiv);

            } catch (e) { }
            showlist = new Array();
        }
        for (var i = 0; i < texlist.length; i++) {
            try {
                this.container.removeChild(texlist[i].textdiv);
            } catch (e) { }
        }
        clearTimeout(this._timerMenu);
    },
    onMyTextClick: function () {

        if (this.options.tar == "open") {
            window.open(this.options.url, "_blank");
        } else {
            window.location.href = this.options.url;
        }
    },
    SetOptions: function (options) {
        this.options = {
            marrleft: "", marrtop: "", msg: "", top: "", left: "", url: "", tar: ""
        };
        Extend(this.options, options || {});
    }
}
 
