/**
 * @author pedromoraes@gmail.com
 */
var BIG;
var SMALL;
var path = "img/rotating_banner/";
var credits;
$(document).ready(function(){
	setTimeout("rotate()", 3000);
	BIG = BIG.split(",");
	SMALL = SMALL.split(",");
	for ( var i = 0; i < BIG.length; i ++ ) BIG[i] = path + BIG[i];
	for ( i = 0; i < SMALL.length; i ++ ) SMALL[i] = path + SMALL[i];
});

function rotate() {
	var pick = Math.floor( Math.random() * 3 );
	var currentSrc;
	var newSrc;
	var current;
	switch( pick ) {
		case 0: //rotate big img
			current = $("#right_menu_container .img1");
			currentSrc = current.attr("src");
			newSrc = BIG.slice();
			newSrc.splice( BIG.indexOf( currentSrc ), 1 );
			break;
		case 1: //rotate small left img
			current = $("#right_menu_container .img2");
			currentSrc = current.attr("src");
			newSrc = SMALL.splice( SMALL.indexOf( currentSrc ), 1 );
			break;
		case 2: //rotate small right img
			current = $("#right_menu_container .img3");
			currentSrc = current.attr("src");
			newSrc = SMALL.splice( SMALL.indexOf( currentSrc ), 1 );
			break;
	}
	newSrc = newSrc[ Math.floor( Math.random() * newSrc.length ) ];
	$("<img/>").attr({ src: newSrc, title: credits }).addClass("img" + (pick + 1))
	.css("opacity", 0)
	.appendTo("#right_menu_container")
	.load(function(){
		$(this).animate({opacity:1},900,null,function(){
			$(current).remove();
			setTimeout("rotate()", 2000);
		});
	});
}
