// JScript File

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

       for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
   
    }
} 

function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}






function appendEventHandler(elementObject, eventName, functionObject)
{
    if(eventName.indexOf('on')==0)
    {
        appendEventHandler(elementObject, eventName.substring(2),functionObject);
        return;
    }
    if(document.addEventListener)
        elementObject.addEventListener(eventName,
            function (evt) {
                functionObject(elementObject, evt)
            }, false);
    else
        if(document.attachEvent)
            elementObject.attachEvent("on" + eventName,
            function () {
            functionObject(elementObject);
            }
    )
}


	function getElement(ID) {
		if( document.layers ) { //Netscape layers
			return document.layers[ID]; }
		if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
			return document.getElementById(ID); }
		if( document.all ) { //Proprietary DOM; IE4
			return document.all[ID]; }
		if( document[ID] ) { //Netscape alternative
			return document[ID]; }
		return false;
	}
	function getElementStyle(element){
	
		var dstyle;
		if( element==null ) return null;
		if( element.style ) { dstyle = element.style; } else {dstyle = element;}
		return dstyle;
				
	}

var NewsTicker = { 
         Scroll:function() {
               
               if(initScroll())
                   runScroll();
        	   	
        }
}

var sspeed=10;
var currentElemStyle = null;
var maxElemNumber = 0;
var StartNumber = 0
function initScroll(){
    var currElem = getElement('dropmsg' + 0);
    var currElemStyle;
    var thisElemNumber = 0;
    StartNumber = currentElemNumber;
    while(currElem!=null){
        currElem = getElement('dropmsg' + thisElemNumber);
        if(currElem==null) return true;        
        maxElemNumber = thisElemNumber;
        currElemStyle = getElementStyle(currElem);
        currElemStyle.display = 'none';
        thisElemNumber++;
    }  return false;     
}
function runScroll(){
    if(currentElemStyle!=null) {
        currentElemStyle.display = 'none';
    }
    var currElem = getElement('dropmsg' + currentElemNumber);
    if(currElem==null) { currentElem = 0;     
        return;  }     
    currElemStyle = getElementStyle(currElem);  
    currElemStyle.display = 'block';  
    currentElemStyle = currElemStyle;
    opacity('NewsTicker', 0, 100, 500);
    currentElemNumber--;
    if(currentElemNumber==-1) currentElemNumber = StartNumber;
    var t=setTimeout("runScroll();",sspeed * 1000)
    
}

function LoadOMDv2NewsPage(URL,Count,Index,Year,Month,NewsType)
{
   location.href="default.aspx?news=true&NewsArticle=" + URL + "&RecC=" + Count + "&RecInd=" + Index + "&RecYear=" + Year + "&RecMonth="+ Month +"&NewsType=" + NewsType;
}     

function LoadNewsPage(URL,Count,Index,Year,NewsType)
{
    location.href="default.aspx?news=true&NewsArticle=" + URL + "&RecC=" + Count + "&RecInd=" + Index + "&RecYear=" + Year +"&NewsType=" + NewsType;
}

ypSimpleScroll.prototype.scrollNorth = function() { this.startScroll(90) }
ypSimpleScroll.prototype.scrollSouth = function() { this.startScroll(270)  }
ypSimpleScroll.prototype.scrollWest  = function() { this.startScroll(180) }
ypSimpleScroll.prototype.scrollEast  = function() { this.startScroll(0)   }


ypSimpleScroll.prototype.startScroll = function(deg, speed) {
	if (this.loaded)
	{
		if (this.aniTimer) window.clearTimeout(this.aniTimer)
		this.overrideScrollAngle(deg)

		this.speed    = speed ? speed : this.origSpeed
		this.lastTime = (new Date()).getTime() - this.y.minRes
		this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
	}
}


ypSimpleScroll.prototype.endScroll = function() {
	if (this.loaded)
	{
		window.clearTimeout(this.aniTimer)
		this.aniTimer = 0;
		this.speed = this.origSpeed
	}
}


ypSimpleScroll.prototype.overrideScrollAngle = function(deg) {
	if (this.loaded)
	{
		deg = deg % 360
		if (deg % 90 == 0) {
			var cos = deg == 0  ? 1 : deg == 180 ? -1 : 0
			var sin = deg == 90 ? -1 : deg == 270 ? 1 : 0
		} else {
			var angle = deg * Math.PI / 180
			var cos   = Math.cos(angle)
			var sin   = Math.sin(angle)
			sin = -sin
		}
		this.fx = cos / (Math.abs(cos) + Math.abs(sin))
		this.fy = sin / (Math.abs(cos) + Math.abs(sin))
		this.stopH = deg == 90 || deg == 270 ? this.scrollLeft : deg < 90 || deg > 270 ? this.scrollW : 0
		this.stopV = deg == 0 || deg == 180 ? this.scrollTop : deg < 180 ? 0 : this.scrollH
	}
}


ypSimpleScroll.prototype.overrideScrollSpeed = function(speed) {
	if (this.loaded) this.speed = speed
}


ypSimpleScroll.prototype.scrollTo = function(stopH, stopV, aniLen) {
	if (this.loaded)
	{
		if (stopH != this.scrollLeft || stopV != this.scrollTop) {
			if (this.aniTimer) window.clearTimeout(this.aniTimer)
			this.lastTime = (new Date()).getTime()
			var dx = Math.abs(stopH - this.scrollLeft)
			var dy = Math.abs(stopV - this.scrollTop)
			var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))
			this.fx = (stopH - this.scrollLeft) / (dx + dy)
			this.fy = (stopV - this.scrollTop) / (dx + dy)
			this.stopH = stopH
			this.stopV = stopV
			this.speed = d / aniLen * 1000
			window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
		}
	}
}

ypSimpleScroll.prototype.jumpTo = function(nx, ny) { 
	if (this.loaded)
	{
		nx = Math.min(Math.max(nx, 0), this.scrollW)
		ny = Math.min(Math.max(ny, 0), this.scrollH)
		this.scrollLeft = nx
		this.scrollTop = ny
		if (this.y.ns4)this.content.moveTo(-nx, -ny)
		else {
			this.content.style.left = -nx + "px"
			this.content.style.top = -ny + "px"
		}
	}
}

ypSimpleScroll.minRes = 10
ypSimpleScroll.ie  = document.all ? 1 : 0
ypSimpleScroll.ns4 = document.layers ? 1 : 0
ypSimpleScroll.dom = document.getElementById ? 1 : 0
ypSimpleScroll.mac = navigator.platform == "MacPPC"
ypSimpleScroll.mo5 = document.getElementById && !document.all ? 1 : 0

// recursively calls itself to animate
ypSimpleScroll.prototype.scroll = function() {
	this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
	var nt = (new Date()).getTime()
	var d = Math.round((nt - this.lastTime) / 1000 * this.speed)
	if (d > 0)
	{
		var nx = d * this.fx + this.scrollLeft
		var ny = d * this.fy + this.scrollTop

		var xOut = (nx >= this.scrollLeft && nx >= this.stopH) || (nx <= this.scrollLeft && nx <= this.stopH)
		var yOut = (ny >= this.scrollTop && ny >= this.stopV)  || (ny <= this.scrollTop && ny <= this.stopV)
		//window.status = nx + " " + this.fx + " " + this.scrollLeft + " " + this.stopH + " | " + ny + " " + this.fy + " " + this.scrollTop + " " + this.stopV + " : " + d
		if (nt - this.lastTime != 0 &&
			((this.fx == 0 && this.fy == 0) ||
			 (this.fy == 0 && xOut) ||
			 (this.fx == 0 && yOut) ||
			 (this.fx != 0 && this.fy != 0 && xOut && yOut)))
		{
			this.jumpTo(this.stopH, this.stopV)
			this.endScroll()
		}
		else {
			this.jumpTo(nx, ny)
			this.lastTime = nt
		}
	}
}

// constructor
function ypSimpleScroll(id, left, top, width, height, speed, contentWidth, initLeft, initTop)
{
	var y = this.y = ypSimpleScroll
	if (!initLeft)     initLeft     = 0
	if (!initTop)      initTop      = 0
	if (!contentWidth) contentWidth = width

	// fix for netscape4 first-page bug.
	if (document.layers && !y.ns4) history.go(0)

	if (y.ie || y.ns4 || y.dom) {
		this.loaded		= false
		this.id			= id
		this.origSpeed	= speed
		this.aniTimer	= false
		this.op			= ""
		this.lastTime	= 0
		this.clipH		= height
		this.clipW		= width
		this.scrollTop	= initTop
		this.scrollLeft	= initLeft

		// global reference to this object
		this.gRef = "ypSimpleScroll_"+id
		eval(this.gRef+"=this")

		var d = document
		d.write('<style type="text/css">')
		d.write('#' + this.id + 'Container { left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(0 ' + width + ' ' + height + ' 0); overflow:hidden; }')
		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; }')
		d.write('#' + this.id + 'Content { left:' + (-initLeft) + 'px; top:' + (-initTop) + 'px; width:' + contentWidth + 'px; }')
		d.write('</style>')
	}
}

ypSimpleScroll.prototype.load = function() {
	var d, lyrId1, lyrId2

	d = document
	lyrId1 = this.id + "Container"
	lyrId2 = this.id + "Content"

	this.container	= this.y.dom ? d.getElementById(lyrId1) : this.y.ie ? d.all[lyrId1] : d.layers[lyrId1]
	this.content	= obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	this.docH		= Math.max(this.y.ns4 ? this.content.document.height : this.content.offsetHeight, this.clipH)
	this.docW		= Math.max(this.y.ns4 ? this.content.document.width  : this.content.offsetWidth,  this.clipW)
	this.scrollH	= this.docH - this.clipH
	this.scrollW	= this.docW - this.clipW
	this.loaded		= true
	this.scrollLeft = Math.max(Math.min(this.scrollLeft, this.scrollW),0)
	this.scrollTop  = Math.max(Math.min(this.scrollTop, this.scrollH),0)
	this.jumpTo(this.scrollLeft, this.scrollTop)
}


function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width:100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 30)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}



