var timeoutId = 0;
var stepX = 20;
var stepT = 1;

function SetMarginLeft(objectName, left, clear) {
	if (clear)
		clearTimeout(timeoutId);
	obj = document.getElementById(objectName);
	currLeft = parseInt(obj.style.marginLeft);
	nextLeft = parseInt(left);
	if (isNaN(currLeft)) currLeft = 0;
	if (isNaN(nextLeft)) nextLeft = 0;
	//window.alert(currLeft + " " + nextLeft);
	if (currLeft < nextLeft)
		obj.style.marginLeft = (currLeft + stepX > nextLeft ? nextLeft : currLeft + stepX) + 'px';
	else if (currLeft > nextLeft)
		obj.style.marginLeft = (currLeft - stepX < nextLeft ? nextLeft : currLeft - stepX) + 'px';
	if (currLeft != nextLeft)
		timeoutId = window.setTimeout("SetMarginLeft('" + objectName + "', '" + left + "', false)", stepT);
	return true;
}

var hT = new Array();
var sT = new Array();
var arrObjName = new Array();
var arrObjOpacity = new Array();
var arrObjObject = new Array();
var opOpStep = 0.05;
var opTimeStep = 25;
var opId;

function SetVisibleImg(objId) {
	clearTimeout(opId);
	OpacityManager(objId);
}

function SmoothShow(objId, x) { 
   var obj = arrObjObject[objId];
   if (obj == "undefined" || obj.style == "undefined")
      return false;
   op = (obj.style.opacity)?parseFloat(obj.style.opacity):parseInt(obj.style.filter)/100;      
   if(op < x)  
   { 
      clearTimeout(hT[objId]);
      op += opOpStep; 
      obj.style.opacity = op; 
      obj.style.filter='alpha(opacity='+op*100+')'; 
      arrObjOpacity[objId] = op;
      sT[objId] = setTimeout('SmoothShow(\''+objId+'\', '+x+')', opTimeStep); 
   } 
} 
	    
function SmoothHide(objId, x) { 
   var obj = arrObjObject[objId];
   if (obj == "undefined" || obj.style == "undefined")
      return false;
   op = (obj.style.opacity) ? parseFloat(obj.style.opacity) : parseInt(obj.style.filter)/100; 
   if(op > x)  
   { 
      clearTimeout(sT[objId]);
      op -= opOpStep; 
      obj.style.opacity = op; 
      obj.style.filter = 'alpha(opacity='+op*100+')'; 
      arrObjOpacity[objId] = op;
      hT[objId] = setTimeout('SmoothHide(\''+objId+'\', '+x+')', opTimeStep); 
   } 
}

function OpacityManager(objId) {
	for(i = 0; i < arrObjName.length; i++)
		if (i != objId)
			SmoothHide(i, 0);
	SmoothShow(objId, 1);
	next = objId + 1;
	if (next > arrObjName.length - 1)
		next = 0;
	opId = setTimeout('OpacityManager(' + next + ')', 5000);
} 
