/*jquery.indicator.js
*
* Copyright 2010 Padilla Technology Solutions. All rights reserved.
*
*/

(function($){
	//create class to use this plug-in as OO
	var Indicator = function(container, options){
		var _self = this;
		var image = null;
		//set up the options first in the settings then use opts to set up any meta tags if included
		var settings = $.extend({}, $.fn.indicator.defaults, options);
		var opts = $.meta ? $.extend({}, settings, self.data()) : settings;
		
		/*@function init
		*	sets up the object
		* 
		* @params none
		*
		* @return void
		*/
		function init(){
			//create the map and enable some default vars
			container = $(container);//make sure we have a jquery object
			image = $(document.createElement('img')).css('z-index',100002);
			image.attr('src', opts.imgSource);
		}
		
		/*@function start
		*	shows the indicator image in the view
		* 
		* @params none
		*
		* @return void
		*/

		_self.start = function(){
			//show the image in the center of our container
			var div = $(document.createElement('div'));
			div.append(image);
			div.css({'background':'#666', 'padding':'10px'});
			div.addClass('ui-corner-all');
			var left = container.position().left + ((container.width() + div.width())/2);
			var top = container.position().top + ((container.height() + div.height())/2);
			
			container.parent().append(div);
			div.css({'position':'absolute','top':top, 'left':left});
		}

		/*@function stop
		*	removes the indicator image from the view
		* 
		* @params none
		*
		* @return void
		*/

		_self.stop = function(){
			image.parent().remove();
		}
		
		
		init();
	}
	//create the actual jquery plugin
	$.fn.indicator = function(options){
		
		return this.each(function(){
				var _self = $(this);
				//if element is already an instance of this plug-in, return 
				if(_self.data('indicator')) return;
				
				var ind = new Indicator(this, options);
				
				/*********************************************************
				THIS IS WHAT YOU NEED TO USE TO GET HOLD OF THE OBJECT!!!!
								var myvar = $('myaccessor').data('indicator')
				**********************************************************/
				//store plug-in object in this element's data ;;; 
				_self.data('indicator', ind);
		});//end this.each
	};

	$.fn.indicator.defaults = {showBox:false, imgSource:"images/ajax_loader_wht_trans.gif"};
})(jQuery);

