/**
* @author avrameisner
*/

var DCoverlay = Class.create({
	initialize: function(options) {
		// set the default options
		this.options = $H({
			id: 'dc_overlay',
			color: '#000',
			opacity: 0.85,
			hideOnClick: true,
			hideOtherElement: null,
			template: "<div id='#{id}' style='background-color:#{color}; opacity:#{opacity}; display:none;'></div>"
		})
	
		// merge custom options with default options
		this.options.update(options);
		
		// convert the hash to JSON
		this.options = this.options.toObject();
		
		this.template = new Template(this.options.template);
	},
	
	add: function() {
		var overlayHTML = this.template.evaluate({id:this.options.id, color:this.options.color, opacity:this.options.opacity});
		
		$$("body")[0].insert({bottom: overlayHTML});
	
		this.overlay = $(this.options.id);
	
		if (this.options.hideOnClick) {
			this.overlay.observe("click", this.hide.bindAsEventListener(this));
		}
	},
	
	show: function() {
		this.overlay.show();
	},
	
	hide: function() {
		this.overlay.hide();
		if (this.options.hideOtherElement) {
			this.options.hideOtherElement.remove();
		}
	}
});
 
 
/**
 * @author avrameisner
 */
var DCoverlayAnimated = Class.create(DCoverlay, {
	show: function() {
		this.overlay.appear({
			duration: 0.5
		});
	},
	
	hide: function() {
		if (this.options.hideOtherElement) {
			this.options.hideOtherElement.remove();
		} else {		
			this.overlay.fade({
				duration: 0.5
			});
		}
	}
});