jQuery.fn.isSlideShow = function(attr,next) {
	
    attr = attr || {};
    
    function changeCurrentImage(container) {
        $(container).each(function() {
            var images = $(this).find('a.image');
            if (images.length < 2)                 
                return;
            
            var current = $(this).find('a.image.current');
            
            var imgb = null;
            do {
                imgb = $(images[Math.floor(Math.random() * images.length)]);
            }
            while (imgb.is('.current'));
            
			var lastTransitionTimeout = null;
			
            function startTransition(to) {
            	
            	$('#core_text').animate({opacity: 0,}, 1500, function() {
            	
            	$('#core_text').html(imgb.attr('alt'));
            	$('#core_text').delay(2000).animate({opacity: 1,}, 1500);
            	
            	});
            	
				clearTimeout(lastTransitionTimeout);
				
                current.css({
                    'opacity': 1,
                    'z-index': 0
                }).animate({
                    'opacity': 0
                }, attr.effectLength, function() {
                    $(this).removeClass('current');
                    
                    $(to).addClass('current');
                    $(to).css({
                        'opacity': 0,
                        'z-index': 1
                    }).animate({
                        'opacity': 1
                    }, attr.effectLength, function() {
                    
                        lastTransitionTimeout = setTimeout(function() {
                            changeCurrentImage(container);
                        }, attr.interval);
                    });
                });
                
            }
            
            if (imgb.find('img').length == 0) {
                imgb.append($('<img src="' + imgb.attr('data-thumbnail') + '" alt="" />').load(function() {
                    startTransition(imgb);
                }));
            } else {
                startTransition(imgb);
            }
            
        });
            	
            	
    }
	
	var ctr = this;
	$(ctr).find('.image:not(.current)').css('opacity', 0);
	setTimeout(function(){
		changeCurrentImage(ctr);
	}, attr.interval);
    
}

$(function() {
    $('#core').isSlideShow({
        'interval': 10000,
        'effectLength': 2000
    },false);
});

