function BackgroundImageResizer (o) {
	
	var debug = new Debugger();
	
	this.Resize = function () {
		
		var ws=getWinSize(),
			bi=o.getElementsByTagName('img')[0],
			is=getObjSize(bi),
			center = false,
			iw,ih,r;
		
		o.style.position='fixed';
		o.style.top='0px';
		o.style.left='0px';
		o.style.zIndex='-1';
		o.style.overflow='hidden';
		o.style.width=ws.width+'px';
		o.style.height=ws.height+'px';
		
		//**********************************************************************************************
		
        if (ws.width > ws.height) {
            if (is.width > is.height) {
                r = is.width/is.height;
                iw = ws.width;
                ih = Math.round(ws.width * (1/r));

                if(ih < ws.height) {
                    r = is.height/is.width;
                    iw = Math.round(ws.height * (1/r));
                    ih = ws.height;
                }
            } else {
                r = is.height/is.width;
                iw = Math.round(ws.height * (1/r));
                ih = ws.height;
            }
        } else {
            r = is.height/is.width;
            iw = Math.round(ws.height * (1/r));
            ih = ws.height;
        }
        
        bi.style.width = iw+'px';
        bi.style.height = ih+'px';
        
	        /*
        if (center) {
            bi.style.position = 'relative';
        
            if (parseInt(bi.style.width) > parseInt(o.width)) {
                var wDiff = (parseInt(bi.style.width) - parseInt(o.width)) / 2;
                bi.style.left = '-'+wDiff+'px';
            }
        }
        */
        
        //**********************************************************************************************	
	}
	
	var self = this;
	
	function init () {
		if (o.className == 'bgNoJs') o.className = '';
		self.Resize();
		window.onresize=function(){self.Resize();};
		
	}
	function getWinSize () {
		var w,h;
		if (window.innerWidth) {
			w = window.innerWidth;
			h = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientWidth) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		} else if (document.body) {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		return {
			width:parseInt(w),
			height:parseInt(h)
		};
	}
	function getObjSize (o) {
		return(o)?{'width':parseInt(o.offsetWidth),'height':parseInt(o.offsetHeight)}:null;
	}
	
	init();
}

