;var $imorphic=(function($){

	$config={
		'hasCanvas':!!document.createElement('canvas').getContext
	}

	if(!$config.hasCanvas){$.fn.imorphic=function(){return this;};return;}

	var $cache={},
		$q=[],
		$o={
			'fx':'fade',
			'speed': 1000,
			'timeout': 6000,
			'autostart':true,
			'pause':false,
			'controls':{
				'id':'banner-controls',
				'order':['action-change prev','action-change next','action-state pause','action-state stop'],
				'text':['Previous','Next','Pause','Stop'],
				'jumpClass':'jump-control',
				'separatorClass':'separator'
			},
			'canvas':$('<canvas></canvas>')
		},
		$lib={
			'fx':{
				'fade':function(){
					var opacity_step= 1,
						opacity= 100 - opacity_step,
						speed= 1500 / (opacity / opacity_step);
/*
					this.interval_id=setInterval(function(){
						alert('fade',$o.index);
						if(!opacity){
							clearInterval($o.interval_id);
							++$o.index;
							if(!$q[$o.index]){$o.index=0;}
//							obj.imorphic(o);
//							$o.canvas.trigger('imorphic.start');
						}
						opacity-= opacity_step;
					},speed);
*/
				}
			},
			'start':function(o){
				o.index=0;
				$lib.fx[o.fx].call(o);
			}
		};

	$.fn.imorphic=function(o){
		o=$.extend(true,$o,o);

		o.canvas.attr({
			'width':o.size.width,
			'height':o.size.height
		}).bind('imorphic.start',function(){
			o.timeout_id=setTimeout($lib.start,3000,o);
		}).bind('imorphic.next',function(){
			
		});

alert('options',$o);

		if(o.images){
			$.each(o.images,function(k,v){
				$q[$q.length]=k;
				o.images[k].img=new Image();
				o.images[k].img.src=o.images[k].src;
			});
		}

		this.each(function(){
			var obj=$(this);
			o.context=obj.find('a').empty().append(o.canvas).find('canvas').get(0).getContext('2d');
			o.canvas.trigger('imorphic.start');

/*
			currIndex=0;
			nextIndex=1;
			context.drawImage(o.images[$q[currIndex]].img,0,0,o.images[$q[currIndex]].size.width,o.images[$q[currIndex]].size.height);

			var opacity_step= 1,
				opacity= 100 - opacity_step,
				speed= 1500 / (opacity / opacity_step);
			interval_id=setInterval(function(){
				context.clearRect(0, 0, o.images[$q[currIndex]].size.width,o.images[$q[currIndex]].size.height);
				context.globalAlpha= (opacity) / 100;
				context.drawImage(o.images[$q[currIndex]].img,0,0,o.images[$q[currIndex]].size.width,o.images[$q[currIndex]].size.height);
				context.globalAlpha= (100 - opacity) / 100;
				context.drawImage(o.images[$q[nextIndex]].img,0,0,o.images[$q[nextIndex]].size.width,o.images[$q[nextIndex]].size.height);
				
				if(!opacity){
					clearInterval(interval_id);
					++nextIndex;
					if(!$q[nextIndex]){nextIndex=0;}
//					obj.imorphic(o);
//					context.canvas.trigger('canvas_cycle.next');
				}
				opacity-= opacity_step;
			},speed);
*/

		});

		return this;
	};

	return{
		'config':$config,
		'load':function(s,o){
			$(s).imorphic(o);
		},
		'set':function(o){
			$.extend(true,$o,o);
		}
	};

})(jQuery);
