var WMBackgroundImage = Class.create();

/**
 * WMBackgroundImage is the javascript class for backgroundimage in connectholland
 *
 *
 * @since Mon Apr 21 2008
 * @author Vanja de Keizer (vanja@connectholland.nl)
 **/
WMBackgroundImage.prototype = {
	/**
	 * initialize
	 *
	 * Initialize a new WMBackgroundImage
	 *
	 * @since Mon Apr 21 2008
	 * @access public
	 * @param integer backgroundimage
	 * @return void
	 **/
	initialize: function(backgroundimage) {
		this.backgroundimage = backgroundimage;
		this.opacity = 0;
		this.timeout = 1000;
		Event.observe(window, "resize", this.resizeImage.bindAsEventListener(this), false);
	},

	/**
	 * resizeImage
	 *
	 * Resize the backgroudimage
	 *
	 * @since Mon Apr 21 2008
	 * @access public
	 * @return void
	 **/
	resizeImage: function() {
		Element.extend(document.body);
		var viewport = document.viewport.getDimensions();
		var height = (viewport.height - (viewport.height % 25) ) + 25 + 120;
		var width = (viewport.width - (viewport.width % 25) ) + 25;
		var image = new Image();
		Event.observe(image, "load", this.setBackgroundImage.bindAsEventListener(this, image) );
		image.src = this.backgroundimage + "_" + width + "_" + height + ".jpg";
	},

	/**
	 * setBackgroundImage
	 *
	 * Sets the background image
	 *
	 * @since Mon Apr 21 2008
	 * @access public
	 * @param integer event
	 * @param integer image
	 * @return void
	 **/
	setBackgroundImage: function(event, image) {
		document.body.setStyle({background: "url(" + image.src + ")" + ' fixed'});
	}
};

