var hwtCSIcon = function(){};

hwtCSIcon.prototype = {

    icon : null ,
    width : 147 ,
    height : 80 ,
    top : 100 ,
    bottom : 50 ,
    left : 20 ,
    right : 20 ,
    align : "right" ,
    valign : "top" ,
    timer : null ,
    delay : 30 ,
    duration : 80 ,
    algo : "Quint" ,
    dir : "" ,
    csl : null ,
    csa : [] ,
    btnclose : null ,
    style : 1 ,
    epuid : 0 ,
    atInvite : true ,
    opened : false ,
    idialog : null ,
    timeri : null ,
    ibMsg : "" ,
    lng : 1 ,
    de : document.documentElement ,
	pdiv : null ,
	mdiv : null ,

    init : function(){
        var _this = this;
        if(!this.icon){
            this.icon = document.createElement("div");
            document.body.insertBefore(this.icon,document.body.childNodes[0]);
            with(this.icon.style){
                zIndex = 998;
                position = "absolute";
                top = "0px";
                width = this.width + "px";
                height = this.height + "px";
                //background = "#FFF";
                //overflow = "hidden";
            }
            if(this.align=="right"){
                this.icon.style.right = this.right + "px";    
            }else{
                this.icon.style.left = this.left + "px";
            }
        }
		
		this.mdiv = document.createElement("div");
		with(this.mdiv.style){
			width = "30px";
			height = "205px";
			//background = "red";
			overflow = "hidden";
			cursor = "pointer";
			display = "none";
			margin = "0px";
			background = "url("+this.dir+"images/sz"+(this.lng==1?"_en":"")+".gif)";
		}
		this.icon.appendChild(this.mdiv);
		this.regEvent(this.mdiv,"click",function(){_this.show();});


		this.pdiv = document.createElement("div");
		this.icon.appendChild(this.pdiv);
		
		

        // Border Top
        var bt = document.createElement("div");
        with(bt.style){
            width = this.width+"px";
            height = "5px";
            overflow = "hidden";
            background = "url("+this.dir+"images/bg-top.gif)";
        }
        this.pdiv.appendChild(bt);

        // Frame Body
        var bd = document.createElement("div");
        with(bd.style){
            width = this.width+"px";
            overflow = "hidden";
            background = "url("+this.dir+"images/bg.gif)";
        }
        this.pdiv.appendChild(bd);

        // Image CS
        var csi = document.createElement("div");
        with(csi.style){
            width = "120px";
            height = "98px";
            overflow = "hidden";
            margin = "0 auto";
            cursor = "pointer";
            background = "url("+this.dir+"images/cs"+this.style+(this.lng==1?"_en":"")+".gif)";
        }
        bd.appendChild(csi);
        this.regEvent(csi, "click",function(){_this.opwin(_this.csa[0].id);});

        // UL CS List
        this.csl = document.createElement("div");
        with(this.csl.style){
            margin = "0 auto";
            padding = "0px";
            listStyleType = "none";
            width = "129px";
        }
        bd.appendChild(this.csl);

        // Image Button Close
        this.btnclose = document.createElement("div");
        with(this.btnclose.style){
            height = "14px";
            width = "16px";
            overflow = "hidden";
            position = "absolute";
            top = "87px";
            left = "123px";
            cursor = "pointer";
            background = "url("+this.dir+"images/close.gif)";
        }
        this.regEvent(this.btnclose,"click",function(){_this.hide();});
        this.pdiv.appendChild(this.btnclose);

        // Image Signal
        var sn = document.createElement("div");
        with(sn.style){
            height = "11px";
            width = "25px";
            overflow = "hidden";
            position = "absolute";
            top = "6px";
            left = "118px";
            background = "url("+this.dir+"images/signal"+(this.lng==1?"_en":"")+".gif)";
        }
        this.pdiv.appendChild(sn);

        // Border Bottom
        var bb = document.createElement("div");
        with(bb.style){
            width = this.width+"px";
            height = "5px";
            overflow = "hidden";
            background = "url("+this.dir+"images/bg-bottom.gif)";
        }
        this.pdiv.appendChild(bb);

        this.height = this.icon.scrollHeight;

        this.regEvent(window,"scroll",function(){_this.reloc();});
        this.regEvent(window,"resize",function(){_this.reloc();});
        this.reloc();
        
        if(this.atInvite){
            setTimeout(function(){_this.ibInit()},5000);    
        }
    },

    ibInit : function(){
        var _this = this;
        if(!this.idialog){
            this.idialog = document.createElement("div");
            document.body.insertBefore(this.idialog,document.body.childNodes[0]);
            var ibBtnOpen  = document.createElement("div");
            var ibBtnClose = document.createElement("div");

            this.idialog.appendChild(ibBtnOpen);
            this.idialog.appendChild(ibBtnClose);

            with(this.idialog.style){
                zIndex = 999;
                width = "322px";
                height = "151px";
                fontSize = "12px";
                top = "50px";
                left = "50px";
                position = "absolute";
                opacity = 1.0;
                filter = "alpha(opacity=100)";
                background = "url("+this.dir+"images/dialog-bg"+(this.lng==1?"_en":"")+".gif)";
            }
            with(ibBtnOpen.style){
                cursor = "pointer";
                position = "absolute";
                top = "105px";
                left = "59px";
                width = "76px";
                height = "25px";
                background = "url("+this.dir+"images/accept_1"+(this.lng==1?"_en":"")+".gif)";
            }
            with(ibBtnClose.style){
                cursor = "pointer";
                position = "absolute";
                top = "105px";
                left = "185px";
                width = "76px";
                height = "25px";
                background = "url("+this.dir+"images/next_1"+(this.lng==1?"_en":"")+".gif)";
            }
            this.regEvent(ibBtnOpen, "click",function(){_this.opwin(_this.csa[0].id);});
            this.regEvent(ibBtnClose,"click",function(){_this.ibHide();});
            this.regEvent(window,"scroll",function(){_this.ibReloc();});
            this.regEvent(window,"resize",function(){_this.ibReloc();});
            this.ibReloc();
        }else{
            this.idialog.style.display = "block";
        }
    },

    ibHide : function(){
        this.idialog.style.display = "none";
    },

    ibReloc : function(){
        var ws = this.wSize();
        var ctop = this.idialog.offsetTop;
        var ttop = this.sTop() + Math.ceil((ws.h-this.idialog.scrollHeight)/2);
        this.idialog.style.left = Math.ceil((ws.w-this.idialog.scrollWidth)/2)+"px";
        clearTimeout(this.timeri);
        this.ibMove(0,ctop,ttop-ctop,100);
    },

    ibMove : function(t,b,c,d){
        var _this = this;
        var mtop = Math.ceil(this.Tween["Bounce"].easeOut(t,b,c,d)); 
        this.idialog.style.top = mtop + "px";
        if(t<d){this.timeri = setTimeout(function(){_this.ibMove(++t,b,c,d);},this.deley);}
    },

    add : function(id,name){
        var _this = this;
        var cs = document.createElement("div");
        with(cs.style){
            height = "25px";
            width = "129px";
            lineHeight = "25px";
            fontSize = "16px";
            fontWeight = "bold";
            textAlign = "center";
            color = "#FFFFFF";
            margin = "4px 0px";
            padding = "0px";
            overflow = "hidden";
            cursor = "pointer";
            background = "url("+this.dir+"images/btn.gif)";
        }
        cs.innerHTML = name;
        this.regEvent(cs,"click",function(){_this.opwin(id);});
        this.csl.appendChild(cs);
        this.csa.push({id:id, name:name});
        this.height = this.icon.scrollHeight;
    },

    opwin : function(csid){
        var url;
	if(this.lng==1){
		url = this.dir+"login_en.asp?epuid="+this.epuid+"&csvcid="+csid;
	}else{
		url = this.dir+"login.asp?epuid="+this.epuid+"&csvcid="+csid;
	}
        var p = [];
        p.push("height=479");
        p.push("width=708");
        p.push("top=200");
        p.push("left=200");
        p.push("status=no");
        p.push("toolbar=no");
        p.push("menubar=no");
        p.push("resizable=no");
        p.push("scrollbars=no");
        p.push("location=no");
        p.push("titlebar=no");
        window.open(url,"hwtSMS_CS_Client"+csid,p.join(","));
        this.opened = true;
    },

    hide : function(){
        this.pdiv.style.display = "none";
		this.mdiv.style.display = "";
		this.icon.style.width = "30px";
    },

    show : function(){
        this.pdiv.style.display = "";
		this.mdiv.style.display = "none";
		this.icon.style.width = "147px";
    },

    reloc : function(){
        var ttop = this.sTop();
        var ctop = this.icon.offsetTop;
        var ws = this.wSize();

        switch(this.valign){
            case "middle" : ttop += Math.ceil(ws.h/2-this.height/2);
            break;
            case "bottom" : ttop += ws.h - this.height - this.bottom;
            break;
            case "top"    : ttop += this.top;
        }

        if(this.align=="middle"){
            this.icon.style.left = Math.ceil((ws.w-this.width)/2)+"px";
        }

        clearTimeout(this.timer);
        this.move(0,ctop,ttop-ctop,this.duration);
    },

    move : function(t,b,c,d){
        var _this = this;
        var mtop = Math.ceil(this.Tween[this.algo].easeOut(t,b,c,d)); 
        this.icon.style.top = mtop + "px";
        if(t<d){this.timer = setTimeout(function(){_this.move(++t,b,c,d);},this.deley);}
    },

    sTop : function(){
        if(window.innerWidth){
            return window.pageYOffset;
        }else if(document.documentElement && document.documentElement.clientWidth){
            return document.documentElement.scrollTop;
        }else if(document.body.clientWidth){
            return document.body.scrollTop;
        }
    },

    wSize : function(){
        var h,w;
        var bw = this.getBrowser();
        var dt = this.hasDoctype();
        if(bw=="firefox"){
            h = window.innerHeight;
            w = document.documentElement.clientWidth+21;
        }else if(bw=="ie6"){
            h = document.documentElement.offsetHeight;
            w = document.documentElement.offsetWidth;
        }else if(bw=="ie7"){
            h = document.documentElement.offsetHeight;
            w = document.documentElement.offsetWidth;
            if(dt){w=w+21;}
        }else if(bw=="ie8"){
            h = document.documentElement.offsetHeight;
            w = document.documentElement.offsetWidth;
        }else{
            h = document.documentElement.offsetHeight;
            w = document.documentElement.offsetWidth;
        }
        return {h:h,w:w};
    },

    hasDoctype : function (){
        var ret=false;
        try{
            if(document.compatMode=="BackCompat")
               ret=false;
            else if(document.compatMode=="CSS1Compat")
               ret=true;
            else
               ret=true;
        }catch(e){ ret=false }
        return ret;
    },

    getBrowser : function(){ 
        var b = "ie6";
        var ua = navigator.userAgent; 
        if(ua.indexOf("compatible")>-1){
            if(ua.indexOf("MSIE 6.0") > -1)
               b = "ie6"
            else if(ua.indexOf("MSIE 7.0") > -1)
               b = "ie7";
            else if(ua.indexOf("MSIE 8.0") > -1)
               b = "ie8";
        }
        else if(ua.indexOf("Gecko") > -1)
            b = "firefox";
      return b;
    },

    Tween : {
        Quint: {
            easeOut: function(t,b,c,d){
                return c*((t=t/d-1)*t*t*t*t + 1) + b;
            }
        },

        Bounce: {
            easeOut: function(t,b,c,d){
                if ((t/=d) < (1/2.75)) {
                    return c*(7.5625*t*t) + b;
                } else if (t < (2/2.75)) {
                    return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
                } else if (t < (2.5/2.75)) {
                    return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
                } else {
                    return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
                }
            }
        }
    },

    regEvent : function(e,t,f){
        if(e.attachEvent){
            e.attachEvent('on'+t,f);
        }else if(e.addEventListener){
            e.addEventListener(t,f,false);
        }else{
            e['on'+t] = f;
        }
    }
};



(function(){
    var a = new hwtCSIcon();
    a.dir = "http://hwt.555aaa.com/";
    a.align = "left";
    a.valign = "top";
    a.top = 50;
    a.left = 20;
    a.right = 20;
    a.bottom = 50;
    a.epuid = 67;
    a.style = 0;
    a.atInvite = false;
    a.lng = 1;
    a.init();
        a.add(68,'Dongli');

})();

