var BBDetailPop = new Object();

BBDetailPop.openZoomer = null;
BBDetailPop.timeoutZoomer = 1000;
BBDetailPop.timeoutIdZoomer = null;

BBDetailPop.openChild = null;
BBDetailPop.containerDiv = null;

BBDetailPop.showZoomer = function(id)
{
	var zoomer = document.getElementById(id);
	
	if (BBDetailPop.openZoomer)
	{
		if (BBDetailPop.openZoomer.id != id)
		{
			BBDetailPop.openZoomer.style.display = "none";
		}

		if (BBDetailPop.timeoutIdZoomer)
		{
			clearTimeout(BBDetailPop.timeoutIdZoomer);
		}
	}
	
	zoomer.style.display = "block";
	BBDetailPop.openZoomer = zoomer;
}

BBDetailPop.hideZoomer = function()
{
	var cmd = "BBDetailPop.openZoomer.style.display = 'none'; BBDetailPop.openZoomer = null";
	BBDetailPop.timeoutIdZoomer = setTimeout(cmd, BBDetailPop.timeoutZoomer);
}

BBDetailPop.pop = function(id, listSrc)
{
	var rgs, parent, child, top, left, offset, offsetContainer;
	var zoomSrc = listSrc.replace(/\/list\//, "/detail/");

	BBUtil.closeAllDHTMLPops("BBDetailPop");

	parent = document.getElementById(id);
	child = document.getElementById(parent.id+"_child");

	if ((BBDetailPop.openChild != null) &&
			(BBDetailPop.openChild.id != parent.id+"_child"))
	{
		clearTimeout(BBDetailPop.timeoutId);
		BBDetailPop.openChild.style.display = "none";
	}

	child.style.position = "absolute";
	child.style.left = "-1000px";
	child.style.top = "-1000px";
	child.style.display = "block";

	/*offset = BBUtil.getXYOffset(parent);
	offsetContainer = BBUtil.getXYOffset(BBDetailPop.containerDiv);*/
	offset = new Array();
	offset["x"] = parent.offsetLeft;
	offset["y"] = parent.offsetTop;
	offsetContainer = new Array();
	offsetContainer["x"] = BBDetailPop.containerDiv.offsetLeft;
	offsetContainer["y"] = BBDetailPop.containerDiv.offsetTop;

//alert(offset["x"]+","+offset["y"]+":"+offsetContainer["x"]+","+offsetContainer["y"]);
	if ((offset["x"] + child.offsetWidth) >= BBDetailPop.containerDiv.offsetWidth)
	{
		left = offset["x"] - (child.offsetWidth - parent.offsetWidth);
	}
	else
	{
		left = offset["x"];
	}
	
	if ((offset["y"] + child.offsetHeight) >= BBDetailPop.containerDiv.offsetHeight)
	// If child will extend below the height of the offset container... let that happen
	{
		//top = offset["y"] - (child.offsetHeight - parent.offsetHeight);
		if ((window.navigator.userAgent.match(/msie/i)) &&
				parent.className.match(/bb_button_set/))
		{
			top = offset["y"] - 2 - parent.offsetHeight;
		}
		else
		{
			top = offset["y"] - 2;
		}
	} 
	else
	{
		top = offset["y"] - 2;
	}
	
	child.style.top = top+"px";
	child.style.left = left+"px";
	child.style.display = "block";

	BBDetailPop.mouseOutParent = false;
	BBDetailPop.mouseOutChild = true;
	BBDetailPop.openChild = child;

	document.getElementById(id+"_img_zoom").src = zoomSrc;
}

BBDetailPop.close = function()
{
	if (BBDetailPop.openChild)
	{
		BBDetailPop.openChild.style.display = "none";
	}
}

BBDetailPop.init = function(root)
{
	var i, c, node, rgs;

	if (BBDetailPop.containerDiv == null)
	{
		BBDetailPop.containerDiv = root;
	}
}


BBDetailPop.cartQtyInc = function(id)
{
	var qty = 1 + parseInt(document.getElementById(id).value);
	document.getElementById(id).value = qty;
}

BBDetailPop.cartQtyDec = function(id)
{
	var qty = parseInt(document.getElementById(id).value) - 1;
	if (qty > 0)
	{
		document.getElementById(id).value = qty;
	}
}

BBDetailPop.switchButtonSetImg = function(imgId, tgtDir)
{
	var el = liltype.ds(imgId);
	el.src = el.src.replace(/\/[^\/]+\/([^\/]+)$/, "/"+tgtDir+"/$1");
}