var Class = function (a) {
    var b = function () {
        if (this.initialize && arguments[0] != 'noinit') return this.initialize.apply(this, arguments);
        else
        return this
    };
    for (var c in this) b[c] = this[c];
    b.prototype = a;
    return b
};
Class.empty = function () {};
Class.prototype = {
    extend: function (c) {
        var d = new this('noinit');
        var e = function (a, b) {
            if (!a.apply || !b.apply) return false;
            return function () {
                this.parent = a;
                return b.apply(this, arguments)
            }
        };
        for (var f in c) {
            var g = d[f];
            var h = c[f];
            if (g && g != h) h = e(g, h) || h;
            d[f] = h
        }
        return new Class(d)
    },
    implement: function (a) {
        for (var b in a) this.prototype[b] = a[b]
    }
};
Object.extend = function () {
    var a = arguments;
    a = (a[1]) ? [a[0], a[1]] : [this, a[0]];
    for (var b in a[1]) a[0][b] = a[1][b];
    return a[0]
};
Object.Native = function () {
    for (var i = 0; i < arguments.length; i++) arguments[i].extend = Class.prototype.implement
};
new Object.Native(Function, Array, String, Number, Class);
if (typeof HTMLElement == 'undefined') {
    var HTMLElement = Class.empty;
    HTMLElement.prototype = {}
} else {
    HTMLElement.prototype.htmlElement = true
}
window.extend = document.extend = Object.extend;
var Window = window;

function $type(a) {
    if (a === null || a === undefined) return false;
    var b = typeof a;
    if (b == 'object') {
        if (a.htmlElement) return 'element';
        if (a.push) return 'array';
        if (a.nodeName) {
            switch (a.nodeType) {
            case 1:
                return 'element';
            case 3:
                return a.nodeValue.test(/\S/) ? 'textnode' : 'whitespace'
            }
        }
    }
    return b
};

function $chk(a) {
    return !!(a || a === 0)
};

function $pick(a, b) {
    return ($type(a)) ? a : b
};

function $random(a, b) {
    return Math.floor(Math.random() * (b - a + 1) + a)
};

function $clear(a) {
    clearTimeout(a);
    clearInterval(a);
    return null
};
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.khtml = true;
else if (document.getBoxObjectFor != null) window.gecko = true;
if (window.ie6) try {
    document.execCommand("BackgroundImageCache", false, true)
} catch (e) {};
Array.prototype.forEach = Array.prototype.forEach ||
function (a, b) {
    for (var i = 0; i < this.length; i++) a.call(b, this[i], i, this)
};
Array.prototype.filter = Array.prototype.filter ||
function (a, b) {
    var c = [];
    for (var i = 0; i < this.length; i++) {
        if (a.call(b, this[i], i, this)) c.push(this[i])
    }
    return c
};
Array.prototype.map = Array.prototype.map ||
function (a, b) {
    var c = [];
    for (var i = 0; i < this.length; i++) c[i] = a.call(b, this[i], i, this);
    return c
};
Array.prototype.every = Array.prototype.every ||
function (a, b) {
    for (var i = 0; i < this.length; i++) {
        if (!a.call(b, this[i], i, this)) return false
    }
    return true
};
Array.prototype.some = Array.prototype.some ||
function (a, b) {
    for (var i = 0; i < this.length; i++) {
        if (a.call(b, this[i], i, this)) return true
    }
    return false
};
Array.prototype.indexOf = Array.prototype.indexOf ||
function (a, b) {
    b = b || 0;
    if (b < 0) b = Math.max(0, this.length + b);
    while (b < this.length) {
        if (this[b] === a) return b;
        b++
    }
    return -1
};
Array.extend({
    each: Array.prototype.forEach,
    copy: function (a, b) {
        a = a || 0;
        if (a < 0) a = this.length + a;
        b = b || (this.length - a);
        var c = [];
        for (var i = 0; i < b; i++) c[i] = this[a++];
        return c
    },
    remove: function (a) {
        var i = 0;
        while (i < this.length) {
            if (this[i] === a) this.splice(i, 1);
            else i++
        }
        return this
    },
    test: function (a, b) {
        return this.indexOf(a, b) != -1
    },
    extend: function (a) {
        for (var i = 0; i < a.length; i++) this.push(a[i]);
        return this
    },
    associate: function (a) {
        var b = {},
            length = Math.min(this.length, a.length);
        for (var i = 0; i < length; i++) b[a[i]] = this[i];
        return b
    }
});

function $A(a, b, c) {
    return Array.prototype.copy.call(a, b, c)
};

function $each(a, b, c) {
    return Array.prototype.forEach.call(a, b, c)
};
String.extend({
    test: function (a, b) {
        return ((typeof a == 'string') ? new RegExp(a, b) : a).test(this)
    },
    toInt: function () {
        return parseInt(this)
    },
    toFloat: function () {
        return parseFloat(this)
    },
    camelCase: function () {
        return this.replace(/-\D/g, function (a) {
            return a.charAt(1).toUpperCase()
        })
    },
    hyphenate: function () {
        return this.replace(/\w[A-Z]/g, function (a) {
            return (a.charAt(0) + '-' + a.charAt(1).toLowerCase())
        })
    },
    capitalize: function () {
        return this.toLowerCase().replace(/\b[a-z]/g, function (a) {
            return a.toUpperCase()
        })
    },
    trim: function () {
        return this.replace(/^\s+|\s+$/g, '')
    },
    clean: function () {
        return this.replace(/\s{2,}/g, ' ').trim()
    },
    rgbToHex: function (a) {
        var b = this.match(/\d{1,3}/g);
        return (b) ? b.rgbToHex(a) : false
    },
    hexToRgb: function (a) {
        var b = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
        return (b) ? b.slice(1).hexToRgb(a) : false
    }
});
Array.extend({
    rgbToHex: function (a) {
        if (this.length < 3) return false;
        if (this[3] && (this[3] == 0) && !a) return 'transparent';
        var b = [];
        for (var i = 0; i < 3; i++) {
            var c = (this[i] - 0).toString(16);
            b.push((c.length == 1) ? '0' + c : c)
        }
        return a ? b : '#' + b.join('')
    },
    hexToRgb: function (a) {
        if (this.length != 3) return false;
        var b = [];
        for (var i = 0; i < 3; i++) {
            b.push(parseInt((this[i].length == 1) ? this[i] + this[i] : this[i], 16))
        }
        return a ? b : 'rgb(' + b.join(',') + ')'
    }
});
Number.extend({
    toInt: function () {
        return parseInt(this)
    },
    toFloat: function () {
        return parseFloat(this)
    }
});
Function.extend({
    create: function (d) {
        var e = this;
        d = Object.extend({
            'bind': e,
            'event': false,
            'arguments': null,
            'delay': false,
            'periodical': false,
            'attempt': false
        }, d || {});
        if ($chk(d.arguments) && $type(d.arguments) != 'array') d.arguments = [d.arguments];
        return function (a) {
            var b;
            if (d.event) {
                a = a || window.event;
                b = [(d.event === true) ? a : new d.event(a)];
                if (d.arguments) b = b.concat(d.arguments)
            } else b = d.arguments || arguments;
            var c = function () {
                return e.apply(d.bind, b)
            };
            if (d.delay) return setTimeout(c, d.delay);
            if (d.periodical) return setInterval(c, d.periodical);
            if (d.attempt) {
                try {
                    return c()
                } catch (err) {
                    return err
                }
            }
            return c()
        }
    },
    pass: function (a, b) {
        return this.create({
            'arguments': a,
            'bind': b
        })
    },
    attempt: function (a, b) {
        return this.create({
            'arguments': a,
            'bind': b,
            'attempt': true
        })()
    },
    bind: function (a, b) {
        return this.create({
            'bind': a,
            'arguments': b
        })
    },
    bindAsEventListener: function (a, b) {
        return this.create({
            'bind': a,
            'event': true,
            'arguments': b
        })
    },
    delay: function (a, b, c) {
        return this.create({
            'delay': a,
            'bind': b,
            'arguments': c
        })()
    },
    periodical: function (a, b, c) {
        return this.create({
            'periodical': a,
            'bind': b,
            'arguments': c
        })()
    }
});
var Element = new Class({
    initialize: function (a) {
        if ($type(a) == 'string') a = document.createElement(a);
        return $(a)
    }
});

function $(a) {
    if (!a) return false;
    if (a._element_extended_ || [window, document].test(a)) return a;
    if ($type(a) == 'string') a = document.getElementById(a);
    if ($type(a) != 'element') return false;
    if (['object', 'embed'].test(a.tagName.toLowerCase()) || a.extend) return a;
    a._element_extended_ = true;
    Garbage.collect(a);
    a.extend = Object.extend;
    if (!(a.htmlElement)) a.extend(Element.prototype);
    return a
};
var Elements = new Class({});
new Object.Native(Elements);
document.getElementsBySelector = document.getElementsByTagName;

function $$() {
    if (!arguments) return false;
    if (arguments.length == 1) {
        if (!arguments[0]) return false;
        if (arguments[0]._elements_extended_) return arguments[0]
    }
    var c = [];
    $each(arguments, function (b) {
        switch ($type(b)) {
        case 'element':
            c.push($(b));
            break;
        case 'string':
            b = document.getElementsBySelector(b);
        default:
            if (b.length) {
                $each(b, function (a) {
                    if ($(a)) c.push(a)
                })
            }
        }
    });
    c._elements_extended_ = true;
    return Object.extend(c, new Elements)
};
Elements.Multi = function (f) {
    return function () {
        var c = arguments;
        var d = [];
        var e = true;
        $each(this, function (a) {
            var b = a[f].apply(a, c);
            if ($type(b) != 'element') e = false;
            d.push(b)
        });
        if (e) d = $$(d);
        return d
    }
};
Element.extend = function (a) {
    for (var b in a) {
        HTMLElement.prototype[b] = a[b];
        Element.prototype[b] = a[b];
        Elements.prototype[b] = Elements.Multi(b)
    }
};
Element.extend({
    inject: function (a, b) {
        a = $(a) || new Element(a);
        switch (b) {
        case "before":
            $(a.parentNode).insertBefore(this, a);
            break;
        case "after":
            if (!a.getNext()) $(a.parentNode).appendChild(this);
            else $(a.parentNode).insertBefore(this, a.getNext());
            break;
        case "inside":
            a.appendChild(this)
        }
        return this
    },
    injectBefore: function (a) {
        return this.inject(a, 'before')
    },
    injectAfter: function (a) {
        return this.inject(a, 'after')
    },
    injectInside: function (a) {
        return this.inject(a, 'inside')
    },
    adopt: function (a) {
        this.appendChild($(a) || new Element(a));
        return this
    },
    remove: function () {
        this.parentNode.removeChild(this);
        return this
    },
    clone: function (a) {
        var b = this.cloneNode(a !== false);
        return $(b)
    },
    replaceWith: function (a) {
        a = $(a) || new Element(a);
        this.parentNode.replaceChild(a, this);
        return a
    },
    appendText: function (a) {
        if (window.ie) {
            switch (this.getTag()) {
            case 'style':
                this.styleSheet.cssText = a;
                return this;
            case 'script':
                this.setProperty('text', a);
                return this
            }
        }
        this.appendChild(document.createTextNode(a));
        return this
    },
    hasClass: function (a) {
        return this.className.test('(?:^|\\s)' + a + '(?:\\s|$)')
    },
    addClass: function (a) {
        if (!this.hasClass(a)) this.className = (this.className + ' ' + a).clean();
        return this
    },
    removeClass: function (a) {
        this.className = this.className.replace(new RegExp('(^|\\s)' + a + '(?:\\s|$)'), '$1').clean();
        return this
    },
    toggleClass: function (a) {
        return this.hasClass(a) ? this.removeClass(a) : this.addClass(a)
    },
    setStyle: function (a, b) {
        if (a == 'opacity') this.setOpacity(parseFloat(b));
        else this.style[a.camelCase()] = (b.push) ? 'rgb(' + b.join(',') + ')' : b;
        return this
    },
    setStyles: function (a) {
        switch ($type(a)) {
        case 'object':
            for (var b in a) this.setStyle(b, a[b]);
            break;
        case 'string':
            this.style.cssText = a
        }
        return this
    },
    setOpacity: function (a) {
        if (a == 0) {
            if (this.style.visibility != "hidden") this.style.visibility = "hidden"
        } else {
            if (this.style.visibility != "visible") this.style.visibility = "visible"
        }
        if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
        if (window.ie) this.style.filter = "alpha(opacity=" + a * 100 + ")";
        this.style.opacity = this.opacity = a;
        return this
    },
    getStyle: function (a) {
        a = a.camelCase();
        var b = this.style[a] || false;
        if (!$chk(b)) {
            if (a == 'opacity') return $chk(this.opacity) ? this.opacity : 1;
            if (['margin', 'padding'].test(a)) {
                return [this.getStyle(a + '-top') || 0, this.getStyle(a + '-right') || 0, this.getStyle(a + '-bottom') || 0, this.getStyle(a + '-left') || 0].join(' ')
            }
            if (document.defaultView) b = document.defaultView.getComputedStyle(this, null).getPropertyValue(a.hyphenate());
            else if (this.currentStyle) b = this.currentStyle[a]
        }
        if (b == 'auto' && ['height', 'width'].test(a)) return this['offset' + a.capitalize()] + 'px';
        return (b && a.test(/color/i) && b.test(/rgb/)) ? b.rgbToHex() : b
    },
    addEvent: function (a, b) {
        this.events = this.events || {};
        this.events[a] = this.events[a] || {
            'keys': [],
            'values': []
        };
        if (!this.events[a].keys.test(b)) {
            this.events[a].keys.push(b);
            if (this.addEventListener) {
                this.addEventListener((a == 'mousewheel' && window.gecko) ? 'DOMMouseScroll' : a, b, false)
            } else {
                b = b.bind(this);
                this.attachEvent('on' + a, b);
                this.events[a].values.push(b)
            }
        }
        return this
    },
    addEvents: function (a) {
        if (a) {
            for (var b in a) this.addEvent(b, a[b])
        }
        return this
    },
    removeEvent: function (a, b) {
        if (this.events && this.events[a]) {
            var c = this.events[a].keys.indexOf(b);
            if (c == -1) return this;
            var d = this.events[a].keys.splice(c, 1)[0];
            if (this.removeEventListener) {
                this.removeEventListener((a == 'mousewheel' && window.gecko) ? 'DOMMouseScroll' : a, d, false)
            } else {
                this.detachEvent('on' + a, this.events[a].values.splice(c, 1)[0])
            }
        }
        return this
    },
    removeEvents: function (b) {
        if (this.events) {
            if (b) {
                if (this.events[b]) {
                    this.events[b].keys.each(function (a) {
                        this.removeEvent(b, a)
                    }, this);
                    this.events[b] = null
                }
            } else {
                for (var c in this.events) this.removeEvents(c);
                this.events = null
            }
        }
        return this
    },
    fireEvent: function (b, c) {
        if (this.events && this.events[b]) {
            this.events[b].keys.each(function (a) {
                a.bind(this, c)()
            }, this)
        }
    },
    getBrother: function (a) {
        var b = this[a + 'Sibling'];
        while ($type(b) == 'whitespace') b = b[a + 'Sibling'];
        return $(b)
    },
    getPrevious: function () {
        return this.getBrother('previous')
    },
    getNext: function () {
        return this.getBrother('next')
    },
    getFirst: function () {
        var a = this.firstChild;
        while ($type(a) == 'whitespace') a = a.nextSibling;
        return $(a)
    },
    getLast: function () {
        var a = this.lastChild;
        while ($type(a) == 'whitespace') a = a.previousSibling;
        return $(a)
    },
    getParent: function () {
        return $(this.parentNode)
    },
    getChildren: function () {
        return $$(this.childNodes)
    },
    setProperty: function (b, c) {
        switch (b) {
        case 'class':
            this.className = c;
            break;
        case 'style':
            this.setStyles(c);
            break;
        case 'name':
            if (window.ie6) {
                var d = $(document.createElement('<' + this.getTag() + ' name="' + c + '" />'));
                $each(this.attributes, function (a) {
                    if (a.name != 'name') d.setProperty(a.name, a.value)
                });
                if (this.parentNode) this.replaceWith(d);
                return d
            }
        default:
            this.setAttribute(b, c)
        }
        return this
    },
    setProperties: function (a) {
        for (var b in a) this.setProperty(b, a[b]);
        return this
    },
    setHTML: function () {
        this.innerHTML = $A(arguments).join('');
        return this
    },
    getProperty: function (a) {
        return (a == 'class') ? this.className : this.getAttribute(a)
    },
    getTag: function () {
        return this.tagName.toLowerCase()
    },
    scrollTo: function (x, y) {
        this.scrollLeft = x;
        this.scrollTop = y
    },
    getValue: function () {
        switch (this.getTag()) {
        case 'select':
            if (this.selectedIndex != -1) {
                var a = this.options[this.selectedIndex];
                return a.value || a.text
            }
            break;
        case 'input':
            if (!(this.checked && ['checkbox', 'radio'].test(this.type)) && !['hidden', 'text', 'password'].test(this.type)) break;
        case 'textarea':
            return this.value
        }
        return false
    },
    getSize: function () {
        return {
            'scroll': {
                'x': this.scrollLeft,
                'y': this.scrollTop
            },
            'size': {
                'x': this.offsetWidth,
                'y': this.offsetHeight
            },
            'scrollSize': {
                'x': this.scrollWidth,
                'y': this.scrollHeight
            }
        }
    },
    getPosition: function (b) {
        b = b || [];
        var c = this,
            left = 0,
            top = 0;
        do {
            left += c.offsetLeft || 0;
            top += c.offsetTop || 0;
            c = c.offsetParent
        } while (c);
        b.each(function (a) {
            left -= a.scrollLeft || 0;
            top -= a.scrollTop || 0
        });
        return {
            'x': left,
            'y': top
        }
    },
    getTop: function () {
        return this.getPosition().y
    },
    getLeft: function () {
        return this.getPosition().x
    },
    getCoordinates: function (a) {
        var b = this.getPosition(a);
        var c = {
            'width': this.offsetWidth,
            'height': this.offsetHeight,
            'left': b.x,
            'top': b.y
        };
        c.right = c.left + c.width;
        c.bottom = c.top + c.height;
        return c
    }
});
window.addEvent = document.addEvent = Element.prototype.addEvent;
window.removeEvent = document.removeEvent = Element.prototype.removeEvent;
window.removeEvents = document.removeEvents = Element.prototype.removeEvents;
var Garbage = {
    elements: [],
    collect: function (a) {
        Garbage.elements.push(a)
    },
    trash: function () {
        Garbage.collect(window);
        Garbage.collect(document);
        Garbage.elements.each(function (a) {
            a.removeEvents();
            for (var p in Element.prototype) a[p] = null;
            a.extend = null
        })
    }
};
window.addEvent('unload', Garbage.trash);
var Chain = new Class({
    chain: function (a) {
        this.chains = this.chains || [];
        this.chains.push(a);
        return this
    },
    callChain: function () {
        if (this.chains && this.chains.length) this.chains.shift().delay(10, this)
    },
    clearChain: function () {
        this.chains = []
    }
});
var Events = new Class({
    addEvent: function (a, b) {
        if (b != Class.empty) {
            this.events = this.events || {};
            this.events[a] = this.events[a] || [];
            if (!this.events[a].test(b)) this.events[a].push(b)
        }
        return this
    },
    fireEvent: function (b, c, d) {
        if (this.events && this.events[b]) {
            this.events[b].each(function (a) {
                a.create({
                    'bind': this,
                    'delay': d,
                    'arguments': c
                })()
            }, this)
        }
        return this
    },
    removeEvent: function (a, b) {
        if (this.events && this.events[a]) this.events[a].remove(b);
        return this
    }
});
var Options = new Class({
    setOptions: function (a, b) {
        this.options = Object.extend(a, b);
        if (this.addEvent) {
            for (var c in this.options) {
                if (($type(this.options[c]) == 'function') && c.test(/^on[A-Z]/)) this.addEvent(c, this.options[c])
            }
        }
        return this
    }
});
var Group = new Class({
    initialize: function () {
        this.instances = $A(arguments);
        this.events = {};
        this.checker = {}
    },
    addEvent: function (b, c) {
        this.checker[b] = this.checker[b] || {};
        this.events[b] = this.events[b] || [];
        if (this.events[b].test(c)) return false;
        else this.events[b].push(c);
        this.instances.each(function (a, i) {
            a.addEvent(b, this.check.bind(this, [b, a, i]))
        }, this);
        return this
    },
    check: function (b, c, i) {
        this.checker[b][i] = true;
        var d = this.instances.every(function (a, j) {
            return this.checker[b][j] || false
        }, this);
        if (!d) return;
        this.instances.each(function (a, j) {
            this.checker[b][j] = false
        }, this);
        this.events[b].each(function (a) {
            a.call(this, this.instances, c)
        }, this)
    }
});
window.extend({
    addEvent: function (a, b) {
        if (a == 'domready') {
            if (this.loaded) b();
            else if (!this.events || !this.events.domready) {
                var c = function () {
                    if (this.loaded) return;
                    this.loaded = true;
                    if (this.timer) this.timer = $clear(this.timer);
                    Element.prototype.fireEvent.call(this, 'domready');
                    this.events.domready = null
                }.bind(this);
                if (document.readyState && this.khtml) {
                    this.timer = function () {
                        if (['loaded', 'complete'].test(document.readyState)) c()
                    }.periodical(50)
                } else if (document.readyState && this.ie) {
                    document.write("<script id=ie_ready defer src=javascript:void(0)><\/script>");
                    $('ie_ready').onreadystatechange = function () {
                        if (this.readyState == 'complete') c()
                    }
                } else {
                    this.addEvent("load", c);
                    document.addEvent("DOMContentLoaded", c)
                }
            }
        }
        Element.prototype.addEvent.call(this, a, b);
        return this
    },
    onDomReady: function (a) {
        return this.addEvent('domready', a)
    }
});
window.extend({
    getWidth: function () {
        if (this.khtml) return this.innerWidth;
        if (this.opera) return document.body.clientWidth;
        return document.documentElement.clientWidth
    },
    getHeight: function () {
        if (this.khtml) return this.innerHeight;
        if (this.opera) return document.body.clientHeight;
        return document.documentElement.clientHeight
    },
    getScrollWidth: function () {
        if (this.ie) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
        if (this.khtml) return document.body.scrollWidth;
        return document.documentElement.scrollWidth
    },
    getScrollHeight: function () {
        if (this.ie) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
        if (this.khtml) return document.body.scrollHeight;
        return document.documentElement.scrollHeight
    },
    getScrollLeft: function () {
        return this.pageXOffset || document.documentElement.scrollLeft
    },
    getScrollTop: function () {
        return this.pageYOffset || document.documentElement.scrollTop
    },
    getSize: function () {
        return {
            'size': {
                'x': this.getWidth(),
                'y': this.getHeight()
            },
            'scrollSize': {
                'x': this.getScrollWidth(),
                'y': this.getScrollHeight()
            },
            'scroll': {
                'x': this.getScrollLeft(),
                'y': this.getScrollTop()
            }
        }
    },
    getPosition: function () {
        return {
            'x': 0,
            'y': 0
        }
    }
});
var Fx = {};
Fx.Base = new Class({
    getOptions: function () {
        return {
            onStart: Class.empty,
            onComplete: Class.empty,
            onCancel: Class.empty,
            transition: Fx.Transitions.sineInOut,
            duration: 500,
            unit: 'px',
            wait: true,
            fps: 50
        }
    },
    initialize: function (a) {
        this.element = this.element || null;
        this.setOptions(this.getOptions(), a);
        if (this.options.initialize) this.options.initialize.call(this)
    },
    step: function () {
        var a = new Date().getTime();
        if (a < this.time + this.options.duration) {
            this.cTime = a - this.time;
            this.setNow();
            this.increase()
        } else {
            this.stop(true);
            this.now = this.to;
            this.increase();
            this.fireEvent('onComplete', this.element, 10);
            this.callChain()
        }
    },
    set: function (a) {
        this.now = a;
        this.increase();
        return this
    },
    setNow: function () {
        this.now = this.compute(this.from, this.to)
    },
    compute: function (a, b) {
        return this.options.transition(this.cTime, a, (b - a), this.options.duration)
    },
    start: function (a, b) {
        if (!this.options.wait) this.stop();
        else if (this.timer) return this;
        this.from = a;
        this.to = b;
        this.time = new Date().getTime();
        this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this);
        this.fireEvent('onStart', this.element);
        return this
    },
    stop: function (a) {
        if (!this.timer) return this;
        this.timer = $clear(this.timer);
        if (!a) this.fireEvent('onCancel', this.element);
        return this
    },
    custom: function (a, b) {
        return this.start(a, b)
    },
    clearTimer: function (a) {
        return this.stop(a)
    }
});
Fx.Base.implement(new Chain);
Fx.Base.implement(new Events);
Fx.Base.implement(new Options);
Fx.Transitions = {
    linear: function (t, b, c, d) {
        return c * t / d + b
    },
    sineInOut: function (t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
    },
    backInOut: function (t, b, c, d, s) {
        if (!s) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b
    }
};
Fx.CSS = {
    select: function (a, b) {
        if (a.test(/color/i)) return this.Color;
        if (b.test && b.test(' ')) return this.Multi;
        return this.Single
    },
    parse: function (a, b, c) {
        if (!c.push) c = [c];
        var d = c[0],
            to = c[1];
        if (!to && to != 0) {
            to = d;
            d = a.getStyle(b)
        }
        var e = this.select(b, to);
        return {
            from: e.parse(d),
            to: e.parse(to),
            css: e
        }
    }
};
Fx.CSS.Single = {
    parse: function (a) {
        return parseFloat(a)
    },
    getNow: function (a, b, c) {
        return c.compute(a, b)
    },
    getValue: function (a, b) {
        return a + b
    }
};
Fx.CSS.Multi = {
    parse: function (a) {
        return a.push ? a : a.split(' ').map(function (v) {
            return parseFloat(v)
        })
    },
    getNow: function (a, b, c) {
        var d = [];
        for (var i = 0; i < a.length; i++) d[i] = c.compute(a[i], b[i]);
        return d
    },
    getValue: function (a, b) {
        return a.join(b + ' ') + b
    }
};
Fx.CSS.Color = {
    parse: function (a) {
        return a.push ? a : a.hexToRgb(true)
    },
    getNow: function (a, b, c) {
        var d = [];
        for (var i = 0; i < a.length; i++) d[i] = Math.round(c.compute(a[i], b[i]));
        return d
    },
    getValue: function (a) {
        return 'rgb(' + a.join(',') + ')'
    }
};
Fx.Style = Fx.Base.extend({
    initialize: function (a, b, c) {
        this.element = $(a);
        this.property = b;
        this.parent(c)
    },
    hide: function () {
        return this.set(0)
    },
    setNow: function () {
        this.now = this.css.getNow(this.from, this.to, this)
    },
    set: function (a) {
        this.css = Fx.CSS.select(this.property, a);
        return this.parent(this.css.parse(a))
    },
    start: function (a, b) {
        if (this.timer && this.options.wait) return this;
        var c = Fx.CSS.parse(this.element, this.property, [a, b]);
        this.css = c.css;
        return this.parent(c.from, c.to)
    },
    increase: function () {
        this.element.setStyle(this.property, this.css.getValue(this.now, this.options.unit))
    }
});
Element.extend({
    effect: function (a, b) {
        return new Fx.Style(this, a, b)
    }
});
Fx.Styles = Fx.Base.extend({
    initialize: function (a, b) {
        this.element = $(a);
        this.parent(b)
    },
    setNow: function () {
        for (var p in this.from) this.now[p] = this.css[p].getNow(this.from[p], this.to[p], this)
    },
    set: function (a) {
        var b = {};
        this.css = {};
        for (var p in a) {
            this.css[p] = Fx.CSS.select(p, a[p]);
            b[p] = this.css[p].parse(a[p])
        }
        return this.parent(b)
    },
    start: function (a) {
        if (this.timer && this.options.wait) return this;
        this.now = {};
        this.css = {};
        var b = {},
            to = {};
        for (var p in a) {
            var c = Fx.CSS.parse(this.element, p, a[p]);
            b[p] = c.from;
            to[p] = c.to;
            this.css[p] = c.css
        }
        return this.parent(b, to)
    },
    increase: function () {
        for (var p in this.now) this.element.setStyle(p, this.css[p].getValue(this.now[p], this.options.unit))
    }
});
Element.extend({
    effects: function (a) {
        return new Fx.Styles(this, a)
    }
});
var XHR = new Class({
    getOptions: function () {
        return {
            method: 'post',
            async: true,
            onRequest: Class.empty,
            onStateChange: Class.empty,
            onSuccess: Class.empty,
            onFailure: Class.empty,
            headers: {},
            isSuccess: this.isSuccess
        }
    },
    initialize: function (a) {
        this.transport = window.XMLHttpRequest ? new XMLHttpRequest() : (window.ie ? new ActiveXObject('Microsoft.XMLHTTP') : false);
        this.setOptions(this.getOptions(), a);
        if (!this.transport) return;
        this.headers = {};
        if (this.options.initialize) this.options.initialize.call(this)
    },
    onStateChange: function () {
        this.fireEvent('onStateChange', this.transport);
        if (this.transport.readyState != 4) return;
        var a = 0;
        try {
            a = this.transport.status
        } catch (e) {}
        if (this.options.isSuccess(a)) this.onSuccess();
        else this.onFailure();
        this.transport.onreadystatechange = Class.empty
    },
    isSuccess: function (a) {
        return ((a >= 200) && (a < 300))
    },
    onSuccess: function () {
        this.response = {
            'text': this.transport.responseText,
            'xml': this.transport.responseXML
        };
        this.fireEvent('onSuccess', [this.response.text, this.response.xml]);
        this.callChain()
    },
    onFailure: function () {
        this.fireEvent('onFailure', this.transport)
    },
    setHeader: function (a, b) {
        this.headers[a] = b;
        return this
    },
    send: function (a, b) {
        this.fireEvent('onRequest');
        this.transport.open(this.options.method, a, this.options.async);
        this.transport.onreadystatechange = this.onStateChange.bind(this);
        if ((this.options.method == 'post') && this.transport.overrideMimeType) this.setHeader('Connection', 'close');
        Object.extend(this.headers, this.options.headers);
        for (var c in this.headers) this.transport.setRequestHeader(c, this.headers[c]);
        this.transport.send(b);
        return this
    }
});
XHR.implement(new Chain);
XHR.implement(new Events);
XHR.implement(new Options);
var Ajax = XHR.extend({
    moreOptions: function () {
        return {
            postBody: null,
            update: null,
            onComplete: Class.empty,
            evalScripts: false,
            evalResponse: false,
            encoding: 'utf-8'
        }
    },
    initialize: function (a, b) {
        this.addEvent('onSuccess', this.onComplete);
        this.setOptions(this.moreOptions(), b);
        this.parent(this.options);
        if (!['post', 'get'].test(this.options.method)) {
            this._method = '_method=' + this.options.method;
            this.options.method = 'post'
        }
        if (this.options.method == 'post') {
            var c = (this.options.encoding) ? '; charset=' + this.options.c : '';
            this.setHeader('Content-type', 'application/x-www-form-urlencoded' + c)
        }
        this.setHeader('X-Requested-With', 'XMLHttpRequest');
        this.setHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
        this.url = a
    },
    onComplete: function () {
        if (this.options.update) $(this.options.update).setHTML(this.response.text);
        if (this.options.evalResponse) eval(this.response.text);
        if (this.options.evalScripts) this.evalScripts.delay(30, this);
        this.fireEvent('onComplete', [this.response.text, this.response.xml], 20)
    },
    request: function () {
        var a = null;
        switch ($type(this.options.postBody)) {
        case 'element':
            a = $(this.options.postBody).toQueryString();
            break;
        case 'object':
            a = Object.toQueryString(this.options.postBody);
            break;
        case 'string':
            a = this.options.postBody
        }
        if (this._method) a = (a) ? [this._method, a].join('&') : this._method;
        return this.send(this.url, a)
    },
    evalScripts: function () {
        var a, regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
        while ((a = regexp.exec(this.response.text))) eval(a[1])
    }
});
Object.toQueryString = function (a) {
    var b = [];
    for (var c in a) b.push(encodeURIComponent(c) + '=' + encodeURIComponent(a[c]));
    return b.join('&')
};
Element.extend({
    send: function (a) {
        a = Object.extend(a || {}, {
            postBody: this.toQueryString(),
            method: 'post'
        });
        return new Ajax(this.getProperty('action'), a).request()
    },
    toObject: function () {
        var d = {};
        $$(this.getElementsByTagName('input'), this.getElementsByTagName('select'), this.getElementsByTagName('textarea')).each(function (a) {
            var b = $(a).name;
            var c = a.getValue();
            if ((c !== false) && b) d[b] = c
        });
        return d
    },
    toQueryString: function () {
        return Object.toQueryString(this.toObject())
    }
});
var Lightbox = {
    init: function (b) {
        if (document.all) AxRep();
        this.options = Object.extend({
            resizeDuration: 1000,
            resizeTransition: Fx.Transitions.backInOut,
            initialWidth: 250,
            initialHeight: 250,
            animateCaption: true
        }, b || {});
        this.anchors = [];
        $each(document.links, function (a) {
            if (a.rel && a.rel.test(/^lightbox/i)) {
                a.onclick = this.click.pass(a, this);
                this.anchors.push(a)
            }
        }, this);
        this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
        this.eventPosition = this.position.bind(this);
        this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(document.body);
        this.center = new Element('div').setProperty('id', 'lbCenter').setStyles({
            width: this.options.initialWidth + 'px',
            height: this.options.initialHeight + 'px',
            marginLeft: '-' + (this.options.initialWidth / 2) + 'px',
            display: 'none'
        }).injectInside(document.body);
        this.image = new Element('div').setProperty('id', 'lbImage').injectInside(this.center);
        this.prevLink = new Element('a').setProperties({
            id: 'lbPrevLink',
            href: '#'
        }).setStyle('display', 'none').injectInside(this.image);
        this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLink').injectInside(this.image);
        this.prevLink.onclick = this.previous.bind(this);
        this.nextLink.onclick = this.next.bind(this);
        this.fullscreen = false;
        this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainer').setStyle('display', 'none').injectInside(document.body);
        this.bottom = new Element('div').setProperty('id', 'lbBottom').injectInside(this.bottomContainer);
        new Element('a').setProperties({
            id: 'lbCloseLink',
            href: '#'
        }).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
        this.caption = new Element('div').setProperty('id', 'lbCaption').injectInside(this.bottom);
        this.number = new Element('div').setProperty('id', 'lbNumber').injectInside(this.bottom);
        new Element('div').setStyle('clear', 'both').injectInside(this.bottom);
        var c = this.nextEffect.bind(this);
        this.fx = {
            overlay: this.overlay.effect('opacity', {
                duration: 500
            }).hide(),
            resize: this.center.effects({
                duration: this.options.resizeDuration,
                transition: this.options.resizeTransition,
                onComplete: c
            }),
            image: this.image.effect('opacity', {
                duration: 500,
                onComplete: c
            }),
            bottom: this.bottom.effect('margin-top', {
                duration: 400,
                onComplete: c
            })
        };
        this.preloadPrev = new Image();
        this.preloadNext = new Image()
    },
    click: function (b) {
        if (b.rel.length == 8) return this.show(b.href, b.title);
        var j, imageNum, images = [];
        this.anchors.each(function (a) {
            if (a.rel == b.rel) {
                for (j = 0; j < images.length; j++) if (images[j][0] == a.href) break;
                if (j == images.length) {
                    images.push([a.href, a.title]);
                    if (a.href == b.href) imageNum = j
                }
            }
        }, this);
        return this.open(images, imageNum)
    },
    show: function (a, b) {
        return this.open([
            [a, b]
        ], 0)
    },
    open: function (a, b) {
        this.images = a;
        this.position();
        this.setup(true);
        this.top = (document.body.offsetHeight / 15);
        this.center.setStyles({
            top: this.top + 'px',
            display: ''
        });
        this.fx.overlay.start(0.8);
        return this.changeImage(b)
    },
    position: function () {
        this.overlay.setStyles({
            top: '0px'
        })
    },
    setup: function (b) {
        var c = $A(document.getElementsByTagName('object'));
        if (window.ie) c.extend(document.getElementsByTagName('select'));
        c.each(function (a) {
            a.style.visibility = b ? 'hidden' : ''
        });
        var d = b ? 'addEvent' : 'removeEvent';
        window[d]('scroll', this.eventPosition)[d]('resize', this.eventPosition);
        document[d]('keydown', this.eventKeyDown);
        this.step = 0
    },
    keyboardListener: function (a) {
        switch (a.keyCode) {
        case 27:
        case 88:
        case 67:
            this.close();
            break;
        case 37:
        case 80:
            this.previous();
            break;
        case 39:
        case 78:
            this.next()
        }
    },
    previous: function () {
        return this.changeImage(this.activeImage - 1)
    },
    next: function () {
        return this.changeImage(this.activeImage + 1)
    },
    changeImage: function (a) {
        if (this.step || (a < 0) || (a >= this.images.length)) return false;
        this.step = 1;
        this.activeImage = a;
        this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
        this.fx.image.hide();
        this.center.className = 'lbLoading';
        this.preload = new Image();
        this.preload.onload = this.nextEffect.bind(this);
        this.preload.src = this.images[a][0];
        return false
    },
    nextEffect: function () {
        switch (this.step++) {
        case 1:
            this.fWidth = (0.9 * document.body.offsetWidth);
            this.fHeight = (0.8 * document.body.offsetHeight);
            this.center.className = '';
            this.image.style.backgroundImage = 'url(' + this.images[this.activeImage][0] + ')';
            this.image.style.backgroundPosition = 'center';
            if (this.preload.width > this.fWidth || this.preload.height > this.fHeight) {
                if (this.preload.width != this.preload.height) {
                    this.image.style.width = this.bottom.style.width = Math.floor(this.preload.width * this.fHeight / this.preload.height) + 'px';
                    this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.fHeight + 'px'
                } else {
                    this.image.style.width = this.bottom.style.width = this.fWidth + 'px';
                    this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.fHeight + 'px'
                }
                this.fullscreen = true
            } else {
                this.image.style.width = this.bottom.style.width = this.preload.width + 'px';
                this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height + 'px'
            }
            this.caption.setHTML(this.images[this.activeImage][1] || '');
            this.number.setHTML((this.images.length == 1) ? '' : 'Image ' + (this.activeImage + 1) + ' of ' + this.images.length);
            if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage - 1][0];
            if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage + 1][0];
            if (this.center.clientHeight != this.image.offsetHeight) {
                this.fx.resize.start({
                    height: this.image.offsetHeight
                });
                break
            }
            this.step++;
        case 2:
            if (this.center.clientWidth != this.image.offsetWidth) {
                this.fx.resize.start({
                    width: this.image.offsetWidth,
                    marginLeft: -(this.image.offsetWidth / 2)
                });
                break
            }
            this.step++;
        case 3:
            this.bottomContainer.setStyles({
                top: (this.top + this.center.clientHeight) + 'px',
                height: '0px',
                marginLeft: this.center.style.marginLeft,
                display: 'none'
            });
            this.fx.image.start(1);
            break;
        case 4:
            if (this.options.animateCaption) {
                this.bottomContainer.style.display = '';
                this.fx.bottom.set(-this.bottom.offsetHeight);
                this.bottomContainer.style.height = '';
                this.fx.bottom.start(0);
                break
            }
            this.bottomContainer.style.height = '';
        case 5:
            if (this.activeImage) this.prevLink.style.display = '';
            if (this.activeImage != (this.images.length - 1)) this.nextLink.style.display = '';
            this.step = 0
        }
    },
    close: function () {
        if (this.step < 0) return;
        this.step = -1;
        if (this.preload) {
            this.preload.onload = Class.empty;
            this.preload = null
        }
        for (var f in this.fx) this.fx[f].stop();
        this.center.style.display = this.bottomContainer.style.display = 'none';
        this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
        return false
    }
};
window.addEvent('domready', Lightbox.init.bind(Lightbox));

function Go(a, b, c) {
    document.title = ('Tanalahy - ' + c);
    new Element('img').setProperties({
        id: 'loading',
        src: '/img/loading.gif',
        width: '32px',
        height: '32px'
    }).setStyles({
        left: ($('container').getSize().size.x / 2 - 16) + 'px',
        top: ($('container').getSize().size.y / 2 - 16) + 'px'
    }).injectInside('container');
    new Fx.Style('alpha', 'opacity').start(1, 0).chain(function () {
        new Fx.Style('loading', 'opacity', {
            duration: 200
        }).start(0, 1);
        new Ajax('./alink.php', {
            postBody: 'data=' + a + '&type=' + b + '&nocache=' + (new Date()).getTime(),
            onComplete: Open,
            update: 'alpha',
            method: 'post'
        }).request()
    })
}
function Open() {
    new Fx.Style('loading', 'opacity', {
        duration: 200
    }).start(1, 0).chain(function () {
        Lightbox.anchors = [];
        $A(document.links).each(function (a) {
            if (a.rel && a.rel.test('^lightbox', 'i')) {
                a.onclick = this.click.pass(a, this);
                this.anchors.push(a)
            }
        }, Lightbox);
        new Fx.Style('alpha', 'opacity').start(0, 1);
        $('loading').remove()
    })
}
function GoGoogle() {
    new Element('img').setProperties({
        id: 'loading',
        src: '/img/loading.gif',
        width: '32px',
        height: '32px'
    }).setStyles({
        left: ($('container').getSize().size.x / 2 - 16) + 'px',
        top: ($('container').getSize().size.y / 2 - 16) + 'px'
    }).injectInside('container');
    new Fx.Style('alpha', 'opacity').start(1, 0).chain(function () {
        new Fx.Style('loading', 'opacity', {
            duration: 200
        }).start(0, 1);
        this.searcher = new GwebSearch();
        this.searcher.setResultSetSize(GSearch.LARGE_RESULTSET);
        this.searcher.setSiteRestriction("http://site.tanalahy.com/");
        this.searcher.setNoHtmlGeneration();
        this.searcher.setSearchCompleteCallback(this, GetGoogle);
        this.searcher.execute($('search').value)
    })
}
function GetGoogle() {
    this.Gresults = this.searcher.results;
    $('alpha').setHTML('');
    for (i = 0; i < this.Gresults.length; i++) {
        if ((i % 2) == 0) {
            this.leselect = new Element('div').setProperty('class', 'gresult').setStyle('background', '#E2ECA3').injectInside('alpha');
            this.num = new Element('div').setProperty('class', 'gnum').setStyle('color', '#F5F6F0').injectInside(this.leselect)
        } else {
            this.leselect = new Element('div').setProperty('class', 'gresult').injectInside('alpha');
            this.num = new Element('div').setProperty('class', 'gnum').injectInside(this.leselect)
        }
        this.num.setHTML([i + 1]);
        this.titleTemp = this.Gresults[i].title.replace(/Tanalahy -/, '');
        this.title = new Element('div').setProperty('class', 'gtitle').injectInside(this.leselect);
        this.LINK = new Element('a').setProperties({
            href: this.Gresults[i].unescapedUrl,
            target: '_blank'
        }).injectInside(this.title);
        this.LINK.setHTML(this.titleTemp);
        this.desc = new Element('div').injectInside(this.leselect);
        this.desc.setHTML(this.Gresults[i].content)
    }
    new Fx.Style('loading', 'opacity', {
        duration: 200
    }).start(1, 0).chain(function () {
        new Fx.Style('alpha', 'opacity').start(0, 1);
        $('loading').remove()
    })
}
