(function($) {
  $.fn.slideShow = function(options) {
    var defaults = {
      images : '/assets/Keyvisuals/wale04.jpg,',
      fadingSpeed : 600,
      fadingInterval: 5000
    }

    var o = $.extend(defaults, options);
	//console.log(o.images);
    var imageArray = o.images.split(',');
    imageArray.pop();

    function doFading() {

        curImg = $('#fadeShow img.selected');
        curImgIndex = $(curImg).attr('id');

        nextImgIndex = curImgIndex == 0 ? imageArray.length-1 : curImgIndex-1;
        

        nextImg = $('#fadeShow img#'+nextImgIndex);
        $(curImg).fadeOut(o.fadingSpeed, function() {
            $(curImg).removeClass('selected');
        });
        
        $(nextImg).fadeIn(o.fadingSpeed, function() {
            $(nextImg).addClass('selected');
        });

    }

    return this.each(function() {
      $(this)
        .attr('id', '')
        .attr('id', 'fadeShow')
        .html('');

      imageArray.reverse();
      $.each(imageArray, function(index, val) {
        $('#fadeShow').append('<img src="'+ val +'" id="'+index+'" />');
      });
      $('#fadeShow img:last').addClass('selected');

      interval = setInterval(doFading, o.fadingInterval);

    });
  }
})(jQuery)


