var $ = jQuery.noConflict();
jQuery(document).ready(function(){

jQuery.fn.simpleSpy = function (limit, interval) {
    limit = limit || 2;
    interval = interval || 10000;
    
    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var list = jQuery(this),
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
            
						height = list.find("> div.newrotitem:first").height();
            
        // capture the cache
        list.find("> div.newrotitem").each(function () {
            items.push("<div class=\"newrotitem\">" + jQuery(this).html() + "</div>");
        });
        
        total = items.length;
        
       // list.wrap("<div class=\"spyWrapper\" />").parent().css({ height : height * limit });
        
        list.find("> div.newrotitem").filter(':gt(' + (limit - 1) + ')').remove();

        // 2. effect        
        function spy() {
            // insert a new item with opacity and height of zero
            var insert = jQuery(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'none'
            }).prependTo(list);
                        
            // fade the LAST item out
            list.find("> div.newrotitem:last").animate({ opacity : 0}, 300, function () {
                // increase the height of the NEW first item
                insert.animate({ height : height }, 4000).animate({ opacity : 1 }, 300);
                
                // AND at the same time - decrease the height of the LAST item
                // $(this).animate({ height : 0 }, 2000, function () {
                    // finally fade the first item in (and we can remove the last)
                    jQuery(this).remove();
                // });
            });
            
            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }
            
            setTimeout(spy, interval)
        }
				//RDC: added if condition
        if(total>1){
				  spy();
				};
				//end RDC
    });
};		
		
jQuery("div.news_internal_rotator").simpleSpy();		

});
