

(function ($) {
    
$.fn.simpleCarrusel = function (interval , imgPath) {

    interval = interval || 10000;
    var imgPath = imgPath || '/img/portada';
	target = this;
    
    function getItem($source) {
	
		last_item = jQuery(imgs_portada).length;
		
		if ( typeof current_item == 'undefined' ) {
			current_item = 0;
		}

		
		$return = imgs_portada[current_item];
		current_item++;
		
		if (current_item == last_item) {
			current_item = 0;
		}
		
        return $return;
    }
	
	function createImagePath(img) {
		return imgPath + '/' + img;
	}
	
	function createImgHtml(img) {
		path = createImagePath(img);
		return '<img src="' + path + '" />';
	}
    
    return this.each(function () {

		function rotateImg() {
                var $item = getItem(imgs_portada);
				
				img_html = createImgHtml($item)
				jQuery(target).fadeOut( 'slow' , function () {
					jQuery(this).html(img_html).fadeIn('slow')
				});

            setTimeout(rotateImg, interval);
        }
        
        rotateImg();
    });
};
    
})(jQuery);
