(function() {
  var newMethods = {
	  nslide : function(options) {
		var defaults = {
			v:2000,
			d:8000,
			a:"fade"
		};
		var options = $.extend(defaults, options);
		var obj = $(this);
		var imgs = $(".slide", obj);
		var current = 0;
		var next;
		var velocity = options.v;
		var delay = options.d;
		var anime = options.a;
		var xdelay = delay + velocity;
		init();
		function init() {
			/* ============================================ */
			if(anime == "fademerge") {
				imgs.css({ opacity:0 });
				imgs.eq(0).animate({ opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).animate({ opacity:0 }, velocity);
					imgs.eq(next).animate({ opacity:1 }, velocity);
					current = next;
				}, xdelay);
			}
			if(anime == "fadewait") {
				xdelay = ((delay) + (velocity *2));
				imgs.css({ opacity:0 });
				imgs.eq(0).animate({ opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).animate({ opacity:0 }, velocity);
					setTimeout(function() {
						imgs.eq(next).animate({ opacity:1 }, velocity);	
						current = next;
					}, velocity);
				}, xdelay);
			}
			/* ============================================ */
			if(anime == "slidepullleft") {
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:'-'+imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ marginLeft:'-'+imgs.eq(current).width() }, velocity);
					imgs.eq(next).animate({ marginLeft:0}, velocity);
					current = next;
				}, xdelay);
			}
			if(anime == "slidepullleftfade") {
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:'-'+imgs.eq(i).width(), opacity:0, zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0, opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ opacity:0, marginLeft:'-'+imgs.eq(current).width() }, velocity);
					imgs.eq(next).animate({ opacity:1, marginLeft:0}, velocity);
					current = next;
				}, xdelay);
			}
			if(anime == "slidepullleftwait") {
				xdelay = ((delay) + (velocity *2));
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:'-'+imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ marginLeft:'-'+imgs.eq(current).width() }, velocity);
					setTimeout(function() {
						imgs.eq(next).animate({ marginLeft:0}, velocity);
						current = next;
					}, velocity);
				}, xdelay);
			}
			if(anime == "slidepullleftfadewait") {
				xdelay = ((delay) + (velocity *2));
				imgs.each(function(i) {
					imgs.eq(i).css({ opacity:0, marginLeft:'-'+imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0, opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ opacity:0, marginLeft:'-'+imgs.eq(current).width() }, velocity);
					setTimeout(function() {
						imgs.eq(next).animate({ opacity:1, marginLeft:0}, velocity);
						current = next;
					}, velocity);
				}, xdelay);
			}
			/* ============================================ */
			if(anime == "slidepullright") {
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ marginLeft:imgs.eq(current).width() }, velocity);
					imgs.eq(next).animate({ marginLeft:0}, velocity);
					current = next;
				}, xdelay);
			}
			if(anime == "slidepullrightfade") {
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:imgs.eq(i).width(), opacity:0, zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0, opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ opacity:0, marginLeft:imgs.eq(current).width() }, velocity);
					imgs.eq(next).animate({ opacity:1, marginLeft:0}, velocity);
					current = next;
				}, xdelay);
			}
			if(anime == "slidepullrightwait") {
				xdelay = ((delay) + (velocity *2));
				imgs.each(function(i) {
					imgs.eq(i).css({ marginLeft:imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ marginLeft:imgs.eq(current).width() }, velocity);
					setTimeout(function() {
						imgs.eq(next).animate({ marginLeft:0}, velocity);
						current = next;
					}, velocity);
				}, xdelay);
			}
			if(anime == "slidepullrightadewait") {
				xdelay = ((delay) + (velocity *2));
				imgs.each(function(i) {
					imgs.eq(i).css({ opacity:0, marginLeft:imgs.eq(i).width(), zIndex:0 });		
				});
				imgs.eq(0).css({ zIndex:10 }, velocity);
				imgs.eq(0).animate({ marginLeft:0, opacity:1 }, velocity);
				setInterval(function() {
					getNext();
					imgs.eq(current).css({ zIndex:0 }, velocity);
					imgs.eq(next).css({ zIndex:10 }, velocity);
					imgs.eq(current).animate({ opacity:0, marginLeft:imgs.eq(current).width() }, velocity);
					setTimeout(function() {
						imgs.eq(next).animate({ opacity:1, marginLeft:0}, velocity);
						current = next;
					}, velocity);
				}, xdelay);
			}
			/* ============================================ */
		}
		function getNext() {
			next = current + 1;
			if(next > (imgs.length - 1)) {
				next = 0;	
			}
		}
		
	  }
  };
  jQuery.each(newMethods, function(i) {
    jQuery.fn[i] = this;
  });
})();
