var previousScrollTop = 0; /* Law var */
var currentScrollTop = 0; /* Law var */
var heightOffset = 50 + 50; /*85 + 50;*/ /*81 + 50;*/ /* Law var */

/* SOURCE: http://javascript.about.com/library/blxdom.htm */
// Cross Browser DOM
// copyright Stephen Chapman, 4th Jan 2005
// you may copy this code but please keep the copyright notice as well
var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById;

if (stdDOM) {
	aDOM = 1;
} else {
	ieDOM = document.all;

	if (ieDOM)
		aDOM = 1;
	else {
		var nsDOM = ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) ==4));

		if (nsDOM)
			aDOM = 1;
	}
}

function xDOM(objectId, wS)
{
	if (stdDOM)
		return wS ? document.getElementById(objectId).style : document.getElementById(objectId);

	if (ieDOM)
		return wS ? document.all[objectId].style : document.all[objectId];

	if (nsDOM)
		return document.layers[objectId];
}

/* SOURCE: http://javascript.about.com/library/blscreen2.htm */
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth()
{
	return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;
}

function pageHeight()
{
	return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;
}

function posLeft()
{
	return window.pageXOffset != null? window.pageXOffset: document.body.scrollLeft != null? document.body.scrollLeft:0;
}

function posTop1()
{
	currentScrollTop = document.body.scrollTop;

	/* Law: Translated from short syntax and altered logic */
	if (currentScrollTop != null) {
		if (currentScrollTop < heightOffset) {
			return 0;
		} else {
			// Substract heightOffset from document.body.scrollTop
			// so that object will line up perfectly with top of
			// browser screen.
			return currentScrollTop - heightOffset;
		}
	} else {
		return 0;
	}
}

function posTop2()
{
	currentScrollTop = document.body.scrollTop;

	/* Law: Translated from short syntax and altered logic */
	if (currentScrollTop <= previousScrollTop) {
		if ((currentScrollTop - heightOffset) >= 0) {
			return currentScrollTop - heightOffset; // just align with the top of the viewable browser screen
		} else {
			return 0; // you're so close to the header, that you might as well be adjacent to it.
		}
	} else {
		// Substract heightOffset from document.body.scrollTop
		// so that object will line up perfectly with top of
		// browser screen.
		return -1; // sentinel to indicate that scrolling down should cause no movement of object
	}
}

function posRight()
{
	return posLeft()+pageWidth();
}

function posBottom()
{
	return posTop()+pageHeight();
}

/* SOURCE: http://javascript.about.com/library/blobja2.htm */
// More Object Functions
// copyright Stephen Chapman, 18th Jan 2005
// you may copy these functions but please keep the copyright notice as well
function setObjVis(objectID,vis)
{
	var objs = xDOM(objectID,1);
	objs.visibility = vis;
}

function toggleObjVis(objectID)
{
	var objs = xDOM(objectID,1);
	var vis = objs.visibility;
	objs.visibility = (vis == "visible" || vis == "show") ? 'hidden' : 'visible';
}

function moveObjTo(objectID,x,y)
{
	var objs = xDOM(objectID,1);
	objs.left = x;
	objs.top = y;
}

function moveObjBy(objectID,x,y)
{
	var obj = xDOM(objectID,0);
	var objs = xDOM(objectID,1);
	if (obj.offsetLeft != null) {
		var l = obj.offsetLeft;
		var t = obj.offsetTop;
		objs.left = l+x; objs.top = t+y;
	} else if (objs.pixelLeft != null) {
		objs.pixelLeft += x;
		objs.pixelTop += y;
	} else obj.moveBy(x,y);
}

function moveObjLayer(objectID,z)
{
	var objs = xDOM(objectID,1); objs.zIndex = z;
}





function start()
{
	var x = (0) + 'px';
	var y = (posTop()-100) + 'px';

	moveObjTo('myobj',x,y);

	setObjVis('myobj','visible');
}

function start1()
{
	var x = 0;
	var y = posTop1();

	moveObjTo('myobj',x + 'px',y + 'px');

	previousScrollTop = currentScrollTop;

	setObjVis('myobj','visible');
}

function start2()
{
	var x = 0;
	var y = posTop2();

	if (y != -1) {
		moveObjTo('myobj',x + 'px',y + 'px');
		previousScrollTop = currentScrollTop;
	}

	setObjVis('myobj','visible');
}

// the number of related product boxes
// to be displayed on this page
var currId = null;

/**
 * Updates the related product boxes so
 * that the active box is highlighted.
 *
 * @id int id of the active box
 *
 * NOTE:
 * The expectation is that the boxes are
 * listed one after another and that each
 * box is labeled with id="i" where i is
 * in the range 1 <= i <= numBoxes.
 */
function updateBoxHighlights(id, recenter, newUrl)
{
	if (newUrl) {
	self.iframe1.location.replace(newUrl);
	}
	// Each time a box is clicked, all of the
	// boxes need to be updated to make sure
	// that they are not highlighted unless "active".
	if (id != null) {
		if (currId != id) {
			document.getElementById(id).style.backgroundImage = 'url("/images/onlinephonestore_new/related_items_active_triangle.gif")';
			if (currId != null) {
				document.getElementById(currId).style.backgroundImage = 'url("/images/spacer.gif")';
			}
		}
	}
	currId = id;
	if (recenter)
		start1();
}
