/*
@author Kris Kelly 2008/09/11
@updated Kris Kelly 2009/02/19
*/
var DEBUG_ON = false;
var Y = YAHOO;
	Y.namespace("Heehaw.Data", "Heehaw.TagCache", "Heehaw.Scroller.Vars", "Heehaw.Scroller.Funcs", "Heehaw.Scroller.Handlers", "Heehaw.Scroller.Settings", "Heehaw.Consts");

var H = Y.Heehaw;
	H.Data.scrollerData = {
		items:[
			{id:1, state:0, name:"Hospitals", href:"#", img:"/images/home/scroller/uses/bed.png", w:108, h:167, markup:'<a href="hospitals_care_homes.html"><strong class="company-name">Byotrol</strong> keeps superbugs at bay. In hospitals Byotrol significantly outperforms any other product in the fight against hospital acquired infections like MRSA.</a>'},
			{id:2, state:0, name:"Hands", href:"#", img:"/images/home/scroller/uses/hands.png", w:78, h:167, markup:'<a href="byotrol_in_home.html">Antibacterial soaps stop working the moment you wash it off. <strong class="company-name">Byotrol</strong>\'s gentle action keeps on protecting your hands from wash to wash.</a>'},
			{id:3, state:0, name:"Infants", href:"#", img:"/images/home/scroller/uses/baby.png", w:71, h:167, markup:'<a href="byotrol_in_home.html"><strong class="company-name">Byotrol</strong> is gentle and provides long-lasting protection against germs and nappy rash.</a>'},
			{id:4, state:0, name:"Agriculture", href:"#", img:"/images/home/scroller/uses/cow.png", w:131, h:167, markup:'<a href="agriculture_dairy.html"><strong class="company-name">Byotrol</strong> helps farmers protect their livestock and equipment from microbes that cause problems such as Foot rot, digital dermatitis and salmonella.</a>'},
			{id:5, state:0, name:"Food", href:"#", img:"/images/home/scroller/uses/apple.png", w:89, h:167, markup:'<a href="food_beverage.html"><strong class="company-name">Byotrol</strong> is non toxic to humans or animals and is therefore perfect for protecting our food factories.</a>'},
			{id:6, state:0, name:"Pets", href:"#", img:"/images/home/scroller/uses/dog.png", w:60, h:167, markup:'<a href="byotrol_in_home.html"><strong class="company-name">Byotrol</strong> is super gentle but also great at killing bacteria and its long lasting action reduces dog odours leaving your pets smelling clean and fresh.'},
			{id:7, state:0, name:"Household", href:"#", img:"/images/home/scroller/uses/house.png", w:101, h:167, markup:'<a href="byotrol_in_home.html"><strong class="company-name">Byotrol</strong> kills 99.99999% of all germs and its long lasting protection stops them from coming back for days.</a>'},
			{id:8, state:0, name:"Domestic", href:"#", img:"/images/home/scroller/uses/toilet.png", w:58, h:167, markup:'<a href="byotrol_in_home.html"><strong class="company-name">Byotrol</strong> lasts 100 times longer than Bleach and is environmentally gentle.</a>'},
			{id:9, state:0, name:"Clothes", href:"#", img:"/images/home/scroller/uses/washing_machine.png", w:78, h:167, markup:'<a href="byotrol_in_home.html"><strong class="company-name">Byotrol</strong> can be used at 30 degrees and because of its long lasting protection it keeps clothes smelling fresh for longer.</a>'},
			{id:10, state:0, name:"Buildings", href:"#", img:"/images/home/scroller/uses/stadium.png", w:129, h:167, markup:'<a href="property.html"><strong class="company-name">Byotrol</strong>\'s powerful long lasting action rids stadiums, buildings and road signs of algae, fungi, dirt and grime.</a>'},
			{id:11, state:0, name:"Travel Industry", href:"#", img:"/images/home/scroller/uses/ship.png", w:131, h:167, markup:'<a href="property.html">Because it\'s non flammable <strong class="company-name">Byotrol</strong> is safe to use on cruise ships and aeroplanes.</a>'}
		],
		getItemById:function(id){for(var i = 0; i < this.items.length; i++){if (this.items[i].id === id){return this.items[i];}}}
	};
	H.Consts.itemStates = {
		IS_IDLE:0,
		IS_ENTER:1,
		IS_LEAVE:2,
		IS_REMOVE:3,
		IS_SCROLL:4
	};
	H.Consts.mouseStates = {
		MS_OVER: 0,
		MS_OUT: 1
	};
	H.Consts.Facing = {
		FACING_LEFT : -1,
		FACING_RIGHT : 1
	};
	for( var i = 0; i < H.Data.scrollerData.items.length; i++ ){
		H.Data.scrollerData.items[i].state = H.Consts.itemStates.IS_IDLE;
		H.Data.scrollerData.items[i].mouseState = H.Consts.mouseStates.MS_OUT;
		H.Data.scrollerData.items[i].imgTag = new Image();
		H.Data.scrollerData.items[i].imgTag.src = H.Data.scrollerData.items[i].img;
	}
	
//for IE and other browsers that don't have a console object
if (Y.lang.isUndefined(console)){var console={log:function(v){if (DEBUG_ON){alert(v);}}};}

//makeConsole();

H.initScroller = function(){
	//alert(Y.env.ua.ie);
	var IEVersion = parseInt(Y.env.ua.ie, 10);
	//cache
	H.TagCache.A = document.createElement("A");
	H.TagCache.DIV = document.createElement("DIV");
	H.TagCache.IMG = document.createElement("IMG");
	if ( IEVersion >= 7 ){
		H.TagCache.IMG.style.msInterpolationMode = 'bicubic';
	}
	//defaults
	var Settings = H.Scroller.Settings;
		Settings.numItems = 3;
		Settings.itemScale = 0.75;
		Settings.zoomSpeed = 0.2;
		Settings.scrollSpeed = 0.5;
		Settings.autoScroll = true;
		
	var HSV = H.Scroller.Vars;
	
		HSV.autoScroll = {
			direction : H.Consts.Facing.FACING_RIGHT,
			canAutoScroll: true,
			interval:null,
			intervalDuration:5000
		};
		//console.log(HSV);
		
	//DOM SETUP
	var A = Y.util.Anim;
	var D = Y.util.Dom;
	var E = Y.util.Event;
	
	var scroller = D.get("scroller");
		D.removeClass(scroller, "noscript");//remove the noscript class since we have been able to run this function
	H.Scroller.contentElement = D.get("scroller_content");
	var content = H.Scroller.contentElement;
		clearNodes( content );//kill the current content
	var leftArrow = H.TagCache.A.cloneNode(false);
		leftArrow.href="#scroller";
		leftArrow.appendChild(document.createTextNode("Back"));
		leftArrow.title = "Click to scroll back through the list.";
		leftArrow.id = "scroller_back";
		
		//attach click event
		E.addListener(leftArrow, "click", function(e){
			
			H.Scroller.Funcs.delayAutoScroll({
				delay: 5000,
				direction:H.Consts.Facing.FACING_LEFT
			});
			E.stopEvent(e);
			scroll(-1);
		});
		
		D.insertBefore(leftArrow, content);
	
	var rightArrow = H.TagCache.A.cloneNode(false);
		rightArrow.href="#scroller";
		rightArrow.appendChild(document.createTextNode("Forward"));
		rightArrow.title = "Click to scroll through the list.";
		rightArrow.id = "scroller_forward";
		
		//attach click event
		E.addListener(rightArrow, "click", function(e){
			
			H.Scroller.Funcs.delayAutoScroll({
				delay: 5000,
				direction:H.Consts.Facing.FACING_RIGHT
			});
			E.stopEvent(e);
			scroll(1);
		});
		
		D.insertAfter(rightArrow, content);
	
	H.Scroller.Handlers.itemEnter = function(e, item){
		item.mouseState = H.Consts.mouseStates.MS_OVER;
		E.stopEvent(e);
		
		H.Scroller.Funcs.pauseAutoScroll();
		
		var img = this.firstChild;
		
		var zoom = new A(img, {marginLeft:{to:10}, marginRight:{to:10}, width: {to: item.w}, height:{to: item.h}, marginTop:{to:0}}, Settings.zoomSpeed, YAHOO.util.Easing.easeIn);
			zoom.onStart.subscribe(function(){
				item.state = H.Consts.itemStates.IS_ENTER;
			});
			zoom.onComplete.subscribe(function(){
				//ensure the width and height are correct
				D.setStyle(img, "width", item.w);
				D.setStyle(img, "height", item.h);
				item.state = H.Consts.itemStates.IS_IDLE;
			});
		var reanimate = function(item){
			var oItem = item[0];
			if (oItem.state !== H.Consts.itemStates.IS_IDLE) {
				if (oItem.state !== H.Consts.itemStates.IS_REMOVE && oItem.state !== H.Consts.itemStates.IS_ENTER && oItem.mouseState !== H.Consts.mouseStates.MS_OUT) {
					window.setTimeout(function(){
						reanimate([oItem]);
					}, Settings.zoomSpeed * 1000);
				}
			} else {
				if (item.mouseState !== H.Consts.mouseStates.MS_OUT) {
					zoom.animate();
				}
			}
		};
		reanimate([item]);
	};
	
	H.Scroller.Handlers.itemLeave = function(e, item){
			//console.log(item.name);
		item.mouseState = H.Consts.mouseStates.MS_OUT;
		E.stopEvent(e);
		H.Scroller.Funcs.resumeAutoScroll({direction:0, intervalDuration:HSV.autoScroll.intervalDuration});
		if (item === H.messageBox.currentItem && e.type != "custom"){
			H.messageBox.currentItemElement = this;
			return false;
		}
		var img = this.firstChild;
		var zoom = new A(img, {marginLeft:{to:18}, marginRight:{to:18}, width: {to: Math.floor(item.w * Settings.itemScale)}, height:{to: Math.floor(item.h * Settings.itemScale)}, marginTop:{to:Math.floor((167-(item.h * Settings.itemScale))/2)}}, Settings.zoomSpeed, YAHOO.util.Easing.easeIn);
			zoom.onStart.subscribe(function(){
				item.state = H.Consts.itemStates.IS_LEAVE;
			});
			zoom.onComplete.subscribe(function(){
				item.state = H.Consts.itemStates.IS_IDLE;
				
			});
		var reanimate = function(item){
			
			var oItem = item[0];
			
			if (oItem.state !== H.Consts.itemStates.IS_IDLE) {
				if (oItem.state !== H.Consts.itemStates.IS_REMOVE && oItem.state !== H.Consts.itemStates.IS_LEAVE && oItem.mouseState !== H.Consts.mouseStates.MS_OVER) {
					window.setTimeout(function(){
						reanimate([oItem]);
					}, Settings.zoomSpeed * 1000);
				}
			} else {
				if (oItem.mouseState !== H.Consts.mouseStates.MS_OVER) {
					zoom.animate();
				}
			}
		};
		reanimate([item]);
	};
	
	H.Scroller.Handlers.itemClick = function(e, item){
		E.stopEvent(e);
		if (item === H.messageBox.currentItem && e.type != "custom"){
			/*H.messageBox.currentItemElement = this;*/
			if (!H.messageBox.hiding) {
				H.messageBox.hide();
			}
			return false;
		}
		//showMessage(this, item);
		H.messageBox.show(item, Y.util.Event.getXY(e));
		return false;
	};
	
	//add the items
	H.Scroller.currentPos = 0;
	for ( var i = 0; i < Settings.numItems; i++ ){
		var newElement = createItem(H.Data.scrollerData.items[i].id);
				D.setStyle(newElement.firstChild, "margin-left", "18px");
				D.setStyle(newElement.firstChild, "margin-right", "18px");
		content.appendChild(newElement);
	}
	
	/**
	 * 
	 */
	H.Scroller.Funcs.pauseAutoScroll = function(){
		if (!Settings.autoScroll || HSV.autoScroll.interval == null ){
			return;
		}
		clearInterval( HSV.autoScroll.interval );
		HSV.autoScroll.interval = null;
	};
	
	/**
	 * 
	 * @param {Object} params
	 */
	H.Scroller.Funcs.resumeAutoScroll = function( params ){
		if (!Settings.autoScroll || HSV.autoScroll.interval != null){
			return;
		}
		if ( Y.lang.isUndefined( params ) ){
			return;
			params = {interval:HSV.autoScroll.intervalDuration, direction:0};
		}
		if ( params.direction != 0 ){
			HSV.autoScroll.direction = params.direction;
		}
		
		HSV.autoScroll.interval = setInterval(H.Scroller.Funcs.autoScroll, params.intervalDuration);
	};
	
	/**
	 * 
	 * @param {Object} params
	 */
	H.Scroller.Funcs.delayAutoScroll = function( params ){
		if (!Settings.autoScroll || HSV.autoScroll.interval == null || Y.lang.isUndefined( params ) ){
			return;
		}
		if ( Y.lang.isUndefined(params.delay) || params.delay  < 1 ){
			return;
		}
		if ( params.direction != 0 ){
			HSV.autoScroll.direction = params.direction;
		}
		H.Scroller.Funcs.pauseAutoScroll();
		HSV.autoScroll.interval = setInterval(H.Scroller.Funcs.autoScroll, params.delay);
	};
	
	/*
	 * if it's allowed, will autoscroll in the direction specified by HSV.autoScrollDirection, 
	 */
	H.Scroller.Funcs.autoScroll = function(){
		if (!HSV.autoScroll.canAutoScroll){
			return;
		}
		var S = H.Scroller.Settings;
		//cascading checks, if any fail then abort auto scroll
		if ( S.removingItem ){
			return;
		}
		if (H.messageBox.current != null){
			return;
		}
		
		for (var i = 0; i < H.Data.scrollerData.items.length; i++){
			if (H.Data.scrollerData.items[i].state != H.Consts.itemStates.IS_IDLE || H.Data.scrollerData.items[i].mouseState == H.Consts.mouseStates.MS_OVER ){
				return;
			}
		}
		
		if ( ( H.Scroller.currentPos + HSV.autoScroll.direction ) < 0 || ( H.Scroller.currentPos + HSV.autoScroll.direction ) > H.Data.scrollerData.items.length - Settings.numItems ) {
			HSV.autoScroll.direction = -HSV.autoScroll.direction;
		}
		scroll( HSV.autoScroll.direction );
	}
	
	/*
	 * Scroll the scroller in the direction supplied (-1 = back, 1 = forwards)
	 * @param Integer d
	 */
	function scroll(d){
		if ( !d ) {
			return;
		}
		var S = H.Scroller.Settings;
		
		if (S.removingItem === true){
			return;
		}
		//check if we can scroll
		if ((H.Scroller.currentPos + d) >= 0 && (H.Scroller.currentPos + d) <= H.Data.scrollerData.items.length - Settings.numItems) {
			var itemElement;
			var newItem;
			//remove the end item
			switch(d){
				case 1:
					//get the first item's element
					itemElement = H.Scroller.contentElement.firstChild;
					//get the new item to be added
					newItem = H.Data.scrollerData.items[H.Scroller.currentPos + Settings.numItems];
				break;
				case -1:
					//get the last item's element
					itemElement = H.Scroller.contentElement.lastChild;
					//get the new item to be added
					newItem = H.Data.scrollerData.items[H.Scroller.currentPos - 1 ];
				break;
			}
			var itemId = parseInt( itemElement.id.substring( itemElement.id.lastIndexOf( "_" ) + 1 ), 10 );//MUST be an int
				
			//advance the pointer
			H.Scroller.currentPos += d;
			
			//create a new item
			var newItemElement = createItem(newItem.id);
				D.setStyle(newItemElement.firstChild, "width", "0px");
				D.setStyle(newItemElement.firstChild, "height", "0px");
				D.setStyle(newItemElement.firstChild, "margin-top", "80px");
			
			switch(d){
				case 1:
					//insert at the end
					D.insertAfter(newItemElement, H.Scroller.contentElement.lastChild);
				break;
				case -1:
					//insert at the beginning
					D.insertBefore(newItemElement, H.Scroller.contentElement.firstChild);
				break;
			}
			
			//animate it in
			var fx;
			if (IEVersion >= 7) {//IE 7 & 8 have a bug with opacity and transparent pngs
				
				fx = {
					marginLeft: {from: 0,to: 18},
					marginRight: {from: 0,to: 18},
					width: {to: Math.floor(newItem.w * Settings.itemScale)},
					height: {to: Math.floor(newItem.h * Settings.itemScale)},
					marginTop: {to: Math.floor((167 - (newItem.h * Settings.itemScale)) / 2)}
				};
			}
			else {
				fx = {
					opacity: {from: 0,to: 1},
					marginLeft: {from: 0,to: 18},
					marginRight: {from: 0,to: 18},
					width: {to: Math.floor(newItem.w * Settings.itemScale)},
					height: {to: Math.floor(newItem.h * Settings.itemScale)},
					marginTop: {to: Math.floor((167 - (newItem.h * Settings.itemScale)) / 2)}
				};
			}
			
			
			var zoom = new A(newItemElement.firstChild, fx, Settings.scrollSpeed, YAHOO.util.Easing.easeIn);
			
			zoom.onStart.subscribe(function(){
				newItem.state = H.Consts.itemStates.IS_SCROLL;
			});
			zoom.onComplete.subscribe(function(){
				newItem.state = H.Consts.itemStates.IS_IDLE;
			});
			zoom.animate();
			removeItem(itemId);
		}
	}//scroll
	
	/*
	 * @param Integer id
	 * @return {DOMNode}
	 */
	function createItem(id){
		
		var D = Y.util.Dom;
		var E = Y.util.Event;
		//var S = H.Scroller.Settings;
		var item = H.Data.scrollerData.getItemById(id);
		
		if (item){
			var link = H.TagCache.A.cloneNode(false);
				link.id = "scroller_item_" + id;
				link.href = "#scroller";//item.href;
				link.title = item.name;
				//link.appendChild(document.createTextNode(item.name));
				link.className = "scroller_item";
				if (IEVersion >= 6 && IEVersion < 7){//bleah
					item.img = item.img.substring(0,item.img.length-3)+"gif";//strip png and replace with gif
				}
				var img = H.TagCache.IMG.cloneNode(false);
					img.src = item.img;
					img.alt = item.name;
				link.appendChild(img);
				
				E.addListener(link, "mouseover", H.Scroller.Handlers.itemEnter, item);
				E.addListener(link, "mouseout", H.Scroller.Handlers.itemLeave, item);
				E.addListener(link, "click", H.Scroller.Handlers.itemClick, item);
				
				D.setStyle(img, "width", (item.w * Settings.itemScale) + "px");
				D.setStyle(img, "height", (item.h * Settings.itemScale) + "px");
				D.setStyle(img, "margin-top", ((167-(item.h * Settings.itemScale))/2) + "px");
				D.setStyle(img, "margin-left", "0px");
				D.setStyle(img, "margin-right", "0px");
			
			return link;
		} else {
			if (console) {
				//console.log("Invalid item id: " + id);
			}
		}
		return null;
	}//createItem
	
	/*
	 * @param Integer id
	 * @return {DOMNode}
	 */
	function removeItem(id, inAnim){
		
		var D = Y.util.Dom;
		var E = Y.util.Event;
		var S = H.Scroller.Settings;
		var item = H.Data.scrollerData.getItemById(id);
		
		if (item){
			var link = D.get("scroller_item_" + id);
			var fx;
			if (IEVersion >= 7) {//IE 7 & 8 have a bug with opacity and transparent pngs
				fx = {marginLeft:{to:0}, marginRight:{to:0}, width: {to: 0}, height:{to: 0}, marginTop:{to:80}};
			} else {
				fx = {opacity:{from: 1, to:0}, marginLeft:{to:0}, marginRight:{to:0}, width: {to: 0}, height:{to: 0}, marginTop:{to:80}};
			}
			var zoom = new A(link.firstChild, fx, Settings.scrollSpeed, YAHOO.util.Easing.easeOut);
			
			var removeElement = function() {
				var el = this.getEl().parentNode;
				el.parentNode.removeChild(el);
				if ( inAnim ) {
					inAnim.animate();
				}
			};
			var zoomStart = function(){
				item.state = H.Consts.itemStates.IS_REMOVE;
				S.removingItem = true;
			};
			var zoomComplete = function(){
				item.state = H.Consts.itemStates.IS_IDLE;
				S.removingItem = false;
			};
			zoom.onComplete.subscribe(removeElement); 
			zoom.onStart.subscribe(zoomStart);
			zoom.onComplete.subscribe(zoomComplete);
			zoom.animate();
			
		} else {
			if (console) {
				//console.log("Invalid item id: " + id);
			}
		}
	}//removeItem
	
	
	function createMessageBox(){
		var killClickEventPropagation = function(e){
			Y.util.Event.stopPropagation(e);
		};
		if (!H.messageBox){
			H.messageBox = {};
			//DOM
			var clearing = H.TagCache.DIV.cloneNode(false);
				clearing.className = "clear";
			//RIGHT
			var box = H.TagCache.DIV.cloneNode(false);
				box.id = "messageBox";
				box.className = "msg_pointer_right";
				
				var content = H.TagCache.DIV.cloneNode(false);
					content.id = "messageBox_content";
					
				var pointer = H.TagCache.DIV.cloneNode(false);
					pointer.id = "messageBox_pointer";
					
					var rightShadow = H.TagCache.DIV.cloneNode(false);
						rightShadow.id = "messageBox_shadow_right";
						pointer.appendChild(rightShadow);
						
				var bottomShadow = H.TagCache.DIV.cloneNode(false);
					bottomShadow.id = "messageBox_bottom_shadow";
				
				box.appendChild(content);
				box.appendChild(pointer);
				box.appendChild(bottomShadow);
				box.appendChild(clearing.cloneNode(true));
			H.messageBox.boxRight = {};
			
			H.messageBox.boxRight.element = box;
			H.messageBox.boxRight.content = content;
			Y.util.Event.addListener(H.messageBox.boxRight.element, "click", killClickEventPropagation);
			
			
			//LEFT
			var box = H.TagCache.DIV.cloneNode(false);
				box.id = "messageBox";
				box.className = "msg_pointer_left";
				var pointer = H.TagCache.DIV.cloneNode(false);
					pointer.id = "messageBox_pointer";
					var leftShadow = H.TagCache.DIV.cloneNode(false);
						leftShadow.id = "messageBox_shadow_left";
					pointer.appendChild(leftShadow);
				var content = H.TagCache.DIV.cloneNode(false);
					content.id = "messageBox_content";
					
					var rightShadow = H.TagCache.DIV.cloneNode(false);
						rightShadow.id = "messageBox_shadow_right";
						
				var bottomShadow = H.TagCache.DIV.cloneNode(false);
					bottomShadow.id = "messageBox_bottom_shadow";
				
				box.appendChild(pointer);
				box.appendChild(content);
				box.appendChild(rightShadow);
				box.appendChild(bottomShadow);
				box.appendChild(clearing.cloneNode(true));
				
			H.messageBox.boxLeft = {};
			H.messageBox.boxLeft.element = box;
			H.messageBox.boxLeft.content = content;
			Y.util.Event.addListener(H.messageBox.boxLeft.element, "click", killClickEventPropagation);
			
			//END DOM
			
			H.messageBox.current = null;
			
			H.messageBox.show = function(item, mousePos){
				var D = Y.util.Dom;
				var E = Y.util.Event;
				var Facing = H.Consts.Facing;
				
				if (!item || !H.Scroller.contentElement){return false;}
				
				H.messageBox.clearTimeout();
				//hide the current one if still visible
				if (H.messageBox.current !== null){
					if (!H.messageBox.hiding) {
						H.messageBox.hide();
					}
					H.messageBox.timeout = window.setTimeout(function(){H.messageBox.show(item, mousePos);},10);//return to this function in 10ms
					return;
				}
				H.messageBox.currentItem = item;
				
				//determine whether it should be a left or right pointing box
				var contentPos = D.getXY( H.Scroller.contentElement );
				
				//disabled facing left
				/*if ( ( mousePos[0] - contentPos[0] ) < 202  ){//232px+40px = message box width + marginleft
					var currentFacing = Facing.FACING_LEFT;
					H.messageBox.current = H.messageBox.boxLeft;
				} else {*/
					var currentFacing = Facing.FACING_RIGHT;
					H.messageBox.current = H.messageBox.boxRight;
				//}
				
				//set the content
				H.messageBox.current.content.innerHTML = item.markup;
				
				//show it
				var element = H.messageBox.current.element;
				
					D.setStyle(element, "position", "absolute");
					
					if (currentFacing === Facing.FACING_LEFT) {
						D.setStyle(element, "left", (mousePos[0] -5) + "px");
					} else {
						D.setStyle(element, "left", (mousePos[0] - 227) + "px");
					}
					//CENTRE POPUP
					var top = (contentPos[1]+30);//( (mousePos[1]-35) > 0 ) ? (mousePos[1]-35) : 0;
					
					D.setStyle(element, "top", top+"px");
					document.body.appendChild(element);
					if (IEVersion < 7) {//IE 7 & 8 have a bug with opacity and transparent pngs
					
						D.setStyle(element, "opacity", 0);
						var anim = new A(element, {
							opacity: {
								to: 1
							}
						}, 0.1, YAHOO.util.Easing.easeIn);
						
						anim.animate();
					}
					
				E.addListener(element, "mouseout", function(e){
					//var target = E.getTarget(e);
					//var related = E.getRelatedTarget(e);
					
					if (!mouseInside(H.messageBox.current.element, E.getXY(e))){
						H.messageBox.clearTimeout();
						H.messageBox.timeout = window.setTimeout(function(){
							H.messageBox.hide();
						}, 250);
					}
					E.stopEvent(e);
				});
				E.addListener(element, "mouseover", function(e){
					H.messageBox.clearTimeout();
				});
			};
			
			H.messageBox.hide = function(){
				
				if (H.messageBox.current && !H.messageBox.hiding) {
				
					H.messageBox.hiding = true;
					//play hide animation
					if (IEVersion >= 7) {//IE 7 & 8 has a bug with opacity and transparent pngs
						var fx = {};
					}
					else {
						var fx = {
							opacity: {
								to: 0
							}
						};
					}
					var anim = new A(H.messageBox.current.element, fx, 0.1, YAHOO.util.Easing.easeOut);
					anim.onComplete.subscribe(function(){
						//clear the content
						clearNodes(H.messageBox.current.content);
						//remove the element from the DOM
						H.messageBox.current.element.parentNode.removeChild(H.messageBox.current.element);
						H.messageBox.current = null;
						H.messageBox.hiding = false;
					});
					anim.animate();
					//E.fireEvent("mouseout", H.messageBox.currentItem);
					if (H.messageBox.currentItemElement){
						H.Scroller.Handlers.itemLeave.call(H.messageBox.currentItemElement,{type:"custom"}, H.messageBox.currentItem);
					}
					H.messageBox.currentItem = null;
				}
			};
			
			H.messageBox.clearTimeout = function(){
				if (H.messageBox.timeout){
					window.clearTimeout(H.messageBox.timeout);
					H.messageBox.timeout = null;
				}
			};
			
		}//if !H.messageBox
		
		Y.util.Event.addListener(document, "click", H.messageBox.hide);
	}//createMessageBox();

		function mouseInside(element, mousePos){
			var elementPos = D.getXY(element);
			if (
				mousePos[0] > elementPos[0] &&
				mousePos[0] < ( elementPos[0] + element.clientWidth ) &&
				mousePos[1] > elementPos[1] &&  
				mousePos[1] < ( elementPos[1] + element.clientHeight )
			){
				return true;
			}
			return false;
		}
	createMessageBox();
	if ( Settings.autoScroll ) {
		HSV.autoScroll.interval = setInterval(H.Scroller.Funcs.autoScroll, HSV.autoScroll.intervalDuration);
	}
}; //H.init
Y.util.Event.onDOMReady( H.initScroller );
function clearNodes(n){var D = Y.util.Dom;if (!n.removeChild){var te = D.get( n );} else {var te = n;}if ( te ){while( te.firstChild !== null ){te.removeChild( te.firstChild );}return true;}}