﻿/* =======================================================
* ypSimpleScroll
* 3/11/2001
* 
* http://www.youngpup.net/
* ======================================================= */

// Modified by Sergi Meseguer (www.zigotica.com) 04/2004
// Now it works with dragger and can use multiple instances in a page



ypSimpleScrollMulti.prototype.scrollNorth = function(count) { this.startScroll(90, count) }
ypSimpleScrollMulti.prototype.scrollSouth = function(count) { this.startScroll(270, count) }
ypSimpleScrollMulti.prototype.scrollWest = function(count) { this.startScroll(180, count) }
ypSimpleScrollMulti.prototype.scrollEast = function(count) { this.startScroll(0, count) }

ypSimpleScrollMulti.prototype.startScroll = function(deg, count) {
	if (this.loaded){
		if (this.aniTimer) window.clearTimeout(this.aniTimer)
		this.overrideScrollAngle(deg)
		this.speed = this.origSpeed
		this.lastTime = (new Date()).getTime() - this.y.minRes
		this.aniTimer = window.setTimeout(this.gRef + ".scroll('"+deg+"','"+count+"')", this.y.minRes)
	}
}

ypSimpleScrollMulti.prototype.endScroll = function() {
	if (this.loaded){
		window.clearTimeout(this.aniTimer)
		this.aniTimer = 0;
		this.speed = this.origSpeed
	}
}

ypSimpleScrollMulti.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
	}
}

ypSimpleScrollMulti.prototype.overrideScrollSpeed = function(speed) {
	if (this.loaded) this.speed = speed
}


ypSimpleScrollMulti.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)
		}
	}
}

ypSimpleScrollMulti.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"
		}
	}
}

ypSimpleScrollMulti.minRes = 10
ypSimpleScrollMulti.ie = document.all ? 1 : 0
ypSimpleScrollMulti.ns4 = document.layers ? 1 : 0
ypSimpleScrollMulti.dom = document.getElementById ? 1 : 0
ypSimpleScrollMulti.mac = navigator.platform == "MacPPC"
ypSimpleScrollMulti.mo5 = document.getElementById && !document.all ? 1 : 0

ypSimpleScrollMulti.prototype.scroll = function(deg,count) {
	this.aniTimer = window.setTimeout(this.gRef + ".scroll('"+deg+"','"+count+"')", 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)
		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
		}
	}
}

function ypSimpleScrollMulti(id, left, top, width, height, speed) {
	var y = this.y = ypSimpleScrollMulti
	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 = 0
		this.scrollLeft = 0
		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:' + (-this.scrollLeft) + 'px; top:' + (-this.scrollTop) + 'px; width:' + width + 'px; }')
		// (zgtc) fix to overwrite p/div/ul width (would be clipped if wider than scroller in css):
		d.write('#' + this.id + 'Container p, #' + this.id + 'Container div {width:' + parseInt(width-10) + 'px; }')
		d.write('</style>')
	}
}

ypSimpleScrollMulti.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)
}

// ==============================================================
// HANDLES SCROLLER/S
// Modified from Aaron Boodman http://webapp.youngpup.net/?request=/components/ypSimpleScroll.xml
// mixed ypSimpleScroll with dom-drag script and allowed multiple scrolelrs through array instances
// (c)2004 Sergi Meseguer (http://zigotica.com/), 04/2004:
// ==============================================================
var theHandleMulti = []; var theRootMulti = []; var theThumbMulti = []; var theScrollMulti = []; var thumbTravelMulti = []; var ratioMulti = [];

function instantiateScrollerMulti(count, id, left, top, width, height, speed){
	if(document.getElementById) {
		theScrollMulti[count] = new ypSimpleScrollMulti(id, left, top, width, height, speed);
	}
}

function createDraggerMulti(count, handler, root, thumb, minX, maxX, minY, maxY){
		var buttonsMulti = '<div class="scrollUp" id="Multiup'+count+'"><a href="#" onmouseover="theScrollMulti['+count+'].scrollNorth(\''+count+'\')" onmouseout="theScrollMulti['+count+'].endScroll()" onclick="return false;"><img src="/images/tylenol/arw_scr_up_on.gif" width="6" height="5" id="arw_scr_up" /></a></div>'+
						   '<div class="scrollDn" id="Multidn'+count+'"><a href="#" onmouseover="theScrollMulti['+count+'].scrollSouth(\''+count+'\')" onmouseout="theScrollMulti['+count+'].endScroll()" onclick="return false;"><img src="/images/tylenol/arw_scr_dn_on.gif" width="6" height="5" id="arw_scr_dn" /></a></div>';

		document.getElementById(root).innerHTML = buttonsMulti + document.getElementById(root).innerHTML;

		theRootMulti[count]   = document.getElementById(root);

		var thisupMulti = document.getElementById("Multiup"+count);
		thisupMulti.style.top = 0 + "px";
		thisupMulti.style.left = parseInt(minX) + "px";

		var thisdnMulti = document.getElementById("Multidn"+count);
		thisdnMulti.style.left = parseInt(minX) + "px";
		thisdnMulti.style.top = parseInt(minY+maxY) + "px";

		theScrollMulti[count].load();
}	

// INITIALIZER:
// ==============================================================
// ala Simon Willison http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(fn) {
      var old = window.onload;
      if (typeof window.onload != 'function') {
         window.onload = fn;
      }
      else {
         window.onload = function() {
         old();
         fn();
         }
      }
   }
addLoadEvent(function(){
		if(theScrollMulti.length>0) {
		for(var i=1;i<theScrollMulti.length;i++){
			createDraggerMulti(i, "handle"+i, "root"+i, "thumb"+i, theScrollMulti[i].clipW, theScrollMulti[i].clipW, 0, theScrollMulti[i].clipH-5);
		}
	}
})
