if(window['console'] === undefined) window.console = {
    log: function(){}
};

var Custom = Class.create({
    initialize: function() {
        this.currentmenu = [];
        this.oldvals = {};

        Cufon.replace([
            '.news a',
            '.content h1',
            '.content h2',
            '.content h3',
            'legend'
        ], {
            hover: true
        });

        if ($('navigation')) this.dropdown();
        if ($('guestbook-form')) $('guestbook-form').setAttribute('action', window.document.URL);
        $$('input', 'textarea').each(this.elementFocus.bind(this));
    },
    dropdown: function() {
        $$('.navigation ul li').each(function(el){
            el.observe('mouseover', this.showmenu.bind(this));
            el.observe('mouseout', this.showmenu.bind(this));
        }.bind(this));
    },
    showmenu: function(e) {
        e.stop();
        if (this.currentmenu.length < 1) $$('li.current').each(this.holdmenu.bind(this));

        if (e.type == 'mouseover') {
            $$('li.current').each(function(el){
                el.className = '';
            })
        } else {
            this.showpreviousmenu();
        }
    },
    holdmenu: function(el) {
        this.currentmenu.push(el);
    },
    showpreviousmenu: function() {
        this.currentmenu.each(function(el){
            el.className = 'current';
        })
    },
    elementFocus: function(el) {
        if (el.type == 'text' || el.tagName.toLowerCase() == 'textarea') {

            this.oldvals[el.id] = (el.tagName.toLowerCase() == 'input') ? el.value : el.innerHTML;

            el.observe('focus', function(e) {
                el = e.target;
                if (el.tagName.toLowerCase() == 'input' && el.value == this.oldvals[el.id]) {
                    el.value = '';
                } else if (el.tagName.toLowerCase() == 'textarea' && el.innerHTML == this.oldvals[el.id]) {
                    el.innerHTML = '';
                }
            }.bind(this));

            el.observe('blur', function(e){
                el = e.target;
                if (el.tagName.toLowerCase() == 'input' && el.value == '') {
                    el.value = this.oldvals[el.id];
                } else if (el.tagName.toLowerCase() == 'textarea' && el.innerHTML == '') {
                    el. innerHTML = this.oldvals[el.id];
                }
            }.bind(this));
        }
    }
});

document.observe('dom:loaded', function(){
    new Custom();
});
