/*
	Information for People
	Natural Touch Marketing
	
	
*/


/*
 * spinner class
 *
 * usage:
 *  	new spinner();				// add div to page with spinner
 *   	$('ifpSpinner').show();		// show div
 * 	 	$('ifpSpinner').hide();		// hide div
 */
Spinner = new Class({

	Implements: [Options,StyleWriter],
	
	// handle to the div element that we create
	divElement: null,
	css: '.ifpSpinnerClass {'+
					'display: block;'+
					'position: absolute;'+
					'top: 0;'+
					'left: 0;'+
					'width: 200px;'+
					'height: 200px;'+
					'z-index: 10000;'+
					'border: 0px solid #0C0;'+
					'padding: 0px;'+
					'visibility: hidden;'+
					'filter: alpha(opacity=80);'+
					'opacity: 0.8;'+
					'background-color: #0C0;'+
					'background-image: url(/themes/ntm/spinner/spinner.gif);'+
					'background-position: center center;'+
					'background-repeat: no-repeat; }',
	
	// default values if the css style .ifpSpinner is not found
	options: {	id: 'ifpSpinner',
				classname: 'ifpSpinnerClass',
				html: ''},
				
	initialize: function(options)
	{
		this.setOptions(options);
		
		// create spinner div
		var spinner = new Element('div', {'id': 'ifpSpinner', 'class': this.options.classname});
		
		// override the css class with the passed options
		spinner.setStyles(this.options);
		
		// add the html to the div
		spinner.set('html',this.options.html); 
		// inject the spinner div at the end of the body
		spinner.inject(document.body);
		
		this.divElement = $(this.options.id);
		
		// does the css exist?
		//  I don't know how to check to see if the style has been defined
		if ((this.divElement).getStyle('background-color') == '') 
		{
			this.createStyle(this.options.css);	// create the class
		}
	},
	show: function () 
	{
		if (self.divElement != null) {
			var spinner = self.divElement;
		} else {
			var spinner = $(this.options.id);
		}
		spinnerSize = spinner.getSize();
		spinner.setStyle('left', window.getScrollLeft()+(window.getWidth()-spinnerSize.x)/2);
		spinner.setStyle('top', window.getScrollTop()+(window.getHeight()-spinnerSize.y)/2);
		spinner.setStyle('visibility','visible');
	},
	hide: function () 
	{
		if (self.divElement != null) {
			var spinner = self.divElement;
		} else {
			var spinner = $(this.options.id);
		}
		spinner.setStyle('visibility','hidden');
	}
});
