var HomePageClients = {
	prevBtn : null,
	nextBtn : null,
	containerWidth : 0,
	clientOffsetWidth : 0,
	currentCountryNumber : 0,
	countryLinks : Array(),
	//countryClientsContainerDIVs : Array(),

	init : function(){
		var homePageClientsAnimationUL = document.getElementById("homePageClientsAnimationUL");
		HomePageClients.containerWidth = homePageClientsAnimationUL.parentNode.offsetWidth;
		//homePageClientsAnimationUL.parentNode.style.height = "91px";
		homePageClientsAnimationUL.parentNode.style.height = "90px";
		homePageClientsAnimationUL.parentNode.style.overflow = "hidden";
		var countryLIs = homePageClientsAnimationUL.childNodes;
		var noOfClients = 0;
		for(var i = 0 ; i < countryLIs.length ; i++){
			if(countryLIs[i].nodeName == "LI"){
				var countryLI = countryLIs[i];
				countryLI.style.width = "auto";
				countryLI.style.display = "inline";
				countryLI.style.marginRight = "3px";
				var countryClientsA = countryLI.firstChild;
				if(countryClientsA.nodeName != "A"){
					countryClientsA = countryClientsA.nextSibling;
				}
				countryClientsA.style.cursor = "default";
				countryClientsA.onclick = HomePageClients.dummy;
				HomePageClients.countryLinks[HomePageClients.countryLinks.length] = countryClientsA;
				countryClientsA._parent = countryLI;
				var countryClientsContainerDIV = countryClientsA.nextSibling;
				if(countryClientsContainerDIV.nodeName != "DIV"){
					countryClientsContainerDIV = countryClientsContainerDIV.nextSibling;
				}
				countryClientsA._associatedDiv = countryClientsContainerDIV;
				countryClientsContainerDIV._parent = countryLI;
				//HomePageClients.countryClientsContainerDIVs[HomePageClients.countryClientsContainerDIVs.length] = countryClientsContainerDIV;
				countryClientsContainerDIV.style.position = "absolute";
				countryClientsContainerDIV.style.top = "25px";
				countryClientsContainerDIV.style.left = "0px";
				countryClientsContainerDIV.style.marginBottom = 0;
				//countryClientsContainerDIV.style.backgroundColor = "coral";
				var countryClientsContainerDIVUL = countryClientsContainerDIV.firstChild;
				if(countryClientsContainerDIVUL.nodeName != "UL"){
					countryClientsContainerDIVUL = countryClientsContainerDIVUL.nextSibling;
				}
				var clientLIs = countryClientsContainerDIVUL.childNodes;
				var tempWidth = 0;
				var actualClients = 0;
				for(var j = 0 ; j < clientLIs.length ; j++){
					if(clientLIs[j].nodeName == "LI"){
						actualClients++;
						noOfClients++;
						tempWidth = tempWidth + clientLIs[j].offsetWidth;
						HomePageClients.clientOffsetWidth = tempWidth;
					}
				}
				countryClientsContainerDIV.style.width = tempWidth + "px";
				countryClientsContainerDIV._width = tempWidth;
				countryClientsContainerDIV._clientLIs = actualClients;
			}
		}
		if(noOfClients > 3){
			var homePageClientsRightOuter = homePageClientsAnimationUL.parentNode.parentNode;
			homePageClientsRightOuter.style.position = "relative";
			homePageClientsRightOuter.style.cssFloat = "left";
			homePageClientsRightOuter.style.width = "558px";
			//homePageClientsRightOuter.style.border = "1px solid blue";
			
			/*			
			var prevBtn = document.createElement("a");
			prevBtn.className = "prevNextButton";
			
			var prevBtnChildImg = document.createElement("img");
			prevBtnChildImg.setAttribute("src", "/images/LeftRightNormalActiveBtns.png");
			prevBtnChildImg.setAttribute("alt", "<<");
			prevBtnChildImg.setAttribute("title", "Previous");
			prevBtnChildImg.style.position = "relative";
			prevBtnChildImg.style.left = "0px";

			prevBtn.appendChild(prevBtnChildImg);
			prevBtn._childImg = prevBtnChildImg;

			homePageClientsRightOuter.insertBefore(prevBtn, homePageClientsAnimationUL.parentNode);
			HomePageClients.prevBtn = prevBtn;
			
			//HomePageClients.enablePrevBtn();

			var nextBtn = document.createElement("a");
			nextBtn.className = "prevNextButton";
			
			var nextBtnChildImg = document.createElement("img");
			nextBtnChildImg.setAttribute("src", "/images/LeftRightNormalActiveBtns.png");
			nextBtnChildImg.setAttribute("alt", ">>");
			nextBtnChildImg.setAttribute("title", "Next");
			nextBtnChildImg.style.position = "relative";
			nextBtnChildImg.style.left = "-72px";
			
			nextBtn.appendChild(nextBtnChildImg);
			nextBtn._childImg = nextBtnChildImg;

			//nextBtn.style.left = "362px";
			nextBtn.style.left = "534px";
			
			homePageClientsRightOuter.appendChild(nextBtn);
			HomePageClients.nextBtn = nextBtn;
			
			//HomePageClients.enableNextBtn();
			*/
		}
		//for(var i = 0 ; i < HomePageClients.countryClientsContainerDIVs.length ; i++){
		for(var i = 0 ; i < HomePageClients.countryLinks.length ; i++){
			HomePageClients.countryLinks[i]._associatedDiv.style.left = HomePageClients.containerWidth + "px";
		}
		HomePageClients.animate();
	},
	
	showRandomDiv : function(){
		var x = Math.floor(Math.random() * HomePageClients.countryLinks.length);
		if(HomePageClients.countryLinks.length > 1){
			while(HomePageClients.currentCountryNumber == x){
				x = Math.floor(Math.random() * HomePageClients.countryLinks.length);
			}
		}
		HomePageClients.currentCountryNumber = x;
		
		var y = 0;
		if(HomePageClients.countryLinks[x]._associatedDiv._width > HomePageClients.containerWidth){
			y = Math.floor(Math.random() * HomePageClients.countryLinks[x]._associatedDiv._clientLIs) * HomePageClients.clientOffsetWidth;
			if(HomePageClients.countryLinks[x]._associatedDiv._width - y < HomePageClients.containerWidth){
				y = HomePageClients.countryLinks[x]._associatedDiv._width - HomePageClients.containerWidth;
			}
		}
		HomePageClients.showThisDiv(HomePageClients.countryLinks[x]._associatedDiv, y * -1);
	},
	
	showThisDiv : function(theDiv, leftOffset){
		Main.addClass(theDiv._parent, "active");
		var theDivShown = false;
		for(var i = 0 ; i < HomePageClients.countryLinks.length ; i++){
			var aDiv = HomePageClients.countryLinks[i]._associatedDiv;
			if(aDiv == theDiv){
				theDiv.style.display = "block";
				theDiv.style.opacity = "0";
				theDiv.style.filter = "alpha(opacity=0)";
				theDiv.style.left = leftOffset + "px";
				theDivShown = true;
				HomePageClients.slowShowDiv(theDiv, 0);
			}
			else{
				Main.removeClass(aDiv._parent, "active");
				if(theDivShown){
					aDiv.style.left = HomePageClients.containerWidth + "px";
				}
				else{
					aDiv.style.left = (-1 * aDiv._width) + "px";
				}
			}
		}
		//setTimeout( function(){ HomePageClients.animate(); }, 3000);
	},
	
	animate : function(){
		HomePageClients.showRandomDiv();
	},
	
	dummy : function(){
		return false;
	},
	
	slowShowDiv : function(elem, opacity){
		elem.style.opacity = opacity / 100;
		elem.style.filter = "alpha(opacity=" + opacity + ")";
		if(opacity < 100){
			setTimeout(function(){HomePageClients.slowShowDiv(elem, opacity+3);}, 50);
		}
		else{
			setTimeout(function(){HomePageClients.slowHideDiv(elem, 80);}, 1000);
		}
	},
	
	//FOR FADE IN FADE OUTS
	slowHideDiv : function(elem, opacity){
		elem.style.opacity = opacity / 100;
		elem.style.filter = "alpha(opacity=" + opacity + ")";
		if(opacity > 0){
			setTimeout(function(){HomePageClients.slowHideDiv(elem, opacity-1);}, 1);
		}
		else{
			elem.style.display = "none";
			//Common.animateFadeInFadeOutUL(container);
			//setTimeout( function(){ HomePageClients.animate(); }, 3000);
			HomePageClients.animate();
		}
	}
};

Main.start(HomePageClients)
