$.fn.hyhExpose = function(a_options) {
	function removePx (item) {
		return parseInt(item.substr(0, item.indexOf('px')));
	}
	if ($(this).length > 1) {
		$(this).each(function(){$(this).hyhExpose(a_options)});
		return;
	}

	var options = {
		color: '#000',
		opacity: '0.8',
		beforeShow: null,
		afterShow: null,
		beforeClose: null,
		afterClose: null,
		fadeSpeed: 400,
		closeOnClick: true
		};
	for (k in a_options) {
		options[k] = a_options[k];
	}

	var API = $(this).data('hyhExposeApi');
	if (API == undefined) {
		API = { element: $(this), options: options, bg:null, baseZIndex:null, basePosition:null, isExposed:false };

		API.closeExpose = function() {
			var API = this;
			if (API.options.beforeClose) {
				API.options.beforeClose(API);
			}
			this.bg.fadeOut(this.options.fadeSpeed, function(){
				API.bg.remove();
				API.element.css('zIndex', this.baseZIndex);
				API.element.css('position', this.basePosition);
				API.isExposed = false;
				if (API.options.afterClose) {
					API.options.afterClose(API);
				}

			});
		}

		API.expose = function() {
			if (this.isExposed) return;
			this.isExposed = true;
			this.bg = $(document.createElement('div'));
			this.bg.css({background:this.options.color, position:'fixed', width:'100%', height:'100%', 
				left:0, top:0,zIndex:9999, opacity:this.options.opacity, display:'none'});
			$('body').prepend(this.bg);
			if (this.baseZIndex == null) {
				this.baseZIndex = this.element.css('zIndex');
			}
			if (this.basePosition == null) {
				this.basePosition = this.element.css('position');
			}
			if (this.options.toCenter) {
				this.element.css('position', 'fixed');
			} else if(this.basePosition=='static') {
				this.element.css('position', 'relative');
			}
			this.element.css('zIndex', 10000);
			if (API.options.closeOnClick) {
				this.bg.click(function(){API.closeExpose()});
			}

			if (API.options.beforeShow) {
				API.options.beforeShow(API);
			}

			this.bg.fadeIn(this.options.fadeSpeed, function(){
				if (API.options.afterShow) {
					API.options.afterShow(API);
				}
			});

		}
		$(this).data('hyhExposeApi', API);
	}

	API.expose();
	return API;
}



