window.addEvent('domready',function(){
    if(Browser.Engine.trident){
        $$('.nav ul li').addEvent('mouseenter',function(){
            this.set('class','over');
        });
        $$('.nav ul li').addEvent('mouseleave',function(){
            this.removeClass('over');
        });
    }
});

// au 1.0.js

Element.Events.show = {   
    condition: function(event) {
        return event.alt;
    }
};

var au = au || {};
au.Tabs = new Class({
    Implements: [Options,Events],
    options: {activeIndex: 0, activeClass: 'actTab'},
    initialize: function(containerId, tabClass, tabContentClass, closeBtnClass, options) {
        this.setOptions(options);        
        this.containerId = $(containerId);
        this.closeBtnClass = $$('#' + containerId + ' div' + closeBtnClass);
        this.tabContentClass = tabContentClass;
        this.tabs = $$('#' + containerId + ' div' + tabClass);
        this.tabContents = $$('#' + containerId + ' div' + tabContentClass);
        this.activeTabIndex = this.options.activeIndex;

        return this;
    },
    onActivate: function() {

    },
    attach: function() {
        this.tabs[this.options.activeIndex].addClass(this.options.activeClass);
        this.tabContents.setStyle('display', 'none');
        this.tabContents[this.options.activeIndex].setStyle('display', 'block');
        this.loadContent(this.tabContents[this.options.activeIndex]);
        this.tabContents[this.options.activeIndex].loaded = true;

        this.addEvent('show', function() {
            this.loadContent(this.tabContents[this.options.activeIndex]);
            this.tabContents[this.options.activeIndex].loaded = true;
        });

        this.tabs.each(function(el, i) {
            el.addEvent('click', function() {
                this.tabs.removeClass(this.options.activeClass);
                this.tabs[i].addClass(this.options.activeClass);
                this.tabContents.setStyle('display', 'none');
                this.tabContents[i].setStyle('display', 'block');
                if (!this.tabContents[i].loaded) {
                    this.loadContent(this.tabContents[i]);
                    this.tabContents[i].loaded = true;
                }
                this.activeTabIndex = i;
                this.fireEvent("onActivate", i);
            }.bind(this));
        }.bind(this));
    },
    loadContent: function(tabContent) {
        var contentUrl = tabContent.get('content-url');
        if (contentUrl) {
            var request = new Request.HTML({url: contentUrl, method: 'get', update: tabContent, headers:{'SpecialAjaxRequest':'true'},
                onRequest: function() { tabContent.innerHTML = "<center><img src='/_img/loading.gif'></center>"; },
                onComplete: function() {
                    $$('.errmsg').addEvent('mouseover', function(ev){
                        var div = this.getElement('div');
                        if (div) {
                            var txt = div.get('html');
                            $('newAlert').set('html', txt);
                            var mouseX = ev.page.x;
                            var mouseY = ev.page.y;
                            $('newAlert').setStyle('display','block');
                            $('newAlert').setStyles({'left':mouseX,'top':mouseY});
                        }
                    });
                    $$('.errmsg').addEvent('mouseleave', function(){
                        $('newAlert').setStyle('display','none');
                    });
                    $$('.errmsg-pass').addEvent('mouseover', function(ev){
                        var div = this.getElement('div');
                        if (div) {
                            var txt = div.get('html');
                            $('newAlert').set('html', txt);
                            var mouseX = ev.page.x;
                            var mouseY = ev.page.y;
                            $('newAlert').setStyle('display','block');
                            $('newAlert').setStyles({'left':mouseX,'top':mouseY});
                        }
                    });
                    $$('.errmsg-pass').addEvent('mouseleave', function(){
                        $('newAlert').setStyle('display','none');
                    });
                }
            });
            request.send();
        }
    }
});

au.Popup = new Class({
    Implements: [Options,Events],
    initialize: function(tabs, containerId, actBtnClass, closeBtnClass, options) {
        this.setOptions(options);
        this.tabs = tabs;
        this.containerId = $(containerId);
        this.actBtnClass = $$(actBtnClass);
        this.closeBtnClass = $$('#' + containerId + ' div' + closeBtnClass);
        return this;
    },
    attach: function() {
        this.actBtnClass.addEvent('click', function() {            
            if (this.tabs) this.tabs.fireEvent('show');
            this.containerId.setStyle('display', 'block');

            var a = getScrollTop();
            this.containerId.setStyle('marginTop', a + 'px');
            this.containerId.setStyle('max-height', document.getElementById('holder').offsetHeight + 'px');
            this.containerId.setStyle('overflow', 'auto');

            this.containerId.set('morph', {duration: 'short', transition: 'sine:in'});
            this.containerId.morph({'opacity': 1});
        }.bind(this));
        this.closeBtnClass.addEvent('click', function() {
            this.close();
        }.bind(this));
        document.addEvent('keydown', function(event) {
            if (event.key=='esc') {
                this.close();
            }
        }.bind(this));
    },
    close: function () {
        this.onclose();
        var containerId = this.containerId;
        this.containerId.set('morph', {duration: 'short', transition: 'sine:out',
            onComplete: function () {
                containerId.setStyle('display', 'none');
            }
        });
        this.containerId.morph({'opacity': 0});
    },
    onclose: function() {}
});
window.addEvent('domready',function(){
    $$('.errmsg').addEvent('mouseover', function(ev){
        var div = this.getElement('div');
        if (div) {
            var txt = div.get('html');
            $('newAlert').set('html', txt);
            var mouseX = ev.page.x;
            var mouseY = ev.page.y;
            $('newAlert').setStyle('display','block');
            $('newAlert').setStyles({'left':mouseX,'top':mouseY});
        }
    });
    $$('.errmsg').addEvent('mouseleave', function(){
        $('newAlert').setStyle('display','none');
    });
    $$('.errmsg-pass').addEvent('mouseover', function(ev){
        var div = this.getElement('div');
        if (div) {
            var txt = div.get('html');
            $('newAlert').set('html', txt);
            var mouseX = ev.page.x;
            var mouseY = ev.page.y;
            $('newAlert').setStyle('display','block');
            $('newAlert').setStyles({'left':mouseX,'top':mouseY});
        }
    });
    $$('.errmsg-pass').addEvent('mouseleave', function(){
        $('newAlert').setStyle('display','none');
    });
});
