var highlightsXML;
if(!MOZILLA)
{
	highlightsXML = new ActiveXObject("Microsoft.XMLDOM");
}
var specifyimage=new Array(); //Your images
var productids=new Array();  // Product ids
var altertext=new Array();
var cubeimage=new Array();
var isloaded = 0;
var rotation = 0;
var delay=5000 //2 seconds

//Counter for array 
var count = 1;
var xmlCount = 0;

var curImage = 1;
var maxImages =	13;	
var imageText = new Array("","FIDE vice-president Azmai's arrest at the 2004 Olympiad in Calvia.","Young GM's Smeets, Carlsen and Ponomariov watch Sergey Karjakin relax at an Amsterdam canal in August 2006.","US Champion Nakamura has just played 1.e4 c5 2.Qh5! and now glances to see how Andrey Volokitin takes this in.","Election time at the 2006 FIDE Congress: a delegate has just met candidate Ilyumzhinov and carries off some 'personal gifts'.","Moro and Topalov, Linares 2007: not the best of friends, they didn't  shake hands, and are now busy ignoring the other.","Xu Yuhua on her way to become World Champion in 2006: she's having a bite while her seconds prepare for the next game.","Magnus Carlsen playing a blindfold simul at the Norwegian College forTop Athletes, in 2006.","Khalifman smiles when confronted by Zviagintsev's novelty 1.e4 c5 2.Na3! at the 2006 Russian Super Final.","Bilbao 2008: there goes a lot of money. Aronian escapes with a draw, Ivanchuk misses out on 20,000 Euro.","Sofia 2008. Ivan Cheparinov checks to see if Bu Xiangzhi realises he has been outplayed.","Yes, he does!","Only the local official wears a western suit (Nanjing 2008)","Amsterdam 2008: Chinese super-GM Wang Yue goes shopping.","Remember Yury Dokhoian, Garry Kasparovs second? At the Olympiad in Dresden 2008 he coaches the formidable (but cheerful) Kosintseva sisters.","")

function loadXML()
{
	if(highlightsXML.readyState == '4')
	{
		xmlCount = 0;
		window.clearTimeout(isloaded);
		var loopIndex,loopNode,currentNode;
		var rootElement = highlightsXML.documentElement;
		if(rootElement == null) return;
		nodeCount = rootElement.childNodes.length;
		for(loopIndex = 0;loopIndex < nodeCount;loopIndex++)
		{
			currentNode = rootElement.childNodes.item(loopIndex);
			for(loopNode = 0;loopNode < currentNode.childNodes.length;loopNode++)
			{
				if(currentNode.childNodes.item(loopNode).nodeName == "ImageUrl")
				{
					specifyimage[xmlCount] = "./Home/Images/Highlights/" + getImageFileName(currentNode.childNodes.item(loopNode).text);
				}
				if(currentNode.childNodes.item(loopNode).nodeName == "NavigateUrl")
				{
					productids[xmlCount] = currentNode.childNodes.item(loopNode).text;
				}
				if(currentNode.childNodes.item(loopNode).nodeName == "AlternateText")
				{
					altertext[xmlCount] = currentNode.childNodes.item(loopNode).text;
					xmlCount++;
				}
			}	
		}
		for(i=0;i<xmlCount;i++)
		{
			cubeimage[i]=new Image();
			cubeimage[i].src=specifyimage[i];
		}
		this.count = Math.floor(Math.random()* xmlCount);

		document.images.cube.src=cubeimage[this.count].src;
		this.GetElementByID("Rotator").href=productids[this.count]+ " ";
		this.GetElementByID("rotatorbox").style.display = "";

		this.count++;
		if (this.count==xmlCount) this.count=0;
		
		setTimeout("movecube()",delay);
	}
	else
	{
		isloaded = window.setTimeout("loadXML()",500);
	}

}
function getImageFileName(fileName)
{
	var index = 0;
	var lastSlash = 0;
	while(true)
	{
		if(fileName.substring(index,index+1) == '/')
		{
			lastSlash = index+1;
		}
		index++;
		if(index > fileName.length) break;
	}
	return fileName.substring(lastSlash);
}
function movecube()
{
	if(rotation == 1) {
		setTimeout("movecube()",delay);
		return;
		}
	var rotator = this.GetElementByID("rotate");
	if (window.createPopup)		rotator.filters[0].apply()
	rotator.src=cubeimage[this.count].src;
	if (window.createPopup) rotator.filters[0].play();
	this.GetElementByID("Rotator").href=productids[this.count]+ " ";
	rotator.alt=altertext[this.count];
	this.count++;
	if (this.count==xmlCount) this.count=0;
	setTimeout("movecube()",delay);
	delay = 10000; // Change to 5 seconds
}
// Start/Stop anime
function stop_rotator()
{
	rotation = 1;
}
function start_rotator()
{
	rotation = 0;
}
// Init the rotatorbar
function InitRotator()
{
	if(!MOZILLA)
	{
		this.highlightsXML.load("./Home/Data/Highlights.xml");
		loadXML();
	}
	else
	{
		//this.GetElementByID("AdRotatorBox").style.display = "";
		xmlDoc=loadXMLDoc("./Home/Data/Highlights.xml");
		x=xmlDoc.getElementsByTagName("ImageUrl");
		y=xmlDoc.getElementsByTagName("NavigateUrl");
		z=xmlDoc.getElementsByTagName("AlternateText");
		for(i=0;i<x.length;i++)
		{
			specifyimage[i] = "http://www.newinchess.com/Home/Images/Highlights/" + x[i].childNodes[0].nodeValue; 
			productids[i] = y[i].childNodes[0].nodeValue; 
			altertext[xmlCount] = z[i].childNodes[0].nodeValue; 
			cubeimage[i]=new Image();
			cubeimage[i].src=specifyimage[i];
		}
		xmlCount = x.length;
		this.count = Math.floor(Math.random()* xmlCount);

		document.images.cube.src=cubeimage[this.count].src;
		this.GetElementByID("Rotator").href=productids[this.count]+ " ";
		this.GetElementByID("rotatorbox").style.display = "";

		this.count++;
		if (this.count==xmlCount) this.count=0;
		setTimeout("movecube()",delay);
	}
}
// 
function shownext()
{
	return;
	this.curImage++;
	if(this.curImage > this.maxImages) this.curImage = 1
	this.GetElementByID('Image2').src = "Home/Images/image_" + curImage + ".jpg";
	this.GetElementByID('Textfield').innerHTML = this.imageText[this.curImage];
}
function loadXMLDoc(dname)
{
	if (window.XMLHttpRequest)
	{
		xhttp=new XMLHttpRequest();
	}
	else
	{
		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;
} 

