/**
 * @author al
 */
(function($){
 	$.fn.overlayImage = function(options) {
 		var defaults = {
			width:200,
			height:121,
			overlay: "/images/image-border1.png"
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			
			img = $(this);
			var wd = img.width();
			var ht = img.height();
			options.width = wd + parseInt(wd/6);
			options.height = ht + parseInt(ht/5);
			if (img.attr('longdesc')) {
				var overlay = img.attr('longdesc');
			}else {
				var overlay = options.overlay;
			}
			var title = img.attr('title') ? img.attr('title') : "";
			
			img.attr({
				"vspace": "0",
				"hspace" : "0",
				"border" : "0",
				"align": "",
				"style" : ""
				
			})
			img.css({
				"position": "absolute",
				"top": parseInt(ht/8) + "px",
				"left": parseInt(wd/10) +"px",
				"width":wd + "px",
				"height":ht + "px",
				"z-index": "1",
				"padding":"0",
				"margin": "0"
			})
			var div = $('<div style="float:left;position:relative; width: ' + options.width +'px; height: ' + options.height +'px;"></div>');
			img.wrap(div)
			if (overlay != "none") {
				img.before('<img src="' + overlay + '" title="' + title + '"  style="width:' + options.width + 'px; height:' + options.height + 'px;position: absolute;top:0;left:0;z-index:2;" />');
			}
			//img.before('<div style="background: transparent url(' + options.overlay + ') no-repeat top left;position: absolute;top:0;left:0;width:100%;height:100%;z-index:2;">&nbsp;</div>');
			
			var text = img.attr('alt');
			var textImg ='<h2 class="dakota" style="position:absolute;top:' + (options.height - 12) + 'px;left:0;z-index:3;width:100%;text-align:center;">' + text + '</h2>';
			img.after(textImg);
			Cufon.refresh();
			
		});
	};
})(jQuery);
