﻿<!-- //

	var allScrollers = new Array();
	var scrollerCount = 0;

	function initScrollers() {
		// set up all types of scroller engines
		
		// horizontal scrollers
		if(document.getElementsByClassName) {
			findScrollers = document.getElementsByClassName("horizontalScroller");
		} else {
			findScrollers = getElementsByClass("horizontalScroller",document,"div");
		}
		for(x=0; x<findScrollers.length ;x++) {
			// create objects in an array
			allScrollers[scrollerCount] = new hScroller(findScrollers[x], scrollerCount);
			scrollerCount += 1;
			document.onmousedown = function(ev) {
				if (window.event) ev = window.event; 
				trigger = ev.srcElement? ev.srcElement : ev.target; 
				if(trigger.className == "scrollbarControl") {
					hs_activeIndex = parseFloat(trigger.id.substring(1,trigger.id.indexOf("_")));
					hs_activeButton = document.getElementById("h" + hs_activeIndex + "_control");
					hs_activeButton.className = "scrollbarControl active";
					document.onmousemove = captureMouse;
					return false;
				}
			}
			document.onmouseup = function() {
				if(hs_activeIndex >= 0) {
					hs_activeButton.className = "scrollbarControl";
					hs_activeIndex = -1;
					hs_activeButton = null;
					document.onmousemove = null;
					oldMouseX = -1;
					return false;
				}
			}
			function captureMouse(ev) { 
				ev = ev || window.event;
				if(hs_activeIndex >= 0) hs_updateDrag(ev);
				return false;
			}
		}
		
		// rotation scrollers
		if(document.getElementsByClassName) {
			findScrollers = document.getElementsByClassName("rotationScroller");
		} else {
			findScrollers = getElementsByClass("rotationScroller",document,"div");
		}
		for(x=0; x<findScrollers.length ;x++) {
			// create objects in an array
			allScrollers[scrollerCount] = new rScroller(findScrollers[x], scrollerCount);
			scrollerCount += 1;
		}
	}
	
	
	
	//****************************************
	//********** HORIZONTAL SCROLLER *********
	//****************************************
	
	var hs_activeIndex = -1;
	var hs_activeButton = null;
	var hs_pauseLength = 3000; 		// amount of milliseconds objects stay still
	var hs_moveUpdateInterval = 10; // amount of milliseconds between move updates
	var oldMouseX = -1;
	var hs_minX = 2;
	var hs_prevTouchX = null;
	var hs_prevTouchY = null;
	var touchMoved = false;
	
	function hScroller(getDiv, getIndex) {
		this.index = getIndex;
		if(iphoneMode) getDiv.className = "horizontalScroller iosScroller";
		getDiv.setAttribute("id","h" + this.index + "_scroller");
		this.oDiv = getDiv;
		this.oDivWidth = parseFloat(this.oDiv.offsetWidth);
		this.totalWidth = 0;
		// get all list items
		this.dList = getDiv.getElementsByTagName("DL")[0];
		this.dList.id = "hs_dl_" + this.index;
		this.allDDs = this.dList.getElementsByTagName("DD");
		// store base image sizes
		for (this.i=0; this.i < this.allDDs.length; this.i++) {
			checkImageSize(this.allDDs[this.i].getElementsByTagName("IMG")[0], 178, 118);
			this.allDDs[this.i].img = this.allDDs[this.i].getElementsByTagName("IMG")[0];
			if(this.allDDs[this.i].img.width < 100) {
				this.allDDs[this.i].style.width = 110 + "px";
			} else {
				this.allDDs[this.i].style.width = ((this.allDDs[this.i].img.width) + 10) + "px";
			}
			this.totalWidth += parseFloat(this.allDDs[this.i].offsetWidth) + 20;
		}
		if(this.totalWidth > (this.oDivWidth + 20)) {
			// add scrollbarContainer
			this.newDiv = document.createElement('div');
			this.divID = "h" + this.index + "_scrollbar";
			this.newDiv.setAttribute('id',this.divID);
			this.newDiv.setAttribute('class',"scrollbarContainer");
			this.oDiv.appendChild(this.newDiv);
			this.scrollbarContainer = document.getElementById("h" + this.index + "_scrollbar");
			this.scrollbarContainer.className = "scrollbarContainer";
			// add scrollbar control
			this.newDiv = document.createElement('a');
			this.divID = "h" + this.index + "_control";
			this.newDiv.setAttribute('id',this.divID);
			this.newDiv.setAttribute('class',"scrollbarControl");
			this.scrollbarContainer.appendChild(this.newDiv);
			this.scrollbarControl = document.getElementById("h" + this.index + "_control");
			this.scrollbarControl.className = "scrollbarControl";
			this.scrollbarX = hs_minX;
			// set button width
			this.scrollbarControlWidth = Math.floor(this.oDivWidth * (this.oDivWidth/this.totalWidth));
			this.scrollbarControl.style.width = this.scrollbarControlWidth + "px";
			this.slideDistance = this.oDivWidth - this.scrollbarControlWidth;
			this.hs_maxX = 958 - this.scrollbarControlWidth;
			// touch behaviours
			getDiv.ontouchstart = function(e) {
				e.preventDefault();
				trigger = e.target;
				while(trigger.className.indexOf("horizontalScroller") < 0) {
					trigger = trigger.parentNode;
				}
				hs_activeIndex = parseFloat(trigger.id.substring(1,trigger.id.indexOf("_")));
				hs_activeButton = document.getElementById("h" + hs_activeIndex + "_control");
				hs_activeButton.className = "scrollbarControl active";
				touchMoved = false;
			}
			getDiv.ontouchmove = function(e) {
				e.preventDefault();
				touchMoved = true;
				if(e.touches.length == 1) { // Only deal with one finger
					var touch = e.touches[0]; // Get the information for finger #1
					// store vales if start of touch
					if(hs_prevTouchX == null) {
						hs_prevTouchX = touch.pageX;
					 	hs_prevTouchY = touch.pageY;
					}
					// move image if touch has moved
					if(hs_prevTouchX != touch.pageX) {
						// calculate move distances
						moveX = hs_prevTouchX - touch.pageX; // reversed!
						scroller = allScrollers[hs_activeIndex];
						scroller.scrollbarX += moveX;
						hs_prevTouchX = touch.pageX;
						hs_move();
					}
					// check for vertical scroll
					if(hs_prevTouchY != touch.pageY) {
						scrollIncrement = hs_prevTouchY - touch.pageY;
						window.scrollBy(0,scrollIncrement);
						hs_prevTouchY = touch.pageY + scrollIncrement;
					}
				}
			}
			getDiv.ontouchend = function(e) {
				e.preventDefault();
				if(!touchMoved) {
					var touchedObject = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
					if(touchedObject.nodeType == 3) touchedObject = touchedObject.parentNode;
					var newEvent = document.createEvent('MouseEvents');
					newEvent.initEvent('click', true, true);
					touchedObject.dispatchEvent(newEvent);
				}
				hs_prevTouchX = null;
			  	hs_prevTouchY = null;
				hs_activeIndex = -1;
				hs_activeButton.className = "scrollbarControl";
				hs_activeButton = null;
				touchMoved = false;
			}
		}
		// find deepest DD and set area heights accordingly
		this.ddMaxDepth = parseFloat(this.dList.offsetHeight);
		if(this.scrollbarContainer) {
			setPos(this.scrollbarContainer, 0, this.ddMaxDepth + 15);
			this.oDiv.style.height = (this.ddMaxDepth + 50) + "px";
		} else {
			this.oDiv.style.height = (this.ddMaxDepth + 15) + "px";
		}
	}
	
	function hs_updateDrag(ev) {
		if(ev.pageX) {
			newMouseX = ev.pageX;
		} else {
			newMouseX = window.event.clientX + document.body.scrollLeft;
		}
		// do move
		if(oldMouseX < 0) {
			oldMouseX = newMouseX;
		} else {
			scroller = allScrollers[hs_activeIndex];
			xShift = newMouseX - oldMouseX;
			scroller.scrollbarX += xShift;
			oldMouseX = newMouseX;
			hs_move();
		}
		return false;
	}
	
	function hs_move() {
		scroller = allScrollers[hs_activeIndex];
		// apply limits
		if(scroller.scrollbarX < hs_minX) scroller.scrollbarX = hs_minX;
		if(scroller.scrollbarX > scroller.hs_maxX) scroller.scrollbarX = scroller.hs_maxX;
		setPos(hs_activeButton, scroller.scrollbarX, 2);
		// update list positioning
		if(scroller.scrollbarX > hs_minX) {
			shiftFactor = (scroller.scrollbarX - hs_minX) / (scroller.hs_maxX - hs_minX);
			scrollerX = 0 - ((scroller.totalWidth - 980) * shiftFactor);
		} else {
			scrollerX = hs_minX;
		}
		dlObject = document.getElementById("hs_dl_" + hs_activeIndex);
		setPos(dlObject, scrollerX, 0);
	}
	
	
	
	//**************************************
	//********** ROTATION SCROLLER *********
	//**************************************
	
	var rs_minScale = 50;			// 1 - 99 scale for objects when they at furthest from the front
	var rs_viewAngle = 12;			// from -90 (underside) thru 0 (flat) to 90 (bird's eye) degrees
	var rs_pauseLength = 3000; 		// amount of milliseconds objects stay still
	var rs_moveUpdateInterval = 10; // amount of milliseconds between move updates
	var rs_yOffset = -40;			// used to shidt the vertical alignment of the list
	
	function rScroller(getDiv, getIndex) {
		this.oDiv = getDiv;
		this.index = getIndex;
		this.scaleRange = 100 - rs_minScale;
		this.yaw = 0;
		this.targetYaw = 0;
		this.moveDirection = true;
		this.frontObject = 0;
		this.targetObject = 0;
		this.titleY = 0;
		this.mouseHover = false;
	
		// get view dimensions
		this.viewWidth = parseFloat(this.oDiv.offsetWidth);
		this.viewHeight = parseFloat(this.oDiv.offsetHeight);
		this.originX = this.viewWidth/2;
		this.originY = this.viewHeight/2;
		// add title area to viewPort
		this.oDiv.innerHTML += "<p><\/p>";
		this.viewTitle = this.oDiv.getElementsByTagName("P")[0];
		// get number of objects work out angle
		this.o = this.oDiv.getElementsByTagName("DD");
		this.oCount = this.o.length;
		this.moveLength = 2000 / this.oCount;
		this.angleInterval = 360 / this.oCount;
		this.yawIncrement = this.angleInterval / (this.moveLength/rs_moveUpdateInterval);
		this.widthScale = (rs_minScale + (this.scaleRange/2))/100;
		// store base image sizes
		for (i=0; i < this.oCount; i++) {
			this.o[i].img = this.o[i].getElementsByTagName("IMG")[0];
			checkImageSize(this.o[i].img, 160, 118);
			this.o[i].imgWidth = this.o[i].img.width;
			this.o[i].imgHeight = this.o[i].img.height;
			this.o[i].radius = (this.originX - (this.o[i].imgWidth/2)) * (0.9/this.widthScale);
			this.o[i].title = this.o[i].img.alt;
			// store link info
			this.o[i].linkURL = this.o[i].getElementsByTagName("A")[0].href;
			this.o[i].linkTarget = this.o[i].getElementsByTagName("A")[0].target;
			// add click behaviour
			this.o[i].getElementsByTagName("A")[0].parentIndex = this.index;
			this.o[i].getElementsByTagName("A")[0].index = i;
			this.o[i].getElementsByTagName("A")[0].onmouseover = function() {
				rs_rollOverObject(this.parentIndex, this.index, true);
			}
			this.o[i].getElementsByTagName("A")[0].onmouseout = function() {
				rs_rollOverObject(this.parentIndex, this.index, false);
			}
			this.o[i].getElementsByTagName("A")[0].onclick = function() {
				if(this.index == allScrollers[this.parentIndex].frontObject) {
					return true;
				} else {
					allScrollers[this.parentIndex].rs_ClickObject(this.index);
					return false;
				}
			};
		}
		this.rs_UpdateObjects();
		this.rs_EndMove();
	}
	
	rScroller.prototype.rs_StartMove = function(getIndex) {
		if(!this.mouseHover) {
			this.targetObject = getIndex;
			this.frontObject = null;
			this.viewTitle.innerHTML = "";
			this.targetYaw = this.targetObject * this.angleInterval;
			if(this.targetYaw > this.yaw) {
				if((this.targetYaw - this.yaw) <= 180) {
					this.moveDirection = true;
				} else {
					this.moveDirection = false;
				}
			} else if(this.targetYaw < this.yaw) {
				if((this.yaw - this.targetYaw) <= 180) {
					this.moveDirection = false;
				} else {
					this.moveDirection = true;
				}
			}
			clearInterval(this.nextUpdate);
			this.nextUpdate = setInterval("allScrollers[" + this.index + "].rs_MoveObjects();",rs_moveUpdateInterval);
		}
	}

	rScroller.prototype.rs_UpdateObjects = function() {
		titleY = 0;
		for (i=0; i < this.oCount; i++) {
			this.thisAngle = (i*this.angleInterval) - this.yaw;
			if(this.thisAngle>= 360) this.thisAngle -= 360
			else if(this.thisAngle < 0) this.thisAngle += 360;
			// convert angle to radians
			this.radians = this.thisAngle * (Math.PI/180);
			// get sin and cos
			this.cosRadians = Math.cos(this.radians);
			this.sinRadians = Math.sin(this.radians);
			// trigonometry
			this.scaleFactor = (rs_minScale + (this.scaleRange/2) + ((this.scaleRange/2) * this.cosRadians))/100;
			this.posX = 0 - this.o[i].radius * this.sinRadians;
			// positions
			this.o[i].style.zIndex = Math.floor(this.scaleFactor * 100);
			this.o[i].img.width = this.o[i].imgWidth * this.scaleFactor;
			this.o[i].img.height = this.o[i].imgHeight * this.scaleFactor;
			this.posX = this.originX + (this.posX * this.scaleFactor) - (this.o[i].img.width/2);
			this.heightRange = (((rs_viewAngle/9)*10)/100) * this.o[i].radius * this.cosRadians;
			this.posY = (this.originY + this.heightRange) - (this.o[i].img.height/2);
			setPos(this.o[i],this.posX,this.posY + rs_yOffset);
			// calc deepest Y for title positioning
			thisY = this.posY + rs_yOffset + this.o[i].img.height + 10;
			if(thisY > titleY) titleY = thisY;
			// depth fading
			this.thisA = this.o[i].getElementsByTagName("A")[0];
			this.thisA.style.height = parseFloat(this.o[i].img.offsetHeight) + "px";
			this.thisA.style.width = parseFloat(this.o[i].img.offsetWidth) + "px";
			this.opacityValue = 60 + (40 * this.cosRadians);
			this.o[i].img.style.opacity = this.opacityValue/100;
			this.o[i].img.style.MozOpacity = this.opacityValue/100;
			this.o[i].img.style.filter = 'alpha(opacity=' + this.opacityValue + ')';
		}
		// position title
		setPos(this.viewTitle, 0, titleY);
	}
	
	rScroller.prototype.rs_MoveObjects = function() {
		if(this.moveDirection) {
			this.yaw += this.yawIncrement;
			if(this.yaw >= 360) this.yaw -= 360;
			this.rs_UpdateObjects();
			this.testNext = this.yaw + this.yawIncrement;
			if(this.testNext >= 360) this.testNext -= 360;
			if(this.testNext < this.yaw) {
				if(this.yaw >= this.targetYaw && this.testNext > this.targetYaw) this.rs_EndMove();
			} else {
				if(this.yaw <= this.targetYaw && this.testNext > this.targetYaw) this.rs_EndMove();
			}
		} else {
			this.yaw -= this.yawIncrement;
			if(this.yaw < 0) this.yaw += 360;
			this.rs_UpdateObjects();
			this.testNext = this.yaw - this.yawIncrement;
			if(this.testNext < 0) this.testNext += 360;
			if(this.testNext > this.yaw) {
				if(this.yaw >= this.targetYaw && this.testNext > this.targetYaw) this.rs_EndMove();
			} else {
				if(this.yaw >= this.targetYaw && this.testNext < this.targetYaw) this.rs_EndMove();
			}
		}
	}
	
	rScroller.prototype.rs_EndMove = function() {
		this.yaw = this.targetYaw;
		this.rs_UpdateObjects();
		this.frontObject = this.targetObject;
		this.viewTitle.innerHTML = this.o[this.frontObject].title;
		clearInterval(this.nextUpdate);
		this.nextUpdate = null;
		this.nextObject = this.targetObject + 1;
		if(this.nextObject >= this.oCount) this.nextObject = 0;
		clearTimeout(this.nextMove);
		this.nextMove = setTimeout("allScrollers[" + this.index + "].rs_StartMove(" + this.nextObject + ");", rs_pauseLength);
		// create text title (with link)
		this.viewTitle.innerHTML = "<a href='" + this.o[this.frontObject].linkURL + "' target='" + this.o[this.frontObject].linkTarget + "' onmouseover='rs_rollOverObject(" + this.index + "," + this.targetObject + ",true)' onmouseout='rs_rollOverObject(" + this.index + "," + this.targetObject + ",false)'>" + this.o[this.frontObject].title + "<\/a>";
	}
	
	rScroller.prototype.rs_ClickObject = function(getIndex) {
		if(getIndex != this.targetObject) {
			clearTimeout(this.nextMove);
			this.nextMove = null;
			clearInterval(this.nextUpdate);
			this.nextUpdate = null;
			this.mouseHover = false;
			this.rs_StartMove(getIndex);
		}
	}
	
	function rs_rollOverObject(parentIndex, getIndex, getMode) {
		if(getMode) {
			if(allScrollers[parentIndex].frontObject == getIndex) {
				allScrollers[parentIndex].o[getIndex].getElementsByTagName("IMG")[0].className = "rollOver";
				allScrollers[parentIndex].viewTitle.getElementsByTagName("A")[0].className = "rollOver";
			}
			allScrollers[parentIndex].mouseHover = true;
		} else {
			if(allScrollers[parentIndex].frontObject == getIndex) {
				allScrollers[parentIndex].o[getIndex].getElementsByTagName("IMG")[0].className = "";
				allScrollers[parentIndex].viewTitle.getElementsByTagName("A")[0].className = "";
			}
			allScrollers[parentIndex].mouseHover = false;
			clearTimeout(allScrollers[parentIndex].nextMove);
			allScrollers[parentIndex].nextMove = setTimeout("allScrollers[" + allScrollers[parentIndex].index + "].rs_StartMove(" + allScrollers[parentIndex].nextObject + ");", rs_pauseLength);
		}
	}

// -->

