function TabCollection() {
	this.selTab = 0;
	this.numTabs = 3;
	this.tabs = new Array(this.numTabs);
	window.tabSlideArrowArr = new Array();
	window.tabArrowSafety = false;
}

TabCollection.prototype.addTab = function(iTabIndx, oImgObj, sLayerName, sSlidingLayerName) {
	oImgObj.onload = "";
	var elcImgObj = new elcImage(oImgObj);			
	var elcLayerObj = new elcLayer(sLayerName);
	var elcSlidingLayerObj = null;
	var elcSlidingUpArrowLayerObj = null;
	var elcSlidingDownArrowLayerObj = null;
	if (typeof(sSlidingLayerName) != "undefined") {
		elcSlidingLayerObj = new elcLayer(sSlidingLayerName);
		elcSlidingUpArrowLayerObj = new elcLayer(sLayerName + "arrowup");
		elcSlidingDownArrowLayerObj = new elcLayer(sLayerName + "arrowdown");
	}
	if (this.tabs[iTabIndx] == null) {
		this.tabs[iTabIndx] = new TabObj(iTabIndx, elcImgObj, elcLayerObj, elcSlidingLayerObj, elcSlidingUpArrowLayerObj, elcSlidingDownArrowLayerObj);
	}
}

TabCollection.prototype.selectTab = function(iTabIndx) {
	if (this.tabs[iTabIndx]) {
		this.resetSelTab();
		for (var i=0; i<this.tabs.length; i++) {
			if (this.tabs[i]) {
				this.tabs[i].setOff();
			}
		}
		this.tabs[iTabIndx].setOn();
		this.selTab = iTabIndx;
	}
}

TabCollection.prototype.setTabOver = function(iTabIndx) {
	if (this.tabs[iTabIndx] && this.tabs[iTabIndx].tabImg) {
		this.tabs[iTabIndx].tabImg.setOn();
	}
}

TabCollection.prototype.unsetTabOver = function(iTabIndx) {
	if (this.tabs[iTabIndx] && this.tabs[iTabIndx].tabImg) {
		for (var i=0; i<this.tabs.length; i++) {
			if (this.tabs[i] && (i != this.selTab)) {
				this.tabs[i].tabImg.setOff();
			}
		}
	}
}

TabCollection.prototype.resetSelTab = function() {
	if ((this.tabs[this.selTab]) && (this.tabs[this.selTab].tabSlider)) {
		this.tabs[this.selTab].tabSlider.reset();
	}
}

TabCollection.prototype.setTabSlideArrows = function(iTabId, oImgObj, sDir) {
	if ((this.tabs[iTabId]) && (this.tabs[iTabId].tabSlider)) {
		if (sDir == "up") {
			this.tabs[iTabId].tabSlider.setUpArrow(oImgObj);
		} else if (sDir == "down") {
			this.tabs[iTabId].tabSlider.setDownArrow(oImgObj);
		}			
	} else {
		window.tabArrowSafety = true;
		function _TabSlideArrow(iTabId, oImgObj, sDir) {
			this.tabId = iTabId;
			this.imgObj = oImgObj;
			this.dir = sDir;
			return this;
		}
		if (window.tabSlideArrowArr.length < (this.numTabs * 2)) {
			window.tabSlideArrowArr[window.tabSlideArrowArr.length] = new _TabSlideArrow(iTabId, oImgObj, sDir);
		}
	}
}

TabCollection.prototype.slideTab = function(iTabId, sDir) {
	if ((this.tabs[iTabId]) && (this.tabs[iTabId].tabSlider)) {
		this.tabs[iTabId].tabSlider.slide(sDir);		
	}
}

TabCollection.prototype.stopTab = function(iTabId) {
	if ((this.tabs[iTabId]) && (this.tabs[iTabId].tabSlider)) {
		this.tabs[iTabId].tabSlider.stop();		
	}
}		



function TabObj(iTabIndx, oElcImgObj, oElcLayerObj, elcSlidingLayerObj, elcSlidingUpArrowLayerObj, elcSlidingDownArrowLayerObj) {
	this.tabId = iTabIndx;
	this.tabImg = oElcImgObj;
	this.tabLayer = oElcLayerObj;
	this.tabSlidingLayer = elcSlidingLayerObj;
	this.tablidingUpArrowLayer = elcSlidingUpArrowLayerObj;
	this.tablidingDownArrowLayer = elcSlidingDownArrowLayerObj;
	this.tabSliderClipHeight = 114;
	if (this.tabSlidingLayer) {
		this.tabSlidingLayer.defaultY = this.tabSlidingLayer.y;
		this.tabSlider = new TabContentSlider(this.tabId,this.tabSlidingLayer,this.tabLayer,this.tabSliderClipHeight,this.tablidingUpArrowLayer,this.tablidingDownArrowLayer);
	} else {
		this.tabSlider = null;
	}
}

TabObj.prototype.setOff = function() {
	this.tabImg.setOff();
	this.tabLayer.hide();
	if (this.tabSlider && (this.tabSlider.upArrowLayer && this.tabSlider.downArrowLayer)) {
		this.tabSlider.upArrowLayer.hide();
		this.tabSlider.downArrowLayer.hide();
	}
}

TabObj.prototype.setOn = function() {
	this.tabImg.setOn();
	this.tabLayer.show();
	if (this.tabSlider) {
		this.tabSlider._checkCanSlide();
	}
}



function TabContentSlider(iTabId, oElcContentLayerObj, oElcClipLayerObj, iClipHeight, oElcArrowUpLayer, oElcArrowDownLayer) {
	this.slideIncrement = (typeof(window.TC_SLIDE_INCREMENT) != "undefined")? window.TC_SLIDE_INCREMENT : 1;
	this.slideTimeout = (typeof(window.TC_SLIDE_TIMEOUT) != "undefined")? window.TC_SLIDE_TIMEOUT : 25;
	this.maxLoops = (typeof(window.TC_MAX_LOOPS) != "undefined")? window.TC_MAX_LOOPS : 1000;
	this.curLoops = 0;
	this.tabId = iTabId;
	this.contentLayer = oElcContentLayerObj;
	this.clipLayer = oElcClipLayerObj;
	this.clipHeight = iClipHeight;
	this.upArrowLayer = oElcArrowUpLayer;
	this.downArrowLayer = oElcArrowDownLayer;
	this.canSlideUp = false;
	this.canSlideDown = false;
}

TabContentSlider.prototype.setUpArrow = function(oImg) {
	this._initArrow(oImg,'up');
	this._positionCheck();
	if (this.canSlideUp) {
		this.upArrow.setOn();
	}
	this._checkCanSlide();
}

TabContentSlider.prototype.setDownArrow = function(oImg) {
	this._initArrow(oImg,'down');
	this._positionCheck();
	if (this.canSlideDown) {
		this.downArrow.setOn();
	}
	this._checkCanSlide();
}

TabContentSlider.prototype.slide = function(sDir) {
	if (this.isSliding) {
		window.clearInterval(this.slideTimer);
	}
	if (sDir && (sDir == 'up') && this.canSlideUp) {
		if ('tc.tabs[' + this.tabId + '].tabSlider') {
			this.slideTimer = window.setInterval('tc.tabs[' + this.tabId + '].tabSlider._slideLoop(' + this.slideIncrement + ')',this.slideTimeout);
			this.isSliding = true;
			if (this.upArrow) {
				this.upArrow.setOver();
				this.upArrow.isOver = true;
			}
		}
	} else if (sDir && (sDir == 'down') && this.canSlideDown) {
		if ('tc.tabs[' + this.tabId + '].tabSlider') {
			this.slideTimer = window.setInterval('tc.tabs[' + this.tabId + '].tabSlider._slideLoop(' + -this.slideIncrement + ')',this.slideTimeout);
			this.isSliding = true;
			if (this.downArrow) {
				this.downArrow.setOver();
				this.downArrow.isOver = true;
			}
		}
	}
}

TabContentSlider.prototype.stop = function(iFinalY) {
	if (this.isSliding) {
		this.isSliding = false;
		this.curLoops = 0;
		if (this.upArrow) {
			this.upArrow.isOver = null;
		}
		if (this.downArrow) {
			this.downArrow.isOver = null;
		}
		window.clearInterval(this.slideTimer);
	}
	//if (typeof(iFinalY) != "undefined") {
	//	this.contentLayer.moveTo(this.contentLayer.x,iFinalY);
	//}
	this._resetArrows();
}

TabContentSlider.prototype.reset = function() {
	this.stop(this.contentLayer.defaultY);
}

TabContentSlider.prototype._initArrow = function(oImg, sDir) {
	eval('this.' + sDir + 'Arrow = new elcImage(oImg,null,true);');
}

TabContentSlider.prototype._checkCanSlide = function() {
	if ((this.upArrow && this.downArrow) && (this.canSlideUp || this.canSlideDown)) {
		this.upArrowLayer.show();
		this.downArrowLayer.show();
	}
}

TabContentSlider.prototype._positionCheck = function() {
	var layerHeightDiff = this._getContentHeight() - this.clipHeight;
	var layerYdiff = this.clipLayer.y - this.contentLayer.y;
	this.canSlideUp = (this.contentLayer.y < this.contentLayer.defaultY);
	this.canSlideDown = ((layerHeightDiff > 0) && (layerYdiff < layerHeightDiff));
}

TabContentSlider.prototype._resetArrows = function() {
	this._positionCheck();
	if ((this.upArrow && this.downArrow) && (!(this.canSlideUp || this.canSlideDown))) {
		this.upArrow.setSrc('/images/global/spacer.gif');
		this.downArrow.setSrc('/images/global/spacer.gif');
	} else {
		if (this.upArrow && (!this.upArrow.isOver)) {
			if (this.canSlideUp) {
				this.upArrow.setOn();
			} else {
				this.upArrow.setOff();
			}
		}
		if (this.downArrow && (!this.downArrow.isOver)) {
			if (this.canSlideDown) {
				this.downArrow.setOn();
			} else {
				this.downArrow.setOff();
			}
		}
	}
}

TabContentSlider.prototype._getContentHeight = function() {
	var topAnchorY = eval('getAnchorPosition("tab_' + this.tabId + '_top").y;');
	var bottomAnchorY = eval('getAnchorPosition("tab_' + this.tabId + '_bottom").y;');
	return (bottomAnchorY - topAnchorY);			
}

TabContentSlider.prototype._slideLoop = function(iSlideIncrement) {
	if ((this.curLoops < this.maxLoops) && ((this.canSlideUp && (iSlideIncrement > 0)) || (this.canSlideDown && (iSlideIncrement < 0)))) {
		this.curLoops++;
		var layerHeightDiff = this._getContentHeight() - this.clipHeight;
		var layerYdiff = this.clipLayer.y - (this.contentLayer.y + iSlideIncrement);
		var willMaxUp = ((this.contentLayer.y + iSlideIncrement) >= this.contentLayer.defaultY);
		var willMaxDown = (layerYdiff >= layerHeightDiff);
		
		if (willMaxUp || willMaxDown) {
			if (willMaxUp) {
				this.stop(this.contentLayer.defaultY);
			}
			if (willMaxDown) {
				this.stop(this.clipLayer.y + this.clipHeight - this._getContentHeight());
			}
		} else {
			this.contentLayer.moveBy(0,iSlideIncrement);
			this._resetArrows();
		}
	}
}



function WorksWellTab() {
		this.products = new Array();
		this.onStyle = "prodshotover";
		this.offStyle = "prodshot";	
		this.infoImg = null;
		this.infoImgDefaultURI = null;
}

WorksWellTab.prototype.setInfoImg = function(oInfoImgObj) {
	this.infoImg = oInfoImgObj;
	if (!this.infoImgDefaultURI) {
		this.infoImgDefaultURI = this.infoImg.src;
	}
}

WorksWellTab.prototype.addProd = function(sProdId, oProdImgObj, sProdInfoImgSrc) {
//	var elcProdImgObj = new elcImage(oProdImgObj);
	var elcProdImgObj = new Image();
	elcProdImgObj.prodId = sProdId;
	elcProdImgObj.HTMLImageObj = oProdImgObj;
	elcProdImgObj.infoImg = new Image();
	elcProdImgObj.infoImg.src = sProdInfoImgSrc;
	this.products[this.products.length] = elcProdImgObj;
}

WorksWellTab.prototype.setOn = function(sProdId) {
	if (this.infoImg) {
		for (var i=0; i<this.products.length; i++) {
			if (this.products[i].prodId == sProdId) {
				this.infoImg.src = this.products[i].infoImg.src;
				this.products[i].HTMLImageObj.className = this.onStyle;
			} else {
				this.products[i].HTMLImageObj.className = this.offStyle;
			}
		}
	}
}

WorksWellTab.prototype.setOff = function() {
	if (this.infoImg) {
		for (var i=0; i<this.products.length; i++) {
			this.products[i].HTMLImageObj.className = this.offStyle;
		}
		this.infoImg.src = this.infoImgDefaultURI;
	}
}

