var objects = new Array();
var marqueePadding = 2;
var marqueeLen = 0;
var step = 1;
var timeout = 0;
var maxElementWidth = 0;

function marqueeInit() {
	marqueeResize();
	window.setTimeout("marqueeRedraw()", 0);
}


function marqueeResize() {
	var obj, j = 0, w;
	
	if ( !ie ) {
		i = 0;
		while( (obj = document.getElementById("c"+i)) != null ) {
			obj.style.width = obj.parentNode.offsetWidth;
			i++;
		}
	}
	i = 0, j = 0;
	while( (obj = document.getElementById("marqueeBlock"+i)) != null ) {
	//if(j>=800){obj.style.visibility="hidden";}
		//else {obj.style.visibility="visible";}
		obj.style.marginLeft = j + "px";
		j += obj.offsetWidth + marqueePadding;
		obj.style.visibility = "inherit";
		objects[i++] = obj;
		
		if (maxElementWidth < obj.offsetWidth)
			maxElementWidth = obj.offsetWidth;
	}
	w = document.getElementById("marquee-contener").offsetWidth;
	if ( j > w ) {
		marqueeLen = j - w;
	}
}

var g__i = 0;
function marqueeMove() {
//alert('move');
	var obj, x, w, s, hx;
	var maxWidth = document.getElementById("marquee-contener").offsetWidth;
	
	for(var i = 0; i < objects.length; i++) {
	
	//objH = document.getElementById("c"+i);	
	
	
		obj = objects[i];
		x = obj.style.marginLeft;
		
		s = new String(x);
		s = s.substr(0, s.length-2);
		x = new Number(s);
		x -= step;
		w = obj.__width;
		hx=obj.offsetLeft;
		
	//alert (hx);
	//if(hx==0){obj.style.visibility="hidden";}
	 // else {obj.style.visibility="visible";}
		if (!w) {
			w = obj.offsetWidth;
			if (w) obj.__width = w;
		}

		if ( x <= -maxElementWidth ) {
			x = maxWidth + marqueeLen;
			marqueeLen += w + marqueePadding;
			//alert(i);
			//if(i%10==0){obj.style.visibility="visible";}
			//else{obj.style.visibility="hidden";}
		}
		
//if(x==230){obj.style.visibility="hidden";}
//if(x==1000){obj.style.visibility="visible";}
		//if(x<300){obj.style.marginLeft=-600+x;}
		//alert(x);
		obj.style.marginLeft = x + "px";
	}
	if ( (marqueeLen -= step) < 0 ) {
		marqueeLen = 0;
		
	}
}

function marqueeRedraw() {
	marqueeMove();
	window.setTimeout("marqueeRedraw()", timeout);
}
