/**
*	@package		My Own Art
*	@subpackage		Javascript
*	@author			Ben Sekulowicz-Barclay
*	@copyright		Copyright 2008, Outside Line.
*	@version		1.00
*
************************************************************************************************************************ **/

var moa_select = Class.create({	
	
	initialize: function() {
		
		document.observe('dom:loaded', function(e) {
			
			$$('div#roomCreate div.content div.section ul.listArtwork li form button').each(function(b) {				
				b.observe('click', this.onClickButton.bindAsEventListener(this));
				b.onclick = function() { return false; }								
			}.bind(this));
			
		}.bindAsEventListener(this));
	},
	
	/* ****************************************************************************************************************** */
	
	onClickButton: function(e) {
		b = Event.findElement(e, 'button');		
		v = b.up().down('input[type=hidden]').value;
		
		// If we are removing a piece of artwork ...
		if (b.hasClassName('remove')) {
			new Ajax.Request(site_url + 'create-a-room/', {
				method: 'post',
				parameters: { removeHtml: v },
				onSuccess: function(result) {
					b.removeClassName('remove').addClassName('select');									
				}.bind(this)
			});
			
		// If we are selecting a piece of artwork ...
		} else {
			new Ajax.Request(site_url + 'create-a-room/', {
				method: 'post',
				parameters: { selectHtml: v },
				onSuccess: function(result) {
					b.removeClassName('select').addClassName('remove');
				}.bind(this)
			});
		}		
	}
	
	/* ****************************************************************************************************************** */	
});