/*
	News Scroller

	version 1.000

	Copyright (c) 2005 Josh Dechant.

  Released under the GNU General Public License
*/

function newsScroller(TheID, TheHeight, TheWidth, TheScrollAmount, TheScrollDelay, TheHtml, TheScrollerName) {
  ScrollerID = TheID;
  ScrollerAmount = (TheScrollAmount ? TheScrollAmount : 5);
  ScrollerDelay = (TheScrollDelay ? TheScrollDelay : 50);
  ScrollerName = TheScrollerName;
  ScrollerHtml  = TheHtml;

	ScrollerIEDOM = ((document.all || document.getElementById) ? true : false);

	//slow speed down by 1 for NS
	ScrollerAmount = ((document.all) ? ScrollerAmount : Math.max(1, ScrollerAmount - 1));

	ScrollerCopyAmount = ScrollerAmount;
	ScrollerPauseAmount = 0;

  if (typeof(TheHeight) == 'number') {
    ScrollerHeight = TheHeight;
    ScrollerHeightUnit = 'px';
  } else if (typeof(TheHeight) == 'string') {
    ScrollerHeight = parseInt('0' + TheHeight, 10);
    ScrollerHeightUnit = TheHeight.toLowerCase().replace(/^[0-9]+/, '');
  } else {
    ScrollerHeight = 200;
    ScrollerHeightUnit = 'px';
  }

  if (typeof(TheWidth) == 'number') {
    ScrollerWidth = TheWidth;
    ScrollerWidthUnit = 'px';
  } else if (typeof(TheWidth) == 'string') {
    ScrollerWidth = parseInt('0' + TheWidth, 10);
    ScrollerWidthUnit = TheWidth.toLowerCase().replace(/^[0-9]+/, '');
  } else {
    ScrollerWidth = 100;
    ScrollerWidthUnit = 'px';
  }

	ScrollerCombinedCSS = 'width: ' + ScrollerWidth + ScrollerWidthUnit + '; height: ' + ScrollerHeight + ScrollerHeightUnit + ';';

	if (ScrollerIEDOM == true) {
		document.write('<div id="' + ScrollerID + '" style="visibility: hidden; position: absolute; top: -100px; left: -10000px;">' + ScrollerHtml + '<\/div>');
	}

	ScrollerActualHeight = '';

	if (window.addEventListener) {
		window.addEventListener('load', ScrollerPopulate, false);
		window.addEventListener('unload', ScrollerSaveLastMsg, false);
	} else if (window.attachEvent) {
		window.attachEvent('onload', ScrollerPopulate);
		window.attachEvent('onunload', ScrollerSaveLastMsg);
	} else if (document.all || document.getElementById) {
		window.onload = ScrollerPopulate;
		window.onunload = ScrollerSaveLastMsg;
	}
}

function ScrollerPopulate() {
	ScrollerContainerDiv = ScrollerGetElm(ScrollerID + 'Container');

	ScrollerDiv = ScrollerGetElm(ScrollerID);

	ScrollerContainerDiv.style.top = ScrollerHeight  + ScrollerHeightUnit;

	if (ScrollerGetCookie('newsScrollerLastPos') != '') {
		ScrollerRememberLastMsg();
	}

	ScrollerContainerDiv.innerHTML = ScrollerHtml;

	ScrollerActualHeight = ScrollerDiv.offsetHeight;

	ScrollerTime = setInterval("ScrollerScroll()", ScrollerDelay);
}

function ScrollerGetElm(id) {
	var elm = null;

	if (document.getElementById) {
		elm = document.getElementById(id);
	} else {
		elm = document.all[id];
	}

	return elm;
}

function ScrollerGetCookie(Name) {
	var search = Name + '=';
	var returnvalue = '';
	var offset;
	var end;

	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);

		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);

			if (end == -1) {
				end = document.cookie.length;
			}

			returnvalue = unescape(document.cookie.substring(offset, end));
		}
	}

	return returnvalue;
}

function ScrollerSaveLastMsg() {
	document.cookie = 'newsScrollerLastPos=' + ScrollerContainerDiv.style.top;
}

function ScrollerRememberLastMsg() {
	var lastPosition;

	lastPosition = parseInt(ScrollerGetCookie("newsScrollerLastPos"));

	//ScrollerContainerDiv.style.top = parseInt(lastPosition) + 'px';
}

function ScrollerScroll() {
	if (parseInt(ScrollerContainerDiv.style.top) > (ScrollerActualHeight*(-1)-ScrollerHeight-8)) {
		ScrollerContainerDiv.style.top = parseInt(ScrollerContainerDiv.style.top) - ScrollerCopyAmount + 'px';
	} else {
		ScrollerContainerDiv.style.top = parseInt(ScrollerHeight) + ScrollerCopyAmount + ScrollerHeightUnit;
	}
}

function newsScroller_init() {
	if (ScrollerIEDOM) {
		with (document) {
			write('<div style="position: relative; overflow: hidden; '+ ScrollerCombinedCSS +'" onmouseover="ScrollerCopyAmount=ScrollerPauseAmount" onmouseout="ScrollerCopyAmount=ScrollerAmount">');
			write('<div id="' + ScrollerID + 'Container" style="position: absolute; left: 0px; top: 0px;"><\/div>');
			write('<\/div>');
		}
	}
}

function newsScroller_2(TheID, TheHeight, TheWidth, TheScrollAmount, TheScrollDelay, TheHtml, TheScrollerName) {
	  ScrollerID2 = TheID;
	  ScrollerAmount2 = (TheScrollAmount ? TheScrollAmount : 5);
	  ScrollerDelay2 = (TheScrollDelay ? TheScrollDelay : 50);
	  ScrollerName2 = TheScrollerName;
	  ScrollerHtml2  = TheHtml;

		ScrollerIEDOM2 = ((document.all || document.getElementById) ? true : false);

		//slow speed down by 1 for NS
		ScrollerAmount2 = ((document.all) ? ScrollerAmount2 : Math.max(1, ScrollerAmount2 - 1));

		ScrollerCopyAmount2 = ScrollerAmount2;
		ScrollerPauseAmount2 = 0;

	  if (typeof(TheHeight) == 'number') {
	    ScrollerHeight2 = TheHeight;
	    ScrollerHeightUnit2 = 'px';
	  } else if (typeof(TheHeight) == 'string') {
	    ScrollerHeight2 = parseInt('0' + TheHeight, 10);
	    ScrollerHeightUnit2 = TheHeight.toLowerCase().replace(/^[0-9]+/, '');
	  } else {
	    ScrollerHeight2 = 200;
	    ScrollerHeightUnit2 = 'px';
	  }

	  if (typeof(TheWidth) == 'number') {
	    ScrollerWidth2 = TheWidth;
	    ScrollerWidthUnit2 = 'px';
	  } else if (typeof(TheWidth) == 'string') {
	    ScrollerWidth2 = parseInt('0' + TheWidth, 10);
	    ScrollerWidthUnit2 = TheWidth.toLowerCase().replace(/^[0-9]+/, '');
	  } else {
	    ScrollerWidth2 = 100;
	    ScrollerWidthUnit2 = 'px';
	  }

		ScrollerCombinedCSS2 = 'width: ' + ScrollerWidth2 + ScrollerWidthUnit2 + '; height: ' + ScrollerHeight2 + ScrollerHeightUnit2 + ';';

		if (ScrollerIEDOM2 == true) {
			document.write('<div id="' + ScrollerID2 + '" style="visibility: hidden; position: absolute; top: -100px; left: -10000px;">' + ScrollerHtml2 + '<\/div>');
		}

		ScrollerActualHeight2 = '';

		if (window.addEventListener) {
			window.addEventListener('load', ScrollerPopulate_2, false);
			window.addEventListener('unload', ScrollerSaveLastMsg_2, false);
		} else if (window.attachEvent) {
			window.attachEvent('onload', ScrollerPopulate_2);
			window.attachEvent('onunload', ScrollerSaveLastMsg_2);
		} else if (document.all || document.getElementById) {
			window.onload = ScrollerPopulate_2;
			window.onunload = ScrollerSaveLastMsg_2;
		}
	}

	function ScrollerPopulate_2() {
		ScrollerContainerDiv2 = ScrollerGetElm(ScrollerID2 + 'Container');

		ScrollerDiv2 = ScrollerGetElm(ScrollerID2);

		ScrollerContainerDiv2.style.top = ScrollerHeight2  + ScrollerHeightUnit2;

		if (ScrollerGetCookie('newsScrollerLastPos2') != '') {
			ScrollerRememberLastMsg();
		}

		ScrollerContainerDiv2.innerHTML = ScrollerHtml2;

		ScrollerActualHeight2 = ScrollerDiv2.offsetHeight;

		ScrollerTime2 = setInterval("ScrollerScroll_2()", ScrollerDelay2);
	}

	function ScrollerGetElm_2(id) {
		var elm = null;

		if (document.getElementById) {
			elm = document.getElementById(id);
		} else {
			elm = document.all[id];
		}

		return elm;
	}

	function ScrollerGetCookie_2(Name) {
		var search2 = Name + '=';
		var returnvalue2 = '';
		var offset2;
		var end2;

		if (document.cookie.length > 0) {
			offset2 = document.cookie.indexOf(search2);

			if (offset2 != -1) {
				offset2 += search2.length;
				end2 = document.cookie.indexOf(";", offset2);

				if (end2 == -1) {
					end2 = document.cookie.length;
				}

				returnvalue2 = unescape(document.cookie.substring(offset2, end2));
			}
		}

		return returnvalue2;
	}

	function ScrollerSaveLastMsg_2() {
		document.cookie = 'newsScrollerLastPos2=' + ScrollerContainerDiv2.style.top;
	}

	function ScrollerRememberLastMsg_2() {
		var lastPosition2;

		lastPosition2 = parseInt(ScrollerGetCookie("newsScrollerLastPos2"));

		ScrollerContainerDiv2.style.top = parseInt(lastPosition2) + 'px';
	}

	function ScrollerScroll_2() {
		if (parseInt(ScrollerContainerDiv2.style.top) > (ScrollerActualHeight2*(-1)-ScrollerHeight2 - 8)) {
			ScrollerContainerDiv2.style.top = parseInt(ScrollerContainerDiv2.style.top) - ScrollerCopyAmount2 + 'px';
		} else {
			ScrollerContainerDiv2.style.top = parseInt(ScrollerHeight2) + ScrollerCopyAmount2 + ScrollerHeightUnit2;
		}
	}

	function newsScroller_init_2() {
		if (ScrollerIEDOM2) {
			with (document) {
				write('<div style="position: relative; overflow: hidden; '+ ScrollerCombinedCSS2 +'" onmouseover="ScrollerCopyAmount2=ScrollerPauseAmount2" onmouseout="ScrollerCopyAmount2=ScrollerAmount2">');
				write('<div id="' + ScrollerID2 + 'Container" style="position: absolute; left: 0px; top: 0px;"><\/div>');
				write('<\/div>');
			}
		}
	}
