var scroll_layers = new Array();
var scrollcontainerwidth = 300;
var scrollcontainerheight = 13;
var scrollcontainer = false;
var scrollcontainerpos = false;
// var scrollcontent = false;
var scrollcurrentx = 0;
var scrollcurrenty = 0;
var scrollspeedy = 0; // vertical pixels to move per repeat
var scrollspeedx = 2; // horizontal pixels to move per repeat
var scrollrepeat = 20; // milliseconds per repeat
var scrollmove = false;
var scrollinit = false;
var current = 0;
var current_end = 0;

function init() {
	var noscroll = false;
	scrollcontainer = gE('scrollcontainer');
	if (!scrollcontainer) {
		scrollcontainer = gE('scrollstatic');
		noscroll = true;
	}
	if (scrollcontainer) {
		pos = getPos('newsticker');
		pos[0]+=70;
		pos[1]-=9;
		pos = adjustPosition(pos);
		scrollcontainerpos = pos;
		scrollcontainer = scrollcontainer;
		scrollcontent = contentInit();
		if (scrollcontent) {
			sS(scrollcontainer,scrollcontainerwidth,scrollcontainerheight);
			sC(scrollcontainer,0,scrollcontainerwidth,scrollcontainerheight,0);
			sP(scrollcontainer, pos[0], pos[1]);
			sE(scrollcontainer);
			if (noscroll == false) {
				scrollmove = true;
				scrollinit = true;
				sE(scrollcontent.el);
				scroll(scrollcontent);
			} else {
				sX(scrollcontent.el, 0);
				sE(scrollcontent.el);
			}
		}
	}
}

function contentInit() {
	scrollcontent = scroll_layers[current];
	scrollcurrentx = 378;
	scrollcontent.el.style.width = 'auto';
	sX(scrollcontent.el, scrollcurrentx);
	// pos = getPos(scrollcontent.id+'img');
	current_end = 0 - scrollcontent.width - 50;
	sE(scrollcontent.el);
	return scrollcontent;
}

function scroll(scrollcontent) {
	if (scrollinit) {
		scrollcurrentx -= scrollspeedx;
		scrollcurrenty += scrollspeedy;
		
		sP(scrollcontent.el,scrollcurrentx,scrollcurrenty);
		// imgpos = getPos(scroll_layers[current].id+'img', scroll_layers[current].id);
		if (scrollmove) {
			if (scrollcurrentx < current_end){
				setTimeout("contentScroll()", 0);//mod zero relative to px length of string relative to window  position from edge  (windowpos -string length)
			} else {
				setTimeout("scroll(scrollcontent)",scrollrepeat);
			}
		}
	}
}

function contentScroll() {
	scrollcontent = scroll_layers[current];
	hE(scrollcontent.el);
	current+=1;
	if (current >= scroll_layers.length) {
		current = 0;
	}
	scrollcontent = contentInit();
	setTimeout("scroll(scrollcontent)",100);
}

function addScrollerContent(id) {
	contentobj = {id:null,el: null,width: 0}
	contentobj.id = id;
	contentobj.el = gE(id);
	if (!contentobj.el) {
		return false;
	}
	pos = getPos(id+'img');
	contentobj.width = pos[0];
	if (contentobj) {
		scroll_layers[scroll_layers.length] = contentobj;
	}
}

function adjustPosition(pos) {
	if (ie && ua.indexOf('win')>-1) {
		if (ua.indexOf('msie 5.0')!=-1 || ua.indexOf('msie 5.5')!=-1) {
			pos[0]-=6;
			pos[1]-=7;
		} else {
			pos[0]+=4;
			pos[1]-=7;
		}
	} else if (ie && ua.indexOf('mac')>-1) {
		pos[0]-=0;
		pos[1]+=1;
	} else if (nn) {
		pos[0]-=23;
		pos[1]-=12;
	} else if (ua.indexOf('gecko')>-1 && ua.indexOf('khtml')==-1) {
		pos[0]-=4;
		pos[1]-=7;
	} else {
		pos[0]+=4;
		pos[1]-=7;
	}
	return pos;
}

// initialize scroller
if (typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', init, false);
} else if (typeof window.attachEvent != "undefined") { // IE
	window.attachEvent('onload', init);
} else {
	if (window.onload != null) {
		// maintain any other onload events
		var oldOnload = window.onload;
		window.onload = function (e) {
			oldOnload(e);
			init();
		};
	} else {
		window.onload = init;
	}
}
