var runTimer=0;
var animTimer=0;
var dt=40;
var alphaStep=0.25;
var currentAlpha=1;
var nextImgIdx='';
var currentImgIdx='';

/*	nextIdx - images array index of new image
	imgName - name of image, which should be change in document
	divID - if <> '', then change will be animated. Image in document have to be 
			encapsulate in div with divID
	Array with images have to be defined (preloded) in document
*/
function changeImg(nextIdx, imgName, divID)
{
	nextImgIdx=nextIdx;
	if(nextImgIdx==currentImgIdx) return;
	//document[imgName].src = pics[nextImgIdx].src;
	//return;
	
	if(divID!='')
	{
		if(!runTimer) // if timer is stopped
		{
			runTimer=-1; // div goes transparent
			funcStr="animateDivAlpha('" + imgName + "','" + divID + "');";
			animTimer=setTimeout(funcStr,dt);
		}
		else if(runTimer>0) // if div is showing up
		{
			runTimer=-1; // div goes transparent
		}
	}
}

function animateDivAlpha(imgName, divID)
{
	el=document.getElementById(divID);
	currentAlpha+=(runTimer*alphaStep);
	if(currentAlpha>=1)
	{
		runTimer=0;
		currentAlpha=1;
	}
	else if(currentAlpha<=0)
	{
		runTimer=1;
		currentAlpha=0;
		currentImgIdx=nextImgIdx;
		img=document.getElementById('bigPhotoImg');
		if(img) img.src=pics[nextImgIdx].src;
		/*
		if (document.images)
	    {
			document[imgName].src = pics[nextImgIdx].src;
	    }
	    */
	}
	ieOpacity=currentAlpha*100;
	el.style.filter = "alpha(opacity=" + ieOpacity.toFixed(2) + ")";
	el.style.MozOpacity = currentAlpha;
	el.style.KHTMLOpacity = currentAlpha;
	el.style.opacity = currentAlpha;
	if(runTimer!=0){
		funcStr="animateDivAlpha('" + imgName + "','" + divID + "');";
		animTimer=setTimeout(funcStr,dt);
	}
	else clearTimeout(animTimer);
	
}
