// initialise the variables 
var lastStateSelected = "anchALL";
i = 0;
flipStates = new Array (ALL);
tickercolourOn = new Image
tickercolourOff = new Image
tickercolourOn.src = "/images/v2/ticker/ticker_color_on.gif";
tickercolourOff.src = "/images/v2/ticker/ticker_color_off.gif";




// this function changes the state which is being displayed
function toggleVals(stateToUse) {

	// modify the text
	document.getElementById('totalrecs').innerHTML=stateToUse[1];
	document.getElementById('newlist').innerHTML=stateToUse[2];
	document.getElementById('pricechanges').innerHTML=stateToUse[3];
	document.getElementById('changestat').innerHTML=stateToUse[4];
	document.getElementById('currentOne').innerHTML=stateToUse[0];

	// switch the colours around for the selected state
	if (lastStateSelected != "none") {
		document.getElementById(lastStateSelected).style.backgroundColor = '';
		document.getElementById(lastStateSelected).style.color = '';
	}
	document.getElementById(stateToUse[6]).style.backgroundColor = '#C7C7C9';
	document.getElementById(stateToUse[6]).style.color = '#000000';
	lastStateSelected = stateToUse[6];
}





// this is the function that does the actual sliding of the elements
function slide(passedbottomrange, blockDiv, inOrOut) {
	if (passedbottomrange) {
		bottomrange = passedbottomrange;
		block = blockDiv.style
		
		// the following if statement fixes a bug with Apple Mac Browsers to do with different settimeout timings
		if (inOrOut == "slidein") {
			block.top = 39;
		}

		block.xpos = parseInt(block.left)
		block.ypos = parseInt(block.top)
		whichSlide = inOrOut;
	}
	if (block.ypos > bottomrange) {
		block.ypos -= 3
        block.top = block.ypos
		
		innerSlideLoop=setTimeout("slide()",10);
	}
}





function resetPosition() {
	document.getElementById('blockDiv_all').style.top = 6;
}






// this function pauses the ticker and changes the text from "Pause Ticker" to "Resume Ticker"
function pauseTicker() {
	clearTimeout(slideItOnOut);
	clearTimeout(keepOnChanging);
	clearTimeout(innerSlideLoop);
	document.getElementById('tickercontrol').innerHTML='<img src="/images/v2/icons/ticker_resume.gif" width="11" height="11" border="0" alt=""> <a href="javascript:resumeTicker()" class="ticker">Resume Ticker</a>';
	chgImg('tickercolour', 'navtickercolourOff');
	
	// the following 2 lines are in case someone pauses the ticker half way through a transition
	resetPosition();
	setTimeout('resetPosition()', 200);
}




// this function starts the ticker back up again and changes the text from "Resume Ticker" to "Pause Ticker"
function resumeTicker() {
	
	// work out which state was the last one selected and then set the loop variable i so that when the ticker starts up again it will start from the correct state
	switch (lastStateSelected)
	{
		case "anchALL":
		  i = 0
		  break
		default:
		  i = 0
	}
	changeIt();
	document.getElementById('tickercontrol').innerHTML='<img src="/images/v2/icons/ticker_pause.gif" width="11" height="11" border="0" alt=""> <a href="javascript:pauseTicker()" class="ticker">Pause Ticker</a>';
	chgImg('tickercolour', 'navtickercolourOn')
}






function changeIt () {
	
	// slide the values into the clipping area
	slide(6, document.getElementById('blockDiv_all'), 'slidein');
	
	// set the state which is to be modified
	statetopass = flipStates[i];

	// switch the values to the next state
	toggleVals(statetopass);

	// slide the values off the clipping area after a 3.5 second delay
	//slideItOnOut=setTimeout('slide(-50, document.getElementById("blockDiv_all"), "slideout")' , 4500);
	
	//check if all the states have been displayed and if they have then start again
	if (i != 0) {
		i += 1;
	} else {
		i = 0;
	}
	
	// continue the function indefinitely by calling itself
	//keepOnChanging=setTimeout('changeIt()', 4800);
}





// this sets the ticker off
changeIt();
