var currentRotateBox = "rotateBox0";
var currentAnimation = "";
var boxCounter = 0;
var rotateTimer = "";
var rotateTime = 5000;
var fadeTime = 750;


function rotateOut(box)
{
	var boxOut = dojo.animateProperty(
	{
	  node:box, 
	  duration:1, 
	  properties:{
	    left:{start:"0", end:"-976", unit:"px"},top:{start:"0", end:"0", unit:"px"}
	    }
	});
	var boxFade = dojo.fadeOut({node: box,duration: fadeTime});
	
	return dojo.fx.chain([boxFade, boxOut]);
}

function rotateIn(box)
{
	dojo.fadeOut({node: box,duration: 1}).play();
	var boxIn = dojo.animateProperty(
	{
	  node:box, 
	  duration:1, 
	  properties:{
	    left:{start:"-976", end:"0", unit:"px"},top:{start:"0", end:"0", unit:"px"}
		
	    }
		
	});
	var boxFade = dojo.fadeIn({node: box,duration: fadeTime});
	
	return dojo.fx.chain([boxIn, boxFade]);
	
}

function rotateBoxes(boxOut, boxIn)
{
	if(!(dojo.byId(boxOut) && dojo.byId(boxIn)) || (boxOut == boxIn))
	{
		return 0;
	}
	
	
	if(currentAnimation && currentAnimation.status() == "playing")
	{	
		//maybe need to do something here..
    }
   
	currentAnimation = dojo.fx.chain([rotateOut(boxOut), rotateIn(boxIn)]).play();
	currentRotateBox = boxIn;
		
	
}

function autoRotate()
{
	boxCounter++;
	if(boxCounter > 9)
	{
		boxCounter = 0;
	}
	rotateBoxes(currentRotateBox, "rotateBox" + boxCounter);
	rotateTimer = setTimeout("autoRotate()", rotateTime);
}

function Left(str, n){
	if (n < 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n < 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function clearTimer()
{
	clearTimeout(rotateTimer);
}

function startTimer()
{
	boxCounter = Right(currentRotateBox, 1);
	rotateTimer = setTimeout("autoRotate()", rotateTime);
}

