makeEaddr = function (user, dom, tld) {
	var addr = [tld, '.', dom, '@', user].join('');
	addr = addr.split("").reverse().join("");
	return ['<a href="mailto:', addr, '">', addr, '</a>'].join('');
};

Scroller = function (id, size, images, buttons, spotlight) {
	this.parentEl = document.getElementById(id);
	this.scrollForward = document.getElementById(buttons.scrollForward);
	this.pageForward = document.getElementById(buttons.pageForward);
	this.endForward = document.getElementById(buttons.endForward);
	this.scrollBackward = document.getElementById(buttons.scrollBackward);
	this.pageBackward = document.getElementById(buttons.pageBackward);
	this.endBackward = document.getElementById(buttons.endBackward);
	this.spotlightImg = false;
	this.spotlightText = false;
	
	this.imageArray = images;
	this.imageCount = images.length + 2;
	this.imageWidth = size;
	this.imageFolder = 'merchandise/';
	this.displaySize = 3;
	this.currScroll = 0;
	
	if (spotlight) {
		var el = document.getElementById(spotlight);
		this.spotlightText = document.createElement('div');
		el.appendChild(this.spotlightText);
		this.spotlightImg = document.createElement('img');
		el.appendChild(this.spotlightImg);
	}
	
	image = document.createElement('img');
	image.src = this.imageFolder + 'clear.gif';
	image.className = 'filler';
	this.parentEl.appendChild(image);
	for (var i = 0; i < images.length; i++) {
		image = document.createElement('img');
		image.src = this.imageFolder + 'thumb-' + images[i].name + '.gif';
		image.title = images[i].title;
		this.parentEl.appendChild(image);
	}
	image = document.createElement('img');
	image.src = this.imageFolder + 'clear.gif';
	image.className = 'filler';
	this.parentEl.appendChild(image);
	
	this.scroller = function (direction, count) {
		var forward, backward, limit, index, myAnim;
		if (!count) {
			count = 1;
		}
		if (direction === 'left') {
			this.currScroll = this.currScroll + (this.imageWidth * count);
			limit = (this.imageCount - this.displaySize) * this.imageWidth;
			if (this.currScroll > limit) {
				this.currScroll = limit;
			}
			if (this.currScroll >= limit) {
				forward = true;
			}
			backward = false;
		}
		else if (direction === 'right') {
			this.currScroll = this.currScroll - (this.imageWidth * count);
			limit = 0;
			if (this.currScroll < limit) {
				this.currScroll = limit;
			}
			if (this.currScroll === limit) {
				backward = true;
			}
			forward = false;
		}
		
		if (this.spotlightImg) {
			index = this.currScroll / this.imageWidth;
			this.spotlightImg.src = this.imageFolder + this.imageArray[index].name + '.gif';
			this.spotlightText.innerHTML = this.imageArray[index].title;
		}
		
		myAnim = new YAHOO.util.Scroll(this.parentEl, {
   			scroll: { to: [this.currScroll, this.parentEl.scrollTop] } 
		}, 0.2);
		if (YAHOO.env.ua.ie) {
			YAHOO.util.Dom.setStyle(this.parentEl, 'background-position', '0 150px');
			myAnim.onComplete.subscribe(function () {
				YAHOO.util.Dom.setStyle(this.parentEl, 'background-position', this.currScroll + ' 0');
			}, this, true);
		}
		myAnim.animate();
		this.scrollForward.disabled = forward;
		this.pageForward.disabled = forward;
		this.endForward.disabled = forward;
		this.scrollBackward.disabled = backward;
		this.pageBackward.disabled = backward;
		this.endBackward.disabled = backward;
	};
	
	this.scrollIt = function (e, direction) {
		this.scroller(direction);
	};
	
	this.pageIt = function (e, direction) {
		this.scroller(direction, this.displaySize);
	};
	
	this.endIt = function (e, direction) {
		var num = Math.floor(this.currScroll / this.imageWidth);
		if (direction === 'left') {
			num = Math.floor(this.imageCount - num);
		}
		this.scroller(direction, num);
	};
	
	YAHOO.util.Event.addListener(this.scrollForward, 'click', this.scrollIt, 'left', this);
	YAHOO.util.Event.addListener(this.pageForward, 'click', this.pageIt, 'left', this);
	YAHOO.util.Event.addListener(this.endForward, 'click', this.endIt, 'left', this);
	YAHOO.util.Event.addListener(this.scrollBackward, 'click', this.scrollIt, 'right', this);
	YAHOO.util.Event.addListener(this.pageBackward, 'click', this.pageIt, 'right', this);
	YAHOO.util.Event.addListener(this.endBackward, 'click', this.endIt, 'right', this);
	
	this.endIt(null, 'right');
};


