var $imorphiclite=(function($){

	var $imageCache={},$cacheGroup={};

$.fn.imorphiclite=function(o){

var o=$.extend({
		'fx':'fade',
		'speed': 1000,
		'timeout': 6000,
		'autostart':true,
		'pause':false,

		'controls':['player','separator','jump'],

		'controlsID':'banner-controls',
		'controlOrder':['action-change prev','action-change next','action-state pause','action-state stop'],
		'controlText':['Previous','Next','Pause','Stop'],

		'jumpClass':'jump-control',
		'separatorClass':'separator'
	}, o);

	this.each(function(){
		var obj=$(this),
		 	item = obj.empty().append(generateImages(o.images,this));


		if(o.controls=='jump'){
			var ctls = '<ul class="menu horizontal controls">',
				imgs=o.images?o.images:$cacheGroup[this.id];
			for(var i=0;i<imgs.length;++i){
				ctls+='<li class="'+o.jumpClass+' item-'+i+'"><span>'+(i+1)+'</span></li>';
			}
			item.prepend(ctls+'</ul>').find('.controls .'+o.jumpClass).each(function(i){
				$(this).click(function(){item.cycle(i);})
			});

		}

/*
		var ctls = '<ul class="menu horizontal controls">';
		for(var i=0;i<o.controlOrder.length;++i){
			ctls+='<li class="'+o.controlOrder[i]+'"><span>'+o.controlText[i]+'</span></li>';
		}
		item.prepend(ctls+'</ul>').find('.controls')
			.find('.stop').click(function(){item.cycle('stop');}).end()
			.find('.pause').data('pause',!o.autostart).click(function(){
				var btn=$(this);
				if(btn.data('pause')){
					item.cycle('resume',true);
					btn.addClass('pause').removeClass('play').data('pause',false);
				}else{
					item.cycle('pause');
					btn.addClass('play').removeClass('pause').data('pause',true);
				}
			}).end()
			.hide().fadeIn(2500);
*/
	});
//,			'pager':(o.controls=='jump'?'#banners-container .controls':null)
		this.cycle({
			'fx':o.fx,
			'timeout':o.timeout,
			'speed':o.speed,
			'autostop':!o.autostart,
			'autostopCount':1,
			'pause':o.pause,
			'slideExpr':'img',
			'prev':'.prev',
			'next':'.next',
			'after':function(currSlideElement, nextSlideElement, options, forwardFlag){
				$('.'+o.jumpClass).removeClass('active').eq(options.currSlide).addClass('active');
			}
		});

	function generateImages(imgs,item){
		if(imgs){
			var cimg=false;
			for(var i=0;i<imgs.length;++i){
				cimg = imgs[i];
				if(cimg.link){imgs[i] = '<a href="'+cimg.link+'"><img alt="'+cimg.alt+'" src="'+cimg.src+'" width="'+cimg.size.width+'" height="'+cimg.size.height+'" /></a>';}
				else{imgs[i]='<img alt="'+cimg.alt+'" src="'+cimg.src+'" width="'+cimg.size.width+'" height="'+cimg.size.height+'" />';}
			}
			return imgs.join('\n');
		}else{
			return generateImages($cacheGroup[item.id]);
		}
	}

	return this;

};


return {
//	Create a new effect that can be used if options are specified, otherwise, the method returns if the effect exists.
//	If no effect name is given, an array of the available effects is returned.
//* fx: Name of the effect
//* o: Effect parameters
//* r: Replace if effect exists
	'fx':function(fx,o,r){
		if(fx){
			var isfx=fx in $.fn.cycle.transitions;
			if(o&&(!isfx||r)){
			//* cc: The container element for the slides
			//* cs: An array of the slide elements
			//* co: The current options object
				return $.fn.cycle.transitions[fx]=function(cc,cs,co){
					$.extend(co,o);
				}
			}
			return isfx;
		}
		var fxs=[];
		for(var fx in $.fn.cycle.transitions){fxs[fxs.length]=fx;}
		return fxs;
	},
//	Create an image object and store it in cache for use in a slideshow.
//* img: An object that has the properties for the image.
//* cache: If given, the value of this will be used as the identifer in the cache.
	'image':function(img,cache){
		if(!$.isArray(img) && !$.isArray(cache)){
			var obj=new Image();
			$.extend(obj,img);
				if(cache&&typeof(cache)=='string'){$imageCache[cache]=obj;return cache;}
			return obj;
		}else{
			for(var i=0;i<img.length;++i){
				this.image(img[i],cache[i]);
			}
		}
	},
	'register':function(k,imgg){
		$cacheGroup[k]=this.cache(imgg);
	},
	'cache':function(imgList){
		var imgs=[];
		for(var i=0;i<imgList.length;++i){
			imgs[imgs.length]=$imageCache[imgList[i]];
		}
		return imgs
	}
};

})(jQuery);


