/*
 * 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,
			inStyle: 'fade', // slide, fade, show
			inSpeed: 'normal', // slow, normal, fast, 1XXX
			outStyle: 'fade', // slide, fade, hide
			outSpeed: 'normal' // slow, normal, fast, 1XXX
		};
		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);
					});
				});
			}
			
			if (options.showCaptions) {
				$(this).find("li").hover( function(e) { // over
					var title = "<div class=\"iwall-title\">"+$(this).find("a img").attr("alt")+"</div>";
					if (options.showCaptions) {
						var caption = "<div class=\"iwall-caption\">"+$(this).find("a img").attr("title")+"</div>";
					}
					var slide = "<div class=\"iwall-bar\">"+title+""+caption+"</div>";
					$(this).append(slide);
					switch(options.inStyle) {
						case "show":
							$(this).find(".iwall-bar:last").show(options.inSpeed);
						break;
						case "slide":
							$(this).find(".iwall-bar:last").slideToggle(options.inSpeed);
						break;
						case "fade":
							$(this).find(".iwall-bar:last").fadeIn(options.inSpeed);
						break;
					}
					}, function() { //out
						switch(options.outStyle) {
							case "hide":
								$(this).find(".iwall-bar:last").hide(options.outSpeed);
							break;
							case "slide":
								$(this).find(".iwall-bar:last").slideToggle(options.outSpeed);
							break;
							case "fade":
								$(this).find(".iwall-bar:last").fadeOut(options.outSpeed);
							break;
						}
				});
			}
			
		});
		
	};
	
})(jQuery);
