(function () {
    var d = document,
    isStrict = d.compatMode == "CSS1Compat",
    dd = d.documentElement,
    db = d.body,
    m = Math.max,
    ie = !!d.all,
    ua = navigator.userAgent.toLowerCase(),
    ff = /firefox/.test(ua),
    head = d.getElementsByTagName('head')[0],
    getWH = function () {
        return {
            h: (isStrict ? dd : db).clientHeight,
            w: (isStrict ? dd : db).clientWidth
        }
    },
    getS = function () {
        return {
            t: m(dd.scrollTop, db.scrollTop),
            l: m(dd.scrollLeft, db.scrollLeft)
        }
    },
    getP = function (a) {
        var r = {
            t: 0,
            l: 0
        },
        isGecko = /gecko/.test(ua),
        add = function (t, l) {
            r.l += l,
            r.t += t
        },
        p = a,
        sTL = getS();
        if (a && a != db) {
            if (a.getBoundingClientRect) {
                var b = a.getBoundingClientRect();
                add(b.top + sTL.t - dd.clientTop, b.left + sTL.l - dd.clientLeft)
            } else {
                var c = d.defaultView;
                while (p) {
                    add(p.offsetTop, p.offsetLeft);
                    var e = c.getComputedStyle(p, null);
                    if (isGecko) {
                        var f = parseInt(e.getPropertyValue('border-left-width'), 10) || 0,
                        bt = parseInt(e.getPropertyValue('border-top-width'), 10) || 0;
                        add(bt, f);
                        if (p != a && e.getPropertyValue('overflow') != 'visible') add(bt, f)
                    }
                    p = p.offsetParent
                }
                p = a.parentNode;
                while (p && p != db) {
                    add(-p.scrollTop, -p.scrollLeft);
                    p = p.parentNode
                }
            }
        }
        return r
    },
    creElm = function (o, t, a) {
        var b = d.createElement(t || 'div');
        for (var p in o) {
            p == 'style' ? b[p].cssText = o[p] : b[p] = o[p]
        }
        return (a || db).insertBefore(b, (a || db).firstChild)
    },
    div = creElm({
        id: 'ckepops',
        style: "position:absolute;z-index:100000;display:none"
    }),
    div1 = creElm({
        id: 'ckepops',
        style: "position:absolute;z-index:100000;display:none;top:50%;left:50%;overflow:auto"
    }),
    timer,
    inputTimer,
    list,
    clist,
    as,
    texts = {},
    iframe,
    tagImgs = ["fav8.gif", "fav81.gif", "fav82.gif", "fav83.gif", "fav84.gif", "fav85.gif", "fav86.gif"],
    scripts = d.getElementsByTagName('script');
    for (var i = 0, ci, Bn; ci = scripts[i++];) {
        if (Bn = ci.src.match(/Bn=(\d)$/)) {
            break
        }
    };
    creElm({
        href: 'http://www.fav8.com/css/css1.css',
        rel: 'stylesheet',
        type: 'text/css'
    },
    'link');
    d.write('<a href="#" onmouseover="return $FAV8.overs(this)" onmouseout="return $FAV8.outs()" onmousemove="$FAV8.moves()" onclick="return $FAV8.centers()"><img src="http://www.fav8.com/images/' + tagImgs[(Bn && Bn[1]) || 0] + '" width="125" height="21" border="0" id="fav8_a"/></a>');
    $FAV8 = {
        pops: div,
        centerpops: div1,
        disappears: function (b) {
            var c = window.event || b,
            t = c.srcElement || c.target,
            contain = div1.contains ? div1.contains(t) : !!(div1.compareDocumentPosition(t) & 16),
            a = d.getElementById('fav8_a'),
            contain1 = div.contains ? div.contains(t) : !!(div.compareDocumentPosition(t) & 16);
            if (!contain && !contain1 && t != a) {
                div1.style.display = 'none';
               iframe&&(iframe.style.display= 'none');
                ff&&(div1.style.position='absolute');
            }
        },
        overs: function (a) {
        	var s,T = this,fn = function(){
        		var p = getP(T.a),
           	 	wh = getWH(),
	            tl = getS();
	            with(div.style) {
	                display = "block";
	                top = (p.t + T.a.offsetHeight + div.offsetHeight > wh.h + tl.t ? p.t - div.offsetHeight - (ie ? 1 : 8) : p.t + T.a.offsetHeight + 1) + 'px';
	                left = p.l + 'px'
	            }
        	};
            if (!this.a) {
                this.a = a;
                s = creElm({
                    src: 'http://www.fav8.com/code/pops.js',
                    charset: 'utf-8'
                },
                'script', head);
                s.onloaded = 0;
                s.onload = function(){s.onloaded=1;fn()};
                s.onreadystatechange = function(){
                	if(s.readyState =='loaded'&&!s.onloaded){
                		fn();
                	}
                }
            }else{
            	fn();
            }
            
            
            return false
        },
        outs: function () {
            timer = setTimeout(function () {
                div.style.display = 'none'
            },
            100)
        },
        moves: function () {
            clearTimeout(timer)
        },
        centers: function () {
            div.style.display = 'none';
            if (!this.script) {
                this.script = creElm({
                    src: 'http://www.fav8.com/code/centerpops.js',
                    charset: 'utf-8'
                },
                'script', head);
                db.style.position = 'static'
            } else {
                var a = getS();
                div1.style.display = "block";
                div1.style.margin = (-div1.offsetHeight / 2 + a.t) + "px " + (-div1.offsetWidth / 2 + a.l) + "px";
                ff&&(div1.style.position='fixed');
                list = d.getElementById('fav8list'),
                clist = list.cloneNode(true),
                as = clist.getElementsByTagName('input');
                for (var i = 0, ci; ci = as[i++];) {
                    texts[ci.value] = ci.parentNode
                };
               	if(!ff){
                	!iframe&&(iframe = creElm({
                		style:'position:absolute;top:'+div1.offsetTop+'px;left:'+div1.offsetLeft+'px;width:'+div1.offsetWidth+'px;height:'+div1.offsetHeight+'px',
                		frameBorder:0
                	},'iframe'));
                	iframe.style.display= 'block';
                }
            }
            return false
        },
        chooses: function (o) {
            clearTimeout(inputTimer);
            inputTimer = setTimeout(function () {
                var s = o.value.replace(/^\s+|\s+$/, ''),
                frag = d.createDocumentFragment();
                for (var p in texts) {
                    eval("var f = /" + (s || '.') + "/ig.test(p)");
                    f && frag.appendChild(texts[p].cloneNode(true))
                }
                list.innerHTML = '';
                list.appendChild(frag)
            },
            100)
        },
        centerCloses: function () {
            div1.style.display = 'none';
             iframe&&(iframe.style.display= 'none');
             ff&&(div1.style.position='absolute');
        }
    };
    div.onmouseover = function () {
        clearTimeout(timer)
    };
    div.onmouseout = function () {
        $FAV8.outs()
    };
    ie ? d.attachEvent("onclick", $FAV8.disappears) : d.addEventListener("click", $FAV8.disappears, false)
})();
function fav8_sendto(m) {
    window.open('http://www.fav8.com/send/?webid=' + m + '&url=' + encodeURIComponent(location) + '&title=' + encodeURIComponent(document.title), '');
    return false
};
function fav8_copyUrl() {
    var a = this.location.href;
    var b = document.title;
    if (window.clipboardData) {
        var c = b + "\n" + a;
        var d = window.clipboardData.setData("Text", c);
        if (d) alert("复制成功,请粘贴到你的QQ/MSN上推荐给你的好友！")
    } else {
        alert("目前只支持IE，请复制地址栏URL,推荐给你的QQ/MSN好友！")
    }
};
function fav8_addBookmark(a) {
    var b = parent.location.href;
    if (window.sidebar) {
        window.sidebar.addPanel(a, b, "")
    } else if (document.all) {
        window.external.AddFavorite(b, a)
    } else if (window.opera && window.print) {
        return true
    }
}