/**
 * page.js
 *
 */


var page;
var Page = Class.create();


var PageOptions = Object.extend({
}, window.PageOptions || {});


Page.prototype = {
    change_wrapper_bg: function () {
        // Change the background
        now = new Date();
        //now_ms = now.getTime();
        now_ms = now.getTime() / (1000 * 60 * 3 * 1);
        now_bg = parseInt(now_ms) % 5;
        if (now_bg == 0) {
            now_bg = 5;
        }
        //this.wrapper.style.background = 'url(images/bg/' + now_bg + ') repeat-x'
        this.wrapper.style.backgroundImage = 'url(images/bg/' + now_bg + '.jpg)';
        this.wrapper.style.backgroundRepeat = 'no-repeat';
        this.wrapper.style.backgroundPosition = 'top center';
    },
    initialize: function () {
        // Initialize attributes
        this.top_menu = $('top_menu');
        this.wrapper = $('wrapper');
        this.start();
    },
    reformat_top_menu: function() {
        var ul = this.top_menu.getElementsBySelector('ul')[0];
        if (! ul) {
            return;
        }
        ul.hide();
        var ancs= this.top_menu.getElementsBySelector('a');
        var ancsLen = ancs.length;
        for (var cnt=0; cnt<ancsLen; ++cnt) {
            var anc = ancs[cnt];
            var span = new Element('span');
            span.addClassName('top_menu_link');
            span.update(anc);
            if ( cnt > 0 ) {
                new Insertion.Bottom(this.top_menu, ' | ');
                //new Insertion.Bottom(span, ' | ');
            }
            new Insertion.Bottom(span, '\n');
            new Insertion.Bottom(this.top_menu, span);
        }
        //ul.remove();
        //this.top_menu.replace(/<span class="top_menu_link"><\/span> | \/g, '');
    },
    start: function () {
        // Start stuff
        this.change_wrapper_bg();
        this.reformat_top_menu();
    }
}


//document.observe('dom:loaded', function () {
    //page = new Page();
//});

