/*
 * jQuery iSlide Plugin
 * Version 1.0
 * 
 * Developed by emarketed
 * http://www.emarketed.com
 *
 */

(function($) {

	$.fn.iSlide = function(options) {
		//BEGIN default settings
		var settings = $.extend({
			photos : {},
			duration : 'slow',
			interval : '5000'
		},options);
		//END default settings
		
		//PROPERTIES
		var properties = {
			slider : null, //the parent obj (iSlide div)
			currentSlide : 0, //the current slide number
			timeout : null //the timeout counter
		};

		//METHODS
		function iSlide_slide() {
			properties.currentSlide++;
			if(properties.currentSlide>=settings.photos.length) {
				properties.currentSlide = 0;
				animateProperties = {'margin-left' : '0px'};
			}
			else {
				animateProperties = {'margin-left' : '-='+properties.parent.width()+'px'};
			}
			properties.timeout = setTimeout(function() {
				if(jQuery.easing) { jQuery.easing.def = "easeOutBack";  }
				$(properties.slider).animate(animateProperties,settings.duration,'swing');
				iSlide_slide();
			},settings.interval);
		}
		
		return this.each(function() {
			var obj = $(this);
			obj.html("");
			var slider = $("<div />")
				.css({
					 'width' : (obj.width()*settings.photos.length) + 'px',
					 'height' : obj.css('height')
				})
				.appendTo(obj);
			properties.parent = obj;
			properties.slider = slider;
			$.each(settings.photos,function(i,image) {
				var img = new Image();
				var jImage = $(img);
				jImage.attr('src',image)
					.css({
						'float' : 'left',
						'width' : obj.css('width'),
						'height' : obj.css('height')
					});
				jImage.load(function() {
					$(this).appendTo(slider);
				}); //END jImage.load()
			}); //END $.each(settings.photo)
			iSlide_slide();
		}); //END ths.each()

	} //END $.fn.iSlide

}) (jQuery);
