try{jQuery.noConflict();}catch(Exception){}

window.addEvent('domready', function(){
	try{
            var img = $$('#bodybg')[0].getElement('img');
            var background = $$('#background')[0];
            if(img && background){
                    var bheight = background.getCoordinates().height;
                    $$(img, '#bodybg').setStyles({
                            'display': 'block',
                            'height': bheight+'px'
                    });
                    var imgMove = function(){
                            var wwidth = window.getCoordinates().width;
                            var bwidth = background.getCoordinates().width;
                            var iwidth = img.getCoordinates().width;
                            if(wwidth > bwidth){
                                    bwidth = wwidth;
                            }
                            if(iwidth > bwidth){
                                    var right = ((iwidth-bwidth)/2);
                                    img.setStyle('margin-right', '-'+right+'px');
                            }else{
                                    img.setStyles({
                                            'height': '',
                                            'width': '100%'
                                    });
                            }
                    };
                    imgMove();
                    window.addEvent('resize', imgMove);

                    /* 
                     *	To make sure that all content are loaded 
                     *	because of facebook content that loads later
                     */
                    var iteration = 10;
                    var period = (function(){
                            if(iteration < 0){
                                    $clear(period);
                            }else{
                                    var nbheight = background.getCoordinates().height;
                                    if(nbheight != bheight){
                                            $$(img, '#bodybg').setStyle('height', nbheight+'px');
                                            imgMove();
                                            bheight = nbheight;
                                    }
                            }
                            iteration--;
                    }).periodical(1000);
            }
        }catch(Exception){}
});
