(function($){
	$.fn.slideBox = function(options) {
		var element		= $(this[0]);
		var closeBtn	= $("#" + element.attr("id") + " > span.close");
		var width		= element.outerWidth();
		
		var positionType	= {
			topLeft : 0,
			topRight : 1,
			bottomLeft : 2,
			bottomRight : 3
		}

		var defaults	= {	
			position: positionType.bottomRight
		};

		var options = $.extend(defaults, options);


		$(closeBtn).click(function () {
			hide();
		});

		var show = function() {
			var screenWidth = $(document).width();
			
			$(element).css('display', 'block');

			if (options.position == positionType.bottomLeft)
			{
				$(element).css('left', -width + 'px');
				$(element).css('bottom', '20px');
				$(element).animate({ left: '+=' + (width + 20) + 'px' }, 1000, 'easeOutExpo', callback);
			}
			else if (options.position == positionType.bottomRight)
			{
				$(element).css('left', screenWidth + 'px');
				$(element).css('bottom', '20px');
				$(element).animate({ left: '-=' + (width + 20) + 'px' }, 1000, 'easeOutExpo', callback);
			}
			else if (options.position == positionType.topLeft)
			{
				$(element).css('left', -width + 'px');
				$(element).css('top', '20px');
				$(element).animate({ left: '+=' + (width + 20) + 'px' }, 1000, 'easeOutExpo', callback);
			}
			else if (options.position == positionType.topRight)
			{
				$(element).css('left', screenWidth + 'px');
				$(element).css('top', '20px');
				$(element).animate({ left: '-=' + (width + 20) + 'px' }, 1000, 'easeOutExpo', callback);
			}
		}

		var callback = function()
		{
			$(element).oneTime(10000, "hide", function(i) {
				hide();
			});
		}

		var hide = function() {
			$(element).stopTime();

			var screenWidth = $(document).width();
			
			$(element).css('display', 'block');

			if (options.position == positionType.bottomLeft)
			{
				$(element).animate({ left: '-=' + (width + 20) + 'px' }, 1000, 'easeInExpo', function(){
					$(element).css('display', 'none');
				});
			}
			else if (options.position == positionType.bottomRight)
			{
				$(element).animate({ left: '+=' + (width + 20) + 'px' }, 1000, 'easeInExpo', function(){
					$(element).css('display', 'none');
				});
			}
			else if (options.position == positionType.topLeft)
			{
				$(element).animate({ left: '-=' + (width + 20) + 'px' }, 1000, 'easeInExpo', function(){
					$(element).css('display', 'none');
				});
			}
			else if (options.position == positionType.topRight)
			{
				$(element).animate({ left: '+=' + (width + 20) + 'px' }, 1000, 'easeInExpo', function(){
					$(element).css('display', 'none');
				});
			}



			$(element).animate({ left: '+=340' }, 1000, 'easeInExpo', function(){
				$(element).css('display', 'none');
			});
		}

		$(element).oneTime(5000, "show", function(i) {
			show();
		});
			

		/*
		$(element).everyTime(10000, "move", function(i) {
			showNext();
		});
		*/
	};
})(jQuery);
