var Accobrands = {};

Accobrands.util = function(){
	return {
		addEvent: function(elm, type, fn){
			try{
				elm.addEventListener(type, fn, false);
			}catch(e){
				elm.attachEvent('on' + type, function() {
					fn.call(elm, window.event);
				});
			}
		}
	}
}();

Accobrands.rollOver = function(){
	var over = "_on.", out = "_off.";
	var overImgList = document.images;
	var overIptList = document.getElementsByTagName("input");
	var main = function() {
		if(overImgList.length) {
			for(var i = 0, len = overImgList.length; i < len; i++){
				if(overImgList[i].getAttribute("src").lastIndexOf(out) != -1) {
					var preload = new Image();
					preload.src = overImgList[i].src.replace(out, over);
					Accobrands.util.addEvent(overImgList[i], "mouseover", function(event) {
						this.setAttribute("src", this.getAttribute("src").replace(out, over));
					});
					Accobrands.util.addEvent(overImgList[i], "mouseout", function(event) {
						this.setAttribute("src", this.getAttribute("src").replace(over, out));
					});
				}
			}
		}
		if(overIptList.length) {
			for(var i = 0, len = overIptList.length; i < len; i++){
				if(overIptList[i].getAttribute("src") && overIptList[i].getAttribute("src").lastIndexOf(out) != -1) {
					var preload = new Image();
					preload.src = overIptList[i].src.replace(out, over);
					Accobrands.util.addEvent(overIptList[i], "mouseover", function() {
						this.setAttribute("src", this.getAttribute("src").replace(out, over));
					});
					Accobrands.util.addEvent(overIptList[i], "mouseout", function() {
						this.setAttribute("src", this.getAttribute("src").replace(over, out));
					});
				}
			}
		}
	}();
}
Accobrands.util.addEvent(window, "load", Accobrands.rollOver);

Accobrands.pageScroller = function() {
	var targetX, targetY, scrollX, scrollY, timer;
	var delay = 7, ms = 10;
	var html = document.documentElement;
	var body = document.body;
	var scrollBtns = document.links;
	var run = function(){
		var X = window.pageXOffset || html.scrollLeft || body.scrollLeft || 0;
		var Y = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
		scrollX += (targetX - X) / delay;
		scrollY += (targetY - Y) / delay;
		if(! ((targetX == scrollX && targetY == scrollY) || (Math.abs(targetX - X) < 1 && Math.abs(targetY - Y) < 1))) {
			window.scrollTo(scrollX, scrollY);
			timer = setTimeout(run, ms);
		} else {
			clearTimeout(timer);
		}
	}
	var main = function() {
		for(var i = 0, len = scrollBtns.length; i < len; i++){
			var btn = scrollBtns[i];
			if (btn.getAttribute("href",2).indexOf("#") != -1) {
				Accobrands.util.addEvent(btn, "click", function(event) {
					var targetId = this.getAttribute("href",2).substr(1);
					if (targetId != "" && document.getElementById(targetId) && targetId != "movie") {
						(event.preventDefault) ? event.preventDefault() : event.returnValue = false;
						var target = document.getElementById(targetId);
						var windowHeight = html.clientHeight || body.clientHeight;
						var windowWidth = html.clientWidth || body.clientWidth;
						var pageHeight = html.scrollHeight || body.scrollHeight;
						var pageWidth = html.scrollWidth || body.scrollWidth;
						if (document.compatMode == "BackCompat") {
							pageHeight = body.scrollHeight, pageWidth = body.scrollWidth;
						}
						try {
							var position = target.getBoundingClientRect();
							targetX = position.left + (body.scrollLeft || html.scrollLeft) - html.clientLeft;
							targetY = position.top + (body.scrollTop || html.scrollTop) - html.clientTop;
						} catch(e) {
							targetX = target.offsetLeft, targetY = target.offsetTop;
						}
						if (windowHeight + targetY > pageHeight) targetY -= (windowHeight + targetY) - pageHeight;
						if (windowWidth + targetX > pageWidth) targetX -= (windowWidth + targetX) - pageWidth;
						scrollX = window.pageXOffset || html.scrollLeft || body.scrollLeft || 0;
						scrollY = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
						run();
					}
				});
			}
		}
	}();
}
Accobrands.util.addEvent(window, "load", Accobrands.pageScroller);
