var FadeInterval
var FadeItem = 0;
var homeImg;
var homeCopy;

function callNextBGNoSel(){
	homeImg[FadeItem-1].morph({opacity:0,duration:1});
	homeCopy[FadeItem-1].morph({opacity:0,duration:1});
	FadeItem = (FadeItem == homeImg.length) ? 1 : FadeItem + 1;
	homeImg[FadeItem-1].morph({opacity:1,duration:1});
	homeCopy[FadeItem-1].morph({opacity:1,duration:1});	
	if(FadeInterval){
		clearInterval(FadeInterval);
	}
	FadeInterval = setInterval(callNextBGNoSel,8000);
}

window.addEvent('domready', function() {
	if($('rotatingBG') != null){
		homeImg = $$('#contentA .img_cms');
		homeCopy = $$('#contentA .txt_cms');
		//alert(homeImg.length);
		if(homeImg.length > 0){
			FadeItem = Math.floor(Math.random() * homeImg.length) + 1;
			for(i=0;i<homeImg.length;i++){
				if( homeImg[i] && homeCopy[i] ){
					homeImg[i].removeClass('hidden');
					homeCopy[i].removeClass('hidden');
					if( (i+1) != FadeItem){
						homeImg[i].setStyle('opacity', 0);
						homeCopy[i].setStyle('opacity', 0);
					}
				}
			}
		}
	}

	if($('listoflinks') != null){
		expandinglist($('listoflinks'), '');		
	}
});

window.addEvent('load', function() {
	 if(FadeItem > 0 && homeImg[0]){
		FadeInterval = setInterval(callNextBGNoSel,8000);
	 }
});
