//  T i c k e r

// The following could go inline in the header:   (HTML is supported in text) 
/* **************************************************************
var tcontent = new TickerContent();
tcontent.addNew("Contact Information","8contact.html");
tcontent.addNew("Volunteer Opportunities","7volunteer.html");
tcontent.addNew("Sponsors & Donors","6sponsors.html");
tcontent.addNew("Links","9links.html");
tcontent.addNew("Registration Information","5register.html");
tcontent.addNew("Bulletin","4bulletin.html");
tcontent.addNew("Directions","2directions.html");  */
// tickername = new Ticker(tickername, mode, div_id, tickercontent);
/*
ticker1 = new Ticker("ticker1", "fade", "tcid", "tcontent");
*/
// Style Sheet - set a style for each "container div" by id or by class
/* **************************************************************
.tclass{position:relative; overflow:hidden; 
	top:50px; left:50px;  
	width:150px;height:30px;
	cursor:pointer;
	}
******************************************************************/
// the following should appear within the html page
/* --------------------------------------------------------------

<body onload="ticker1.displayTicker();">

<div id=tcid class=tclass></div>
 --------------------------------------------------------------*/
function TickerContent(){
   this.tc_text     = new Array();
   this.tc_URL      = new Array ();
   this.tc_target   = new Array ();
   this.tc_tickerMax 	= 0;   // how many text/URLs in this ticker -1
   // methods:
   this.addNew         = addNew;
}
function addNew(txt,URL,target) {
	this.tc_text[this.tc_tickerMax] = txt;
	this.tc_URL[this.tc_tickerMax] = URL;
	if (target) {
		if (target != 1){
			this.tc_target[this.tc_tickerMax] = 0;
		}
	} else {
		this.tc_target[this.tc_tickerMax] = 0;
	}
	this.tc_tickerMax++;
}

function Ticker(varname, mode, container, content) {
   // properties:
   this.rd_varname	= varname;       // hold the variable name.. until we learn how to get it from the window!
   this.rd_containerId	= container;     // the ID of the container for the ticker. Not the Ticker Object ID itself
   this.rd_innerDivId	= container+"_son";
   this.rd_content	= eval(content);     //reference to the tickercontent object
   this.rd_mode 	= mode;    //fade, shuffle, scrollright or scrolldown
   this.rd_tickerno	= 0;   // count used to update fade 
   this.rd_colorVal	= 15;  // color value
   this.rd_refresh	= true;    // boolean for mouseover and mouseout pause / resume function
   this.rd_timeOutVal	= 300;    // Delay in milliseconds
   this.rd_modeUse	= 0;      // width of window for scrollright ticker, counter for shuffle ticker
   
   // methods:

   this.setNodeEvents	= setNodeEvents;
   this.refreshTicker	= refreshTicker;
   this.displayTicker	= displayTicker;
   this.execFade	= execFade;
   this.execDown	= execDown;
   this.execRight 	= execRight;
   this.execShuffle 	= execShuffle;
   this.buildDiv 	= buildDiv;
   this.setHexColor	= setHexColor;
   this.setPause	= setPause;
   this.setResume	= setResume;
   this.eventAdd	= eventAdd;
}
 
//  *****  METHODS  *****

/* 
   this method adds text, URL, target indicator 
   and behavior indicator
   to ticker arrays        */

/* 
   this method is executed once to set the onmouseover and onmouseout events to ticker <DIV id=id>         */
function setNodeEvents(Obj){
	var refnode = document.getElementById(Obj.rd_containerId);
	refnode.innerHTML=Obj.buildDiv();   //this builds the inner DIV
	var refnode2 = document.getElementById(Obj.rd_innerDivId);
	var fname = Obj.rd_varname+".setPause("+Obj.rd_varname+")";
	eventAdd(refnode,"onmouseover",fname);
	
	var fname = Obj.rd_varname+".setResume("+Obj.rd_varname+")";
	eventAdd(refnode,"onmouseout",fname);
	
	
	if(Obj.rd_content.tc_target[Obj.rd_tickerno] == 0)
	{
		eventAdd(refnode,"onclick",'location.href="'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'"')
	} else {
		eventAdd(refnode,"onclick",'window.open("'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'")')
	}
	if (Obj.rd_mode=="scrolldown"){
		Obj.rd_timeOutVal = 60;    // Delay in milliseconds
	}
	if (Obj.rd_mode=="scrollright"){
		refnode2.style.width=Obj.rd_modeUse;
		Obj.rd_timeOutVal = 20;    // Delay in milliseconds
	}   
	if (Obj.rd_mode=="shuffle"){
		Obj.rd_modeUse = 0;
		Obj.rd_timeOutVal = 30;    // Delay in milliseconds
	}   
}

function refreshTicker(Obj){
    var refnode = document.getElementById(Obj.rd_containerId);
    if (Obj.rd_mode=='fade'){
	    execFade(Obj);
    }
    if (Obj.rd_mode=='scrolldown'){
	    execDown(Obj);
    }
    if (Obj.rd_mode=='scrollright'){
	    execRight(Obj);
    }
    if (Obj.rd_mode=='shuffle'){
	    execShuffle(Obj);
    }

     if (Obj.rd_refresh){
	     setTimeout(function(){Obj.refreshTicker(Obj)},Obj.rd_timeOutVal);
     }
}

function displayTicker(){
    this.setNodeEvents(this);
    this.refreshTicker(this);
}

// ****** Setting Delay on MouseOver and MouseOut ******


function setPause(Obj) {
    Obj.rd_refresh = false;
}
    

function setResume(Obj){
    Obj.rd_refresh = true;
    setTimeout(function(){Obj.refreshTicker(Obj)},Obj.rd_timeOutVal);
}



// Generate a Hex Color from an Array 

function setHexColor(getColor) {
	var colorChoice = new Array(
		"ffccff",
		"eeccee",
		"ddccdd",
		"cccccc",
		"bb99bb",
		"aa99aa",
		"996699",
		"886688",
		"776677",
		"663366",
		"553355",
		"443344",
		"330033",
		"220022",
		"110011",
		"000000");
    return (colorChoice[getColor]);
}

function execFade(Obj){
    var refnode = document.getElementById(Obj.rd_containerId);
    refnode.innerHTML= '<font color="#' + 
    setHexColor(Obj.rd_colorVal) +
    '"><b>' + Obj.rd_content.tc_text[Obj.rd_tickerno] + '</b></font>';
    if(Obj.rd_colorVal > 0)
    {
	    Obj.rd_colorVal--;
    } else {
	    Obj.rd_colorVal=15;
	    if(Obj.rd_tickerno < (Obj.rd_content.tc_tickerMax - 1)) {
		    Obj.rd_tickerno++;
	    } else {
		    Obj.rd_tickerno = 0;
	    }
    }  
    if(Obj.rd_content.tc_target[Obj.rd_tickerno] == 0)
    {
	    Obj.eventAdd(refnode,"onclick",'location.href="'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'"')
    } else {
	    Obj.eventAdd(refnode,"onclick",'window.open("'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'")')
    }
}


function execDown(Obj){
	var refnode=document.getElementById(Obj.rd_innerDivId);
	if(refnode.style.top==""){refnode.style.top=0;}
	var x = refnode.offsetHeight;
	var y = parseInt(refnode.style.top)*(-1); 
	if(y > x){refnode.style.top=0;}
	var holdtop = parseInt(refnode.style.top);
	holdtop = holdtop - 1;
	refnode.style.top = holdtop+'px';
}

function execRight(Obj){
	var refnode=document.getElementById(Obj.rd_innerDivId);
	if(refnode.style.left==""){refnode.style.left=0;}
	var x = Obj.rd_modeUse;  //length of the horizontal inner div from BuildDiv() function
	var y = parseInt(refnode.style.left)*(-1); 
	if(y > x){refnode.style.left=0;}
	var holdleft = parseInt(refnode.style.left);
	holdleft--;
	refnode.style.left = holdleft+'px';
}

function execShuffle(Obj){
    var refnode = document.getElementById(Obj.rd_containerId);
    refnode.innerHTML= Obj.rd_content.tc_text[Obj.rd_tickerno].substring(0,Obj.rd_modeUse); 
    if(Obj.rd_content.tc_target[Obj.rd_tickerno] == 0)
    {
	    Obj.eventAdd(refnode,"onclick",'location.href="'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'"')
    } else {
	    Obj.eventAdd(refnode,"onclick",'window.open("'+Obj.rd_content.tc_URL[Obj.rd_tickerno]+'")')
    }
//  advance the ticker
    if (Obj.rd_modeUse < Obj.rd_content.tc_text[Obj.rd_tickerno].length){
	    Obj.rd_modeUse++;
	    Obj.rd_timeOutVal = 30;    // Delay in milliseconds
    }else{
	    Obj.rd_timeOutVal = 3000;    // Delay in milliseconds
	    Obj.rd_modeUse = 0;
	    if(Obj.rd_tickerno < (Obj.rd_content.tc_tickerMax - 1)) {
		    Obj.rd_tickerno++;
	    } else {
		    Obj.rd_tickerno = 0;
	    }
    }


}

function buildDiv(){
	var divstr = "<div class=\"tickercontent\" ";
	divstr+= "id=\""+this.rd_innerDivId+"\" ";
	divstr+= "style=\"position:relative; white-space:nowrap;\">";
	var spcr = "";
	var hlngth =0;
	if (this.rd_mode=='scrolldown'){
		spcr = "<br>";
	}else{ 
		if(this.rd_mode=='scrollright'){
		spcr = "&nbsp;&nbsp;&nbsp;";
		}
	}
	for(i=0;i<this.rd_content.tc_tickerMax;i++){
		divstr+=spcr+"<a href=\""+this.rd_content.tc_URL[i]+"\"";
		if (this.rd_content.tc_target[i] == 1){
			divstr+=" target=\"_blank\">";
		} else {
			divstr+=" target=\"_self\">";
		}
		divstr+=this.rd_content.tc_text[i]+"</a>"+spcr;
		hlngth+=this.rd_content.tc_text[i].length *7;
	}
	divstr+= "</div>";
	this.rd_modeUse = hlngth;
//	 	alert(divstr);
	return divstr;
}	

function eventAdd(objAttrib,handler,addFunction){
	if ((!document.all)&&(document.getElementById)){
		objAttrib.setAttribute(handler,addFunction);
	}
	//workaround for IE 5.x
	if ((document.all)&&(document.getElementById)){
		objAttrib[handler]=new Function(addFunction);
	}
}

