Array.prototype.reach = function(a, b) {
    for (var i = this.length - 1; i >= 0; i--)a.call(b, this[i], i, this)
};
var Preview = new Class({initialize:function(a) {
    this.button = a;
    this.href = $E('.href', a.getParent()).innerHTML;
    this.li = a.getParent().getParent();
    this.sw = false;
    this.frame = new Element('div').adopt(new Element('iframe'));
    a.addEvent('click', this.toggle.bind(this))
},toggle:function() {
    this.sw = !this.sw;
    this.button.innerHTML = this.sw ? '\u5173\u95ed' : '\u9884\u89c8';
    if (this.sw) {
        this.frame.injectInside(this.li);
        $E('iframe', this.frame).setProperty('src', this.href)
    } else this.frame.remove()
}});
var Bookmark = new Class({initialize:function(a) {
    this.data = {'mockUrl.url':$E('.href', a.getParent()).innerHTML,'mockUrl.title':$E('.title', a.getParent()).innerHTML,'mockUrl.brief':$E('.content', a.getParent().getParent()).innerHTML.replace(/<\/?b>/gi, '')};
    a.addEvent('click', this.tag.bind(this))
},tag:function() {
    Object.extend(this.data, {'mockUrl.tagString':$('search').value});
    var a = 650;
    var b = 350;
    var c = parseInt((screen.availWidth / 2) - (a / 2));
    var d = parseInt((screen.availHeight / 2) - (b / 2));
    window.open("http://cang.suotianxia.com/home!post.action?" + Object.toQueryString(this.data), "mywindow", "width=" + a + ",height=" + b + ",left=" + c + ",top=" + d + ",menubar=0,toolbar=0,scrollbars=1,location=0,status=1,resizable=1")
}});
var loadHistory = function(a, b, c) {
    var f = {duration:10};
    var g = Cookie.get('his');
    var i = Cookie.get('ts');
    var h = g ? g.split(',') : [];
    var t = i ? i.split(',') : [];
    var j = function() {
        g = h.join(',');
        i = t.join(',');
        Cookie.set('his', g, f);
        Cookie.set('ts', i, f)
    };
    var k = function(a) {
        var b = (new Date().getTime() - a) / 1000;
        if (Math.floor(b) == 0)return'\u73b0\u5728';
        if (b < 60)return Math.floor(b) + '\u79d2\u949f\u524d';
        var c = b / 60;
        if (c < 60)return Math.floor(c) + '\u5206\u949f\u524d';
        var d = c / 60;
        if (d < 24)return Math.floor(d) + '\u5c0f\u65f6\u524d';
        var e = d / 24;
        return Math.floor(e) + '\u5929\u524d'
    };
    if (t.length != h.length) {
        h.each(function(x) {
            t.push(new Date().getTime())
        });
        j()
    }
    if (h.length > 10) {
        h = h.copy(0, 8);
        t = t.copy(0, 8)
    }
    var l = $(a).value.replace(/[,]/g, '');
    if (!h.test(l)) {
        h.push(l);
        t.push(new Date().getTime());
        j()
    }
    $(b).innerHTML = '';
    var m = new Element('ul').addClass('history').injectAfter(new Element('h2').setHTML('\u641c\u7d22\u5386\u53f2').adopt(new Element('a').setStyles({'padding-left':'5px','font-size':'0.8em','color':'#FE0000'}).setHTML('[\u6e05\u9664]').setProperty('href', 'javascript:void(0)').addEvent('click', function() {
        Cookie.set('his', '', f);
        Cookie.set('ts', '', f);
        $(b).remove()
    })).injectInside(b));
    h.reach(function(l, p) {
        new Element('a').setProperty('href', 'javascript:void(0)').setProperty('title', l + '[' + k(t[p]) + ']').setHTML(l.length > 10 ? l.substring(0, 3) + '...' + l.substring(l.length - 3) : l).addEvent('click', function(e) {
            e = new Event(e);
            e.stop();
            $(a).value = l;
            c(l)
        }).injectInside(new Element('li').injectInside(m))
    })
};