/*
 * tinyLightbox - "quicky" animation extension 2.0 - Plugin for jQuery
 * 
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Depends:
 *  jquery.js
 *	jquery.tinyLightbox.js
 * 
 *
 *  Copyright (c) 2008 Oleg Slobodskoi (ajaxsoft.de)
 */
;(function($) {

	$.tinyLightbox.animation.quicky = function()
	{
			var self = this;
			
			this.show = function ( callback)
			{
				self.$overlay.show();
				self.change(callback);
			};
			
			this.prepare = function ( callback )
			{
				self.$bar.hide().height('auto');
				self.$labelClose.hide();
				self.$image.hide();
				callback();
			};
			
			this.change = function ( callback )
			{

				var imageWidth = self.imageWidth< self.d.minWidth ? self.d.minWidth : self.imageWidth;

				var left= self.doc.width/2- imageWidth/2,
					vertAnimation = false,
					horAnimation = false
				;
				
				if ( self.imageHeight != self.$tinyLightbox.innerHeight() )
					vertAnimation = true;
				if (imageWidth != self.$tinyLightbox.innerWidth())
					horAnimation = true;

				vertAnimation ? animateHeight() : ( horAnimation ? animateWidth() : showImage() );
				function animateHeight ()
				{
					self.$tinyLightbox.css({
						height: self.imageHeight+self.paddingTop*2
					});
					horAnimation ? animateWidth() : showImage();
				};

				function animateWidth ()
				{
					self.$tinyLightbox.css({
						width: imageWidth,
						left: left
					});
					showImage();
				};

				function showImage (callback)
				{
					self.$image.show();

					self.$bar.css({
						width: self.$tinyLightbox.innerWidth(),
						bottom: self.$bar.height()*-1
					}).show();
					self.$labelClose.show();
					callback && callback();

				};
			};
			
			this.close = function ( )
			{
				self.$tinyLightbox.remove();
				self.$overlay.remove();
			};
			
			this.limit = function ( callback )
			{
				shake(4, self.d.speed/2, 40, '+', 0);
				function shake (times, speed, distance, dir, timesNow)
				{
					timesNow++;
					dir = dir=='+' ? '-' : '+';
					self.$tinyLightbox.animate({left: dir+'='+distance}, speed, function(){
						timesNow<times && shake(times, speed, distance, dir, timesNow);
						
					});
				};
			};
			
		
	};				

})( jQuery );
