var Background = new Class({
    Implements:  [Events],
    start: function(){
        this.debugMode = false;
        this.enableAlert = false;
        this.bgWidth = 0;
        this.bgHeight = 0;
        this.randomBg = ["bg1-","bg2-","bg8-","bg9-","bg8-","bg9-","bg8-","bg9-","bg5-"];

        try{
            console.log('Starting Background Manager');
            this.debugMode = true;
        }catch(e){}

        this.bgImage = this.randomBg.getRandom();


        this.update();
    },

    setBackgroundSize: function (){
	if(!window.innerWidth)
	{
            if(!(document.documentElement.clientWidth == 0)){
                this.bgWidth = document.documentElement.clientWidth;
                this.bgHeight = document.documentElement.clientHeight;
            }else{
                this.bgWidth = document.body.clientWidth;
                this.bgHeight = document.body.clientHeight;
            }
	}else{
            this.bgWidth = window.innerWidth;
            this.bgHeight = window.innerHeight;
	}

        this.log(this.bgWidth+" "+this.bgHeight);
    },

    update: function(){
            this.setBackgroundSize();
            var fmt = this.bgHeight;
            try{
                console.log(fmt);
            }catch(e){
                
            }
            var bodytag = this.bgImage;
            bodytag += (fmt<=800)?'size-5':
                (fmt>801&&fmt<=900)?'size-5':
                (fmt>901&&fmt<=1000)?'size-6':
                (fmt>1001&&fmt<=1100)?'size-7':'size-8';
            document.body.className = bodytag
            this.log(bodytag);
    },

    log: function(message){
        if(this.debugMode){
            console.log(message);
        }else if(this.enableAlert){
            alert(message);
        }
    }
});
BgManager = new Background();
window.onload = function(){
    BgManager.start();
};
window.onresize = function(){
    BgManager.update();
};