//===========================================================================
//  Shopping Cart technology copyright (c) 1997-2001 wirejunkie
//  DHTML scrollers copyright (c) 2001 wirejunkie
//  All JavaScript copyright (c) 1997-2001 wirejunkie
//  
//  Unauthorized use, copying, distribution, modification and
//  derivation is prohibited.  All rights reserved.
//  
//  If you want to use it, email us at info@wirejunkie.com, or
//  check out our web site at http://www.wirejunkie.com/
//===========================================================================

//---------------------------------------------------------------------------
// General
//---------------------------------------------------------------------------

//
// ScriptCaps object - determine browser capabilities
//
function ScriptCaps()
{
	this.dom = (document.getElementById ? true : false);
	this.ns = navigator.appName == 'Netscape';
	this.ie = navigator.appName == 'Microsoft Internet Explorer';
	this.lyr = (document.layers ? true : false);
	this.all = (document.all ? true : false);
	if ((this.dom || this.lyr || this.all) &&
		(navigator.appName.indexOf('WebTV') == -1) &&
		(navigator.userAgent.indexOf('Opera') == -1))
	{
		this.dhtml = true;
	}
	else
	{
		this.dhtml = false;
	}
	this.ns4 = this.ns && (parseInt(navigator.appVersion) == 4);
	return this;
}
caps = new ScriptCaps();

//
// voidFunc() - does nothing.  Handy for <a href="javascript:voidFunc()"...
//
function voidFunc()
{
}

function findImage(id, pfx)
{
	var obj = null;
	eval('var len = ' + pfx + '.images.length;');
	for (var i = 0; i < len; ++i)
	{
		eval('var img = ' + pfx + '.images[' + i + '];');
		if (img.name ==	id)
		{
			obj = img;
			break;
		}
	}
	if (obj == null && caps.lyr)
	{
		eval('var len = ' + pfx + '.layers.length;');
		for(var i = 0; i < len; ++i)
		{
			obj = findImage(id, pfx + '.layers[' + i + '].document');
			if (obj != null)
			{
				break;
			}
		}
	}
	return obj;
}

function loadImage(id, src)
{
	var img = findImage(id, 'window.document');
	if (img != null)
	{
		img.src = src;
	}
}

function rollover(i, s, m)
{
	var img = findImage(i, 'window.document');
	if (img != null)
	{
		img.src = s;
	}
	window.status = m;
}

//---------------------------------------------------------------------------
// Layers
//---------------------------------------------------------------------------

function findLayerNS4(id, pfx)
{
	var elm = null;
	eval('var len = ' + pfx + '.length;');
	for(var i = 0; i < len; ++i)
	{
		eval('var lyr = ' + pfx + '[' + i + '];');
		if (lyr.id == id)
		{
			elm = lyr;
			break;
		}
		if (lyr.document.layers.length > 0)
		{
			elm = findLayerNS4(id, pfx + '[' + i + '].document.layers');
			if (elm != null)
			{
				break;
			}
		}
	}
	return elm;
}

function layerMoveBy(x, y)
{
	var newX = this.x;
	var newY = this.y;
	if (x != null)
	{
		newX += x;
	}
	if (y != null)
	{
		newY += y;
	}
	this.moveTo(newX, newY);
}

function layerMoveTo(x, y)
{
	if (x != null)
	{
		this.x = x;
		if (caps.dom || caps.lyr)
		{
			this.style.left = this.x + (caps.dom ? 'px' : 0);
		}
		else if(caps.all)
		{
			this.style.pixelLeft = this.x;
		}
	}
	if (y != null)
	{
		this.y = y;
		if (caps.dom || caps.lyr)
		{
			this.style.top = this.y + (caps.dom ? 'px' : 0);
		}
		else if(caps.all)
		{
			this.style.pixelTop = this.y;
		}
	}
}

function layerResize(w, h)
{
	if (caps.ns)
	{
		if (w != null && w > 0)
		{
			this.style.width = w + 'px';
			if (caps.dom)
			{
				this.w = this.elm.offsetWidth;
			}
			else
			{
				this.w = this.style.clip.width;
			}
		}
		if (h != null && h > 0)
		{
			this.style.height = h + 'px';
			if (caps.dom)
			{
				this.h = this.elm.offsetHeight;
			}
			else
			{
				this.h = this.style.clip.height;
			}
		}
	}
	else if (caps.ie)
	{
		if (w != null && w > 0)
		{
			this.style.pixelWidth = w;
			this.w = (caps.dom) ? this.elm.offsetWidth : this.style.pixelWidth;
		}
		if (h != null && h > 0)
		{
			this.style.pixelHeight = h;
			this.h = (caps.dom) ? this.elm.offsetHeight : this.style.pixelHeight;
		}
	}
}

function layerSetClip(t, r, b, l)
{
	if (t < b && l < r)
	{
		if (caps.dom || caps.ie)
		{
			var c = 'rect(' + t + 'px ' + r + 'px ' + b + 'px ' + l + 'px)';
			this.style.clip = c;
		}
		else if (caps.ns)
		{
			this.style.clip.top = t;
			this.style.clip.right = r;
			this.style.clip.bottom = b;
			this.style.clip.left = l;
			this.w = this.style.clip.width;
			this.h = this.style.clip.height;
		}
	}
}

function layerShow()
{
	if (caps.dom || caps.ie)
	{
		this.style.visibility = 'visible';
	}
	else if (caps.ns)
	{
		this.style.visibility = 'show';
	}
}

function layerHide()
{
	if (caps.dom || caps.ie)
	{
		this.style.visibility = 'hidden';
	}
	else if (caps.ns)
	{
		this.style.visibility = 'hide';
	}
}

function Layer(id)
{
	if (caps.dom)
	{
		this.elm = document.getElementById(id);
		this.style = this.elm.style;
		this.doc = document;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		if(caps.ns)
		{
			this.x -= this.elm.parentNode.offsetLeft;
			this.y -= this.elm.parentNode.offsetTop;
		}
		this.w = this.elm.offsetWidth;
		this.h = this.elm.offsetHeight;
	}
	else if (caps.all)
	{
		this.elm = document.all[id];
		this.style = this.elm.style;
		this.doc = document;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		this.w = this.elm.offsetWidth;
		this.h = this.elm.offsetHeight;
	}
	else if (caps.lyr)
	{
		this.elm = findLayerNS4(id, 'window.document.layers');
		this.style = this.elm;
		this.doc = this.elm.document;
		this.x = this.style.left;
		this.y = this.style.top;
		this.w = this.style.clip.width;
		this.h = this.style.clip.height;
	}
	this.moveTo = layerMoveTo;
	this.moveBy = layerMoveBy;
	this.resize = layerResize;
	this.setClip = layerSetClip;
	this.show = layerShow;
	this.hide = layerHide;
	return this;
}

//---------------------------------------------------------------------------
// Scroller
//---------------------------------------------------------------------------

function scrollerScroll(dist, time)
{
	if (this.scrolling)
	{
		var delay = time || 10;
		var y = this.cnt.y;
		y += dist;
		if (y > this.top)
		{
			y = this.top;
		}
		if (y < this.bottom)
		{
			y = this.bottom;
		}
		if (this.cnt.h > this.win.h)
		{
			this.cnt.moveTo(null, y);
			setTimeout('scroller.scroll(' + dist + ',' + delay + ');', delay);
		}
	}
	else
	{
		if (caps.ns4)
		{
				// Force refresh on NS4 to fix redrawing problems with form fields
			this.cnt.hide();
			setTimeout('scroller.cnt.show()', 25);
		}
	}
}

function scrollerUp()
{
	if (this.scrolling) return;
	this.scrolling = true;
	this.scroll(8);
}

function scrollerDown()
{
	if (this.scrolling) return;
	this.scrolling = true;
	this.scroll(-8);
}

function scrollerStop()
{
	this.scrolling = false;
}

function scrollerResize(w, h)
{
	this.win.resize(w, h);
	this.win.setClip(0, w, h, 0);
	this.bottom = this.start - (this.cnt.h - this.win.h + 60);
	this.cnt.resize(w - 20, null);
	this.cnt.moveTo(null, this.start);
}

function scrollerShow()
{
	this.win.show();
	this.cnt.show();
}

function Scroller(win, cnt)
{
	this.win = win; //new Layer(win);
	this.cnt = cnt; //new Layer(cnt);
	this.start = this.cnt.y;
	this.top = this.start;
	this.bottom = this.start - (this.cnt.h - this.win.h + 60);
	this.scrolling = false;
	this.up = scrollerUp;
	this.scroll = scrollerScroll;
	this.down = scrollerDown;
	this.stop = scrollerStop;
	this.resize = scrollerResize;
	this.show = scrollerShow;
}

//---------------------------------------------------------------------------
// Debugging
//---------------------------------------------------------------------------

//
// dumpObject(obj) - dumps all the properties of an object to a new window
//
function dumpObject(obj)
{
	var w = window.open('', 'dumpWindow',
		'resizable=yes,scrollbars=yes,menubar=yes,status=yes');
	w.document.open('text/html');
	w.document.writeln('<html><body><pre>');
	for (var p in obj)
	{
		w.document.writeln(p + ' = ' + obj[p]);
	}
	w.document.writeln('</pre></body></html>');
	w.document.close();
}

