var ticketObject = new Object();
var minY = 240;
var callRate = 10;

ticketObject.scrollMain=function() {
	var rootElements = document.getElementsByTagName('html');
	this.windowHeight = rootElements[0].clientHeight;
	var scrollTop = rootElements[0].scrollTop;

	var newTargetY = minY;
	var ticketTooLarge = 0;
	if (maxTicketHeight > this.windowHeight)
		ticketTooLarge = maxTicketHeight-this.windowHeight;
	if (minY+ticketTooLarge-scrollTop < 0)
		newTargetY = scrollTop-ticketTooLarge;

	this.currentY = this.ticketDiv.style.pixelTop;
	if (this.currentY != newTargetY) {
		if (newTargetY != this.targetY) {
			this.targetY = newTargetY;
			this.slideInit( );
	
		}
		this.slide( );
	}
	// window.status='CurrentY: '+this.currentY+' newTargetY: '+newTargetY+' scrollTop: '+scrollTop+' windowHeight: '+this.windowHeight+' maxTicketHeight: '+maxTicketHeight;
}	

ticketObject.slideInit = function() {
	var now	= new Date( );
	this.A		= this.targetY - this.currentY;
	this.B		= Math.PI / ( 2 * this.slideTime );
	this.C		= now.getTime( );
	if (Math.abs(this.A) > this.windowHeight) {
		this.D = this.A > 0 ? this.targetY - this.windowHeight : this.targetY + this.windowHeight;
		this.A = this.A > 0 ? this.windowHeight : -this.windowHeight;
	} else {
		this.D = this.currentY;
	}
}


ticketObject.slide = function() {
	var now	= new Date( );
	var newY = this.A * Math.sin( this.B * ( now.getTime( ) - this.C ) ) + this.D;
	newY = Math.round( newY );
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY ))
		this.ticketDiv.style.pixelTop = newY;
}


ticketObject.slideDOM = function() {
	var y = minY;
	var ticketTooLarge = 0;
	if (maxTicketHeight > window.innerHeight)
		ticketTooLarge = maxTicketHeight-window.innerHeight;
	if (minY+ticketTooLarge-window.pageYOffset < 0)
		y = window.pageYOffset-ticketTooLarge;
	ticketObject.ticketDiv.style.top = y+'px';
}


function initBetTicketScrolling(ticketID) {
  	//----------------------------
	// For IE, onscroll calls the
	// BetTicketPos() method
	//----------------------------
	if (document.all)  {
		// IE Browser
		ticketObject.slideTime = 1200;
		ticketObject.ticketDiv = document.getElementById(ticketID);
		window.setInterval("ticketObject.scrollMain( )", callRate);
	} else if (document.getElementById) {
		// DOM Browser
		ticketObject.ticketDiv = document.getElementById(ticketID);
		window.setInterval("ticketObject.slideDOM()", callRate);
	} else {
		if (document.layers)
   			setInterval("BetTicketPos()", callRate);	
	}
}

