(function ($) {
	$.loewy = $.loewy || {};
	
	$.fn.loewyAjaxLoad = function() {
		return this.each(function() {
			new $.loewy.ajaxLoad(this)
		});
	};
	
	$.loewy.ajaxLoad = function(obj) {
		var e = obj;
		var file = "";
		var type = "";
		var tries = 0;
		
		var init = function() {
			rel = $(e).attr("rel");
			rels = rel.split(":",2);
			if (rels.length > 0 && rels[1] != "") {
				file = rels[1];
				
				if (/\.png$/ig.test(file)) {
					type="image/png";
				}
				if (/\.gif$/ig.test(file)) {
					type="image/gif";
				}
				if (/\.jpg$/ig.test(file)) {
					type="image/jpg";
				}
				
				return true;
			} else {
				return false;
			}
		};
		
		var start = function() {
			$.ajax({
				url:'/load_image.php',
				data:'file='+URLEncode(file),
				type:'get',
				success:function(msg) {
					p = $(e).parent();
					$(e).replaceWith(msg);
					if ($.loewy.fixPng!=undefined && typeof $.loewy.fixPng == "function") {
						$.loewy.fixPng(p);
					}
				},
				error:function(obj,msg,err) {
				}
			});
		};
		
		if (!init()) {
			return false;
		}
		
		start();
	};
	
	$().ready(function() {
		$('[@rel*=ajaxload]').loewyAjaxLoad();
		
		
	});
})(jQuery);

