/*
# class backgroundswap
#swaps page background image
*/
var backgroundswap = {
	/*
	# string path
	# contains relative path
	*/
	path : '',
	/*
	# array backgrounds
	# contains file name for each image
	*/
	backgrounds : [],
	/*
	# bool currentIndex
	# int current array index
	*/
	currentIndex : 0,
	/*
	# method bool apply()
	# apply indexed background image on user request
	*/
	apply : function(index){
		/*
		# if the index is not the current index
		# replace the background image and set
		# current index
		*/
		if(this.currentIndex!==index){
			document.body.style.background = 'url('+this.path+this.backgrounds[index]+')';
			this.currentIndex=index;
			this.update(index);
			return true;
		}
		return false;
	},
	
	/*
	# method bool apply()
	# apply indexed background image on init
	*/
	init : function(){
		document.body.style.background = 'url('+this.path+this.backgrounds[this.currentIndex]+')';
		return true;
	},
	
	/*
	# method bool send(array paramName, array domCompleteForm)
	# send form using ajax request
	*/
	update : function(index){
		var strPostfields = 'wrapper=1&index='+index;
		new Ajax.Request('/session/ajax-bg-update/'+index,{
			onFailure: function(){
				alert('session could not be updated');
			}
		});
	}
}