/**
 * jQuery GSImageTitle plugin, 
 * @author Michał Lipek
 * @version 0.01
 *
 * Changelog:
 * 0.01
 * - wersja pierwsza
 * 0.02honda
 * - po | można w title wstawić linka
 * 
 * Copyright (c) 2009 GoldenSubmarine, 
 * http://www.goldensubmarine.com/
 * 
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License 
 */

(function($) {
	 
	$.fn.gsImageTitle = function(settings) {
		                                    
		var config = $.extend({}, $.fn.gsImageTitle.defaults);
		if (settings) {
			var config = $.extend(config, settings);
		}
	 
		return this.each(function() {
			$this = $(this);
			_init($this);
		});

		
	    function _init($element) {
			var title = $element.attr("title");
			var url = "";
	    	if (title.length) {
				if (title.indexOf("|") >= 0) {
					var tmp = title.split("|");
					title = tmp[0];
					url = tmp[1];
					$element.attr('title', tmp[0]);
				}
				$container = $element.parents("div:first").css("position", "relative");
				
				var position = $element.position();
				var width = $element.width();
				var height = $element.height();
				var marginTop = parseInt($element.css('margin-top'));
				
				$titleWrap = $("<span>").addClass("gsImageTitleWrap");
				$titleWrap.css({
					position: "absolute",
					left: position.left.toString()+"px",
					top: (position.top + height - config.height + marginTop).toString()+"px",
					width: width.toString()+"px",
					display: "block",
					height: config.height.toString()+"px"
				});
				$title = $("<span>").addClass("gsImageTitle").html(title);
				if (url.length) {
					$a = $("<a>").attr('href', url);
					$a.append($title);
					$titleWrap.append($a);
				}
				else {
					$titleWrap.append($title);
				}
				$container.append($titleWrap);
	    	}
	    };


	};
	
	$.gsImageTitle = function() {
		// nothing :)
	}
	
	$.gsImageTitle.destroy = function() {
		$('.gsImageTitleWrap').remove();
	}
	
	
	$.fn.gsImageTitle.defaults = {
		"height": 30
	};
	 
})(jQuery);


/* end of plugin */