var Background = Class.create({

	initialize: function(file, width, height)
	{
		this.background = {};
		this.background.target = $('background');
		this.background.target.innerHTML = '<img src="./images/'+file+'" alt="" />';
		this.background.width = this.background.target.getWidth();
		this.background.height = this.background.target.getHeight();
		
		this.image = {};
		this.image.target = $$('div#background img')[0];
		this.image.width = width;
		this.image.height = height;
		
		window.onresize = this.resize.bind(this);
		this.redraw();
	},
	
	resize: function()
	{
		this.background.width = this.background.target.getWidth();
		this.background.height = this.background.target.getHeight();
		this.redraw();
	},
	
	redraw: function()
	{
		var ratio  = Math.max(this.background.width / this.image.width, this.background.height / this.image.height);
		var width  = Math.ceil(ratio * this.image.width);
		var height = Math.ceil(ratio * this.image.height);
		var left   = -Math.round(.5 * (width - this.background.width));
		var top    = -Math.round(.5 * (height - this.background.height));
		
		
		this.image.target.writeAttribute('width', width);
		this.image.target.writeAttribute('height', height);
		this.image.target.style.left = left + 'px';
		this.image.target.style.top = top + 'px';

	}
});