/*
 * jQuery Image Wall 0.3
 * By Damon Williams
 *
 * Copyright (c) 2009 Damon Williams
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.gnu.org/licenses/gpl-2.0.txt) licenses.
*/

(function($){
	
	$.fn.imageWall = function(options) {
		
		var defaults = {
			showNumbers: true,
			showCaptions: true
		};
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			
			if (options.showNumbers) {
				$(this).each(function() {
					$(this).find("li").each(function(i) {
						var number = "<div class=\"iwall-number\">"+(i+1)+"</div>";
						$(this).prepend(number);
					});
				});
			}
		
			$(this).find("li").hover( function(e) { // over

				var w = $(this).find("img").width();

				$(this).stop().animate({
					backgroundPosition:"(-110px 0px)", 
					opacity: "1.0"
				}, {
					duration:600, 
					easing: "easeInOutQuad", 
					complete: function() {
						//$(this).addClass("glow");
						
						$(this).find(".iwall-bar:last").stop().animate({
							width: w
						}, {
							duration:200, 
							easing: "easeInOutQuad", 
							complete: function() {
								$(this).addClass("open");
								$(this).find(".iwall-caption").fadeIn(100);
							}
						});
					}
				});
						
			}, function() { // out
					var b = $(this);
					
					if (!$(this).hasClass("active")) {
						
						//$(this).removeClass("glow");
						
						$(this).stop().animate({
							backgroundPosition:"(230px 0)", 
							opacity: "0.48"
						}, {
							duration:600, 
							easing: "easeInOutQuad", 
							complete: function() {
								$(this).find(".iwall-caption").fadeOut(100, function(evt) {
									b.find(".iwall-bar:last").stop().animate({
										width: "40px"
									}, {
										duration:200, 
										easing: "easeInOutQuad", 
										complete: function() {
											$(this).removeClass("open");
										}
									});
								});
							}
						});
						
					}
					
							
			});
			
		});
		
	};
	
})(jQuery);
