(function($){
	
	/* The plugin extends the jQuery Core with four methods */
	
	/* Converting an element into a bounce box: */
	$.fn.bounceBox = function(){
		
		/*
			Applying some CSS rules that center the
			element in the middle of the page and
			move it above the view area of the browser.
		*/
		
		this.css({
			top			: -this.outerHeight(),
			marginLeft	: -this.outerWidth()/2,
			position	: 'fixed',
			left		: '50%'
		});
		
		return this;
	}
	
	var timeOut;
	
	/* The boxShow method */
	$.fn.bounceBoxShow = function(param){
		
		/* Starting a downward animation */
		
		this.stop().animate({top:0},{easing:'easeOutBounce'});
		this.data('bounceShown',true);
		
		/* Auto-hide functionality, added on 29.05.2010 */
		
		clearTimeout(timeOut);
		
		if(param && param.hasOwnProperty('autohide')){
			
			var element = this;
			timeOut = setTimeout(function(){
								
				if(element.data('bounceShown')) element.bounceBoxHide();
				
			}, param.autohide);
		}
		
		return this;
	}
	
	/* The boxHide method */
	$.fn.bounceBoxHide = function(){
		
		/* Starting an upward animation */
		
		clearTimeout(timeOut);
		
		this.stop().animate({top:-this.outerHeight()});
		this.data('bounceShown',false);
		return this;
	}
	
	/* And the boxToggle method */
	$.fn.bounceBoxToggle = function(param){
		
		/* 
			Show or hide the bounceBox depending
			on the 'bounceShown' data variable
		*/
		
		param = param || {};
		
		if(this.data('bounceShown'))
			this.bounceBoxHide();
		else
			this.bounceBoxShow(param);
		
		return this;
	}
	
})(jQuery);
