(function($){

	$.fn.melt = function(options) { 	
		var defaults = {
			path: 'imgs/',								// our default path where the images are stored
			imges: Array('one.jpg','another.jpg'),		// our list of images to load
			speed: 1000,								// how fast it takes to fade between two images
			delay: 3000,								// how long we wait till we fade to the next image
			cur: 0,										// the current image we are showing (i.e. we are busy showing image 3 out of the 8)
			max: 0,										// the amount of images we have ( i.e. a total of 8 images )
			target: '_self',					// target if we click this (_parent,_self,_blank,etc)
			src: '#-'						// the link we go to (i.e. the href=
		};
  
		var options = $.extend(defaults, options);
		var obj = $(this);

		var outp = '';
		options.max = options.imges.length;

		for( var i = 0; i < options.max; i++ ) {
			outp += '<div style="position: absolute;display: none;"><a href="'+options.src+'" target="'+options.target+'"><img src="'+options.path+options.imges[i]+'"></a></div>';
		}

		// create our div tags for each image and lay them ontop of eachother
		obj.html(outp);
		// show the first image so we can fade it out and fade the second image in
		obj.children('div:eq('+options.cur+')').show();
		// begin the magic
		f(obj.children('div:eq('+options.cur+')'),options.delay);
		
		function f(next) {
			options.cur++; if( options.cur == options.max ) { options.cur = 0; }
			next.delay(options.delay).fadeOut(options.speed);
			obj.children('div:eq('+options.cur+')').delay(options.delay).fadeIn(options.speed,function(){ f($(this)); });
		}
	};
})(jQuery);
