//Fader Gallery
//By khaled

(function($){

	$.fn.fader=function(settings){
		var settings=$.extend({
			method:"click",
			targetElement:"#receiver",
			CurrImg:"#firstimg",
			animating:false
			},settings);
		this.settings=settings;	
		apply(this);	
	};
	function apply(thIP){
		$(thIP.settings.targetElement).css({position:"relative"});
		thIP.each(function(){
			var method=(thIP.settings.method=="mouseover")?("mouseover"):("click");
			$(this).bind(method,function(){
				if(thIP.settings.animating==false){
					render(this,thIP.settings);	
				}
					
			});			
		});
	}	
	function render(el,settings){
		settings.animating=true;
		var src=$(el).attr("src");
		$(settings.targetElement).append("<img src='"+src+"' border='0' />");
		$(settings.targetElement).children().eq(1).css({display:"none",position:"absolute"});
		$(settings.targetElement).children().eq(1).fadeIn("slow")
		$(settings.targetElement).children().eq(0).fadeOut("slow",function(){
			$(this).remove();
			settings.animating=false;
		});
	}	
})(jQuery);
