var transitiontime = 6000;
var spacer = 18;

function theRotator() {
	//Set the opacity of all images to 0
    $('div.rotator ul li').css({ opacity: 0.0 });
    
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({ opacity: 1.0 });
		  	
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds	
	setInterval('rotate(true)', transitiontime);	
}

function rotate(rotate) {	

	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

    if (rotate == true) {

        next.show();
        //$("your-pure-css-selector").not('[name="value"]')        
	    //Set the fade in effect for the next image, the show class has higher z-index
	    next.css({opacity: 0.0})
	    .addClass('show')
	    .animate({ opacity: 1.0 }, 1000);
	}

	var div = $(".example-twitter");
	var startHeight = current.height() + spacer;

    if (rotate == true)
    {
        $('div.rotator ul').height(next.height());
        next.find('span.tweet_text').height(next.height());
	    // Set back to start height and then do animation
	    div.css('height', startHeight + 'px');
	    div.animate({ 'height': next.height() + spacer }, { duration: 500 });
	    div.find('.tweet_text').height(next.height());
    }

    if (rotate == true)
    {
	    //Hide the current image
	    current.animate({opacity: 0.0}, 500)
	    .removeClass('show');

	    current.hide();
    }
};
