﻿/*
 * FourthMedia Image Loader
 * Version 1.0 (22 May 2009)
 * @requires jQuery v1.3.2
 * Created By Brand HU
 */

function LoadImagebyDivID(divID){
var thediv = jQuery("#"+divID)
LoadImage(thediv)
}
function LoadImagesByClass(classname){
	jQuery("."+classname).each(function(){
		LoadImage(jQuery(this));
	});
}
function LoadImage(jobject){
    var loadingclass = 'imageloading'
	var imgpath = jobject.attr("imagesrc")
	var width = jobject.attr("imagewidth")
	var height = jobject.attr("imageheight")
	var overimage = jobject.attr("overimage")
	if (imgpath){
	    jobject.html("&nbsp;");
	    if(!jobject.hasClass(loadingclass)){
	        jobject.addClass(loadingclass)
	    }
		var img = new Image();
		jQuery(img).load(
			function (){
			    jobject.html("");
				jQuery(this).css('display','none');
				if (width && height){
				    jQuery(this).css('width',width+'px');
				    jQuery(this).css('height',height+'px');
				}
				jobject.removeClass(loadingclass);
				jobject.append(this);
				jQuery(this).fadeIn();
				if(overimage){
				    jQuery(this).before("<div class='" + overimage + "'></div>")
				}
			}
		).error(function(){jobject.html('No Image')}).attr("src",imgpath);
	}else{
	    if(jobject.hasClass(loadingclass)){
	        jobject.removeClass(loadingclass)
	    }
	}
}

