
function ajaxticker(inid,hh)
{
	this.happyhour = hh;
	this.ticked = false;
	this.id = inid;
	this.dynamic_size = false;
	this.narrow_env = false;
	this.paused = false;
	this.self = this;
	this.tickspeed = 1;
	this.limitsize = 1;
	this.ticktime = 50;
    this.timerinterval = 0;
	this.DynamicResize = function(speed)
	{
		this.dynamic_resize = true;
		if(speed==2) {
			this.narrow_env = true;
		}
	}

	this.Pause = function()
	{
		this.paused = true;
	}

	this.Resume = function(e)
	{
		// suppress events to our subelements
		var docObj = $(this.id);
		var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
		if ( reltg != null ) {
			while (reltg != docObj && reltg.nodeName != 'BODY')
				reltg= reltg.parentNode
		}
		if (reltg== docObj) return;

		this.paused = false;
	}

	this.SetSpeed = function(speed)
	{
		this.tickspeed = speed;
	}
	
    this.TickTime = function(timex)
    {
        this.ticktime = timex;
    }

	this.LimitSize = function(size) 
	{
		this.limitsize = size;
	}

	this.updateContent = function()
	{
		var docObj = $(this.id);
		TICKER_WIDTH = docObj.style.width;
		var savedHtml = docObj.innerHTML;
		var winW = 800;
		var winH = 600;
		var logoW = 175;
		var add_msg_text = 47;
		var ticker_page_space =95;

		// Firefox
		if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
			if(this.dynamic_resize) {
				winW = window.innerWidth;
				winH = window.innerHeight;
				if (this.limitsize) {
					TICKER_WIDTH = (winW - logoW)-ticker_page_space;
					//docObj.style.width = TICKER_WIDTH;
					if(this.happyhour == 1){
					    docObj.style.width = TICKER_WIDTH-100;
					}else{
					    docObj.style.width = TICKER_WIDTH+30;
					}
				} else {
					docObj.style.width =winW-125;
				}
			}
			docObj.update("<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'><SPAN ID='TICKER_BODY."+this.id+"' width='100%'>&nbsp;</SPAN></TD></TR></TABLE>");
		}
		// IE
		if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
			if(this.dynamic_resize) {
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
				if (this.limitsize) {
					TICKER_WIDTH = (winW - logoW)-ticker_page_space;
					if(this.happyhour == 1){
					    docObj.style.width = TICKER_WIDTH-65;
					}else{
                        docObj.style.width = TICKER_WIDTH+30;
                    }
				} else {
					docObj.style.width = winW-30-add_msg_text-add_msg_text;
				}
			}
		    docObj.update("<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'><SPAN ID='TICKER_BODY."+this.id+"' width='100%'>&nbsp;</SPAN></TD></TR></TABLE>");
        }

        $("TICKER_BODY."+this.id).update("<table cellpadding='0' cellspacing='0' border='0'><tr><td nowrap='nowrap'>"+savedHtml+"</td><td nowrap='nowrap'>"+savedHtml+"</td></tr></table>");
	    docObj.scrollLeft = 0;
		docObj.style.display="block";
		
        // alert("winW="+winW+" winH="+winH+" TICKER_WIDTH="+TICKER_WIDTH);
		// window.onresize = this.updateContent();

        this.start();
	}

	this.start = function() 
	{
        if (!this.timerinterval) {
		    var me = this;
            this.timerinterval = setInterval(function() { me.tick(me); }, me.ticktime);
        }
	}

	this.tick = function(me) 
	{
		var obj = $(me.id);
		if(!me.paused)
            obj.scrollLeft += me.tickspeed;
		if(obj.scrollWidth/2 > obj.offsetWidth) {
			if(obj.scrollLeft >= obj.scrollWidth/2) 
                obj.scrollLeft = 0; // big images
		} else {
			// this will jitter.  images too small. 
			if(obj.scrollLeft >= obj.scrollWidth-obj.offsetWidth) 
                obj.scrollLeft = 0;
		}
	}
}

