RS = {
	hhap: {
		init: function() {			

			var pageChooser = document.getElementById("pageChooser");
			if (pageChooser) {
				pageChooser.onchange = function() {
					window.location = "/clients/page"+this.options[this.selectedIndex].value+"/";
				}
			}		
						
			var container = document.getElementById("imagePagerContainer");
			var pager = document.getElementById("imagePager");
			if (container && pager) {
				RS.hhap.triggers = RS.hhap.getElementsByClassName(pager,"a","swapimg");
				RS.hhap.mainimg = document.getElementById("mainimg");
				RS.hhap.mainimg.onclick = RS.hhap.nextImg;
				RS.hhap.mainimg.style.cursor = "pointer";
				for (var i=0; i < RS.hhap.triggers.length; i++) {
					RS.hhap.triggers[i].position =  i+1;
					if (i<RS.hhap.triggers.length-1) {
						RS.hhap.triggers[i].nextTrigger = RS.hhap.triggers[i+1];
					} else {
						RS.hhap.triggers[i].nextTrigger = RS.hhap.triggers[0];
					}
					if (i>0) {
						RS.hhap.triggers[i].previousTrigger = RS.hhap.triggers[i-1];
					} else {
						RS.hhap.triggers[i].previousTrigger = RS.hhap.triggers[RS.hhap.triggers.length-1];
					}
				};
				RS.hhap.currentTrigger = RS.hhap.triggers[0];				
				RS.hhap.mainimg.preload = document.createElement("img");
				RS.hhap.mainimg.preload.src = RS.hhap.currentTrigger.nextTrigger.href;				
				// indicator
				RS.hhap.indicator = document.createElement("span");
				container.appendChild(RS.hhap.indicator);
				RS.hhap.setIndicator();

				// previous button
				RS.hhap.previous = document.createElement("a");
				RS.hhap.previous.href = "#";
				RS.hhap.previous.className = "previous";
				var pimg = document.createElement("img");
				pimg.width = "8";
				pimg.height = "11";
				pimg.src = "/img/left.gif";
				RS.hhap.previous.appendChild(pimg);
				pimg.onmouseover = function() {
					this.src = "/img/left-on.gif";
				}
				pimg.onmouseout = function() {
					this.src = "/img/left.gif";
				}
				pimg.on = document.createElement("img");
				pimg.on.src = "/img/left-on.gif";
				// RS.hhap.previous.appendChild(document.createTextNode(" < "));
				container.appendChild(RS.hhap.previous);
				RS.hhap.previous.onclick = RS.hhap.previousImg;

				container.appendChild(document.createTextNode(" "));

				// next button
				RS.hhap.next = document.createElement("a");
				RS.hhap.next.href = "#";
				RS.hhap.next.className = "next";
				var nextimg = document.createElement("img");
				nextimg.width = "8";
				nextimg.height = "11";
				nextimg.src = "/img/right.gif";
				RS.hhap.next.appendChild(nextimg);
				nextimg.onmouseover = function() {
					this.src = "/img/right-on.gif";
				}
				nextimg.onmouseout = function() {
					this.src = "/img/right.gif";
				}
				nextimg.on = document.createElement("img");
				nextimg.on.src = "/img/left-on.gif";				
				// RS.hhap.next.appendChild(document.createTextNode(" > "));
				container.appendChild(RS.hhap.next);
				RS.hhap.next.onclick = RS.hhap.nextImg;
				pager.style.display = "none";
			}
		},
		nextImg: function() {
			RS.hhap.currentTrigger = RS.hhap.currentTrigger.nextTrigger;
			RS.hhap.mainimg.preload.src = RS.hhap.currentTrigger.nextTrigger.href;				
			RS.hhap.swapimg();
			return false;
		},
		previousImg: function() {
			RS.hhap.currentTrigger = RS.hhap.currentTrigger.previousTrigger;
			RS.hhap.mainimg.preload.src = RS.hhap.currentTrigger.previousTrigger.href;				
			RS.hhap.swapimg();
			return false;
		},
		swapimg: function() {
			RS.hhap.mainimg.src = this.currentTrigger.href;
			RS.hhap.mainimg.setAttribute("title",this.currentTrigger.getAttribute("title"));
			RS.hhap.mainimg.setAttribute("alt",this.currentTrigger.getAttribute("title"));
			RS.hhap.setIndicator();
		},
		setIndicator: function() {
			while(RS.hhap.indicator.firstChild) {
				RS.hhap.indicator.removeChild(RS.hhap.indicator.firstChild);
			}
			RS.hhap.indicator.appendChild(document.createTextNode(" "+RS.hhap.currentTrigger.position+" of "+ RS.hhap.triggers.length+ " "));
		},
		doSIFR: function() {
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h1", named({nPaddingBottom: "1", sFlashSrc: "/swf/helvetica neue.swf", sColor: fontColour, sWmode:"transparent"}));
				sIFR.replaceElement("h2", named({nPaddingBottom: "1",sFlashSrc: "/swf/helvetica neue.swf", sColor: fontColour, sWmode:"transparent"}));			
			};				
		},		
		getElementsByClassName: function(oElm, strTagName, strClassName){
		    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
		    var arrReturnElements = new Array();
		    strClassName = strClassName.replace(/\-/g, "\\-");
		    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		    var oElement;
		    for(var i=0; i<arrElements.length; i++){
		        oElement = arrElements[i];
		        if(oRegExp.test(oElement.className)){
		            arrReturnElements.push(oElement);
		        }
		    }
		    return (arrReturnElements)
		},
		addLoadEvent: function(func) {
		  var oldonload = window.onload;
		  if (typeof window.onload != 'function') {
		    window.onload = func;
		  } else {
		    window.onload = function() {
		      oldonload();
		      func();
		    }
		  }
		}

	}
};

RS.hhap.addLoadEvent(RS.hhap.init);
RS.hhap.addLoadEvent(RS.hhap.doSIFR);
