/*-------------------------------------------
	eResize
--------------------------------------------*/
function eResize(strIDs)
{
	var strTheIDs = strIDs.split(",");
	var winW = 630, winH = 460;
	var leftPos = 0;
	var i = 0;

	winW = document.body.clientWidth;

	if(winW >= 770) {
		leftPos = Math.floor(winW/2 - 385);
		for(i=0;i<strTheIDs.length;i+=2)
			$(strTheIDs[i]).style.left = leftPos + parseInt(strTheIDs[i+1],10);
	}
	else {
		for(i=0;i<strTheIDs.length;i+=2)
			$(strTheIDs[i]).style.left = parseInt(strTheIDs[i+1]);
	}

	for(i=0;i<strTheIDs.length;i+=2)
		$(strTheIDs[i]).style.visibility = "visible";
}

/*-------------------------------------------
	wGo
--------------------------------------------*/
function wGo(url){window.location.href=url;}

var unblurTimeout = {navRowOneTD: setTimeout("", 10), navRowTwoTD: setTimeout("", 10)};
function blurMenuBar(id)
{
	clearTimeout(unblurTimeout[id]);
	$(id).style.backgroundColor = "#CCE82E";
}
function unblurMenuBar(id)
{
	clearTimeout(unblurTimeout[id]);
	unblurTimeout[id] = setTimeout("$('"+id+"').style.backgroundColor = '#D6ED58';", 100);
}









var roundedEdgeCreate = new Array();
var roundedEdgeOnResize = new Array();

function addRoundedEdges(id, side, productName)
{
	var roundEdge = document.createElement("div");
	var prodNum = id.replace(/\D/g, "");
	var id2 = id.replace(/_zoom/, "_center");

	roundEdge.id = id + "_" + side + "_round_edge";
	roundEdge.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='media/png/standard-zoom-cr-"+side+".png')";
	roundEdge.innerHTML = "<img style='filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' src='media/png/standard-zoom-cr-"+side+".png' border='0' width='14' height='114' />";
	roundEdge.style.width = 14;
	roundEdge.style.height = 114;
	roundEdge.style.position = "absolute";
	roundEdge.style.top = LTSun.getElementTop(id);
	roundEdge.style.left = LTSun.getElementLeft(id) + (side=="left"?101:0);
	roundEdge.style.zIndex = 5;

	$(id).onmouseover = function(){if(loggedIn!="true"){$(id).onclick=function(event){getProduct(event, prodNum);};}showProductArrow(prodNum);};
	$(id).onmouseout = function(){hideProductArrow(prodNum);};
	
	$(id2).onmouseover = function(){if(loggedIn!="true"){$(id2).onclick=function(event){getProduct(event, prodNum);};}showProductArrow(prodNum);};
	$(id2).onmouseout = function(){hideProductArrow(prodNum);};

	$(id).style.cursor = "pointer";
	$(id2).style.cursor = "pointer";

	

	document.body.appendChild(roundEdge);
	
	$("top_left_prod_navigation").innerHTML += "<a id=\"prodNavTopLeft"+prodNum+"\" href=\"javascript:void(0);\" class=\"productNav\" onMouseOut=\"if(typeof(hideProductArrow)!='undefined')hideProductArrow("+prodNum+");\" onMouseOver=\"this.onclick=function(event){getProduct(event,'"+prodNum+"');};if(typeof(showProductArrow)!='undefined')showProductArrow("+prodNum+");\">"+productName+"</a>";
	$("top_left_prod_navigation").innerHTML += "<div style=\"font-size:1px;line-height:1px;height:2px;\">&nbsp;</div>";
}

function onResizeRoundedEdge(id, side)
{
	var tmpObj = document.getElementById(id + "_" + side + "_round_edge");
	if (document.getElementById(id).innerHTML.length < 30) {
		tmpObj.style.display = 'none';	
	} else {
		tmpObj.style.top = LTSun.getElementTop(id);
		tmpObj.style.left = LTSun.getElementLeft(id) + (side==="left"?102:0);
	}
}










function showNavDDMenu(num, callerId)
{
	var cIdWidth = LTSun.getElementWidth(callerId) + 10;
	var cIdLeft = LTSun.getElementLeft(callerId);
	var navContentId = "navMenuContent0"+num.toString();
	var navContent = $(navContentId);

	$("navMenuDDTopDiv").setStyle({width: cIdWidth});
	$("navMenuDDBottomDiv").setStyle({width: cIdWidth});
	$("navMenuDDTopImg").setStyle({width: cIdWidth});
	$("navMenuDDBottomImg").setStyle({width: cIdWidth});

	$("navMenuDDMiddleLeftDiv").setStyle({height: LTSun.getElementHeight(navContentId)-60});
	$("navMenuDDMiddleRightDiv").setStyle({height: LTSun.getElementHeight(navContentId)-60});
	$("navMenuDDMiddleLeftImg").setStyle({height: LTSun.getElementHeight(navContentId)-60});
	$("navMenuDDMiddleRightImg").setStyle({height: LTSun.getElementHeight(navContentId)-60});

	$("navMenuDDMiddleMiddleDiv").setStyle({width: cIdWidth});
	$("navMenuDDMiddleMiddleImg").setStyle({width: cIdWidth});
	$("navMenuDDMiddleMiddleDiv").setStyle({height: LTSun.getElementHeight(navContentId)-60});
	$("navMenuDDMiddleMiddleImg").setStyle({height: LTSun.getElementHeight(navContentId)-60});

	navContent.onmouseover = function(event){showNavDDMenu(num, callerId);};
	navContent.onmouseout = function(event){hideNavDDMenu(num);if(typeof(unblurMenuBar) == 'function'){unblurMenuBar('navRowOneTD');unblurMenuBar('navRowTwoTD');}};

	$("navMenuDropDownBg").setStyle({left: cIdLeft - 20, visibility: "visible"});
	navContent.setStyle({width: cIdWidth+12, left: cIdLeft-12, visibility: "visible"});

	if(typeof(unblurMenuBar) == 'function')unblurMenuBar('navRowOneTD');
	if(typeof(blurMenuBar) == 'function')blurMenuBar('navRowTwoTD');
}
function hideNavDDMenu(num)
{
	$("navMenuDropDownBg").setStyle({visibility: "hidden"});
	$("navMenuContent0"+num.toString()).setStyle({visibility: "hidden"});
}






var oscLoginWindowInError = false;

function oscLogin()
{
	new Ajax.Request
	(
		"catalog/login.php?action=process",
		{
			parameters:
			{
				email_address: $('ltsUsername').value,
				password: $('ltsPassword').value
			},

			onSuccess : function(transport)
			{
				if(transport.responseText.indexOf("Error") == -1)
				{
					window.location.reload(false);
				}
				else
				{
					oscLoginFail();
				}
			},

			onFailure : function(transport)
			{
				return oscLoginFail();
			}
		}
	);
}

function oscOpenLoginWindow()
{
	var loginHTML = "";

	loginHTML += "<center>";
	loginHTML += "<input type='button' value='Create New Account' style='width:130px;background-color:#f8981e;color:#ffffff;' onclick=\"wGo('create_account.php');\" />&nbsp;&nbsp;&nbsp;";
	loginHTML += "<input type='button' value='Forgot Password' style='width:130px;background-color:#ffffff;' onclick=\"wGo('password_forgotten.php');\" />&nbsp;&nbsp;&nbsp;";
	loginHTML += "<div style='font-size:1px;line-height:1px;height:8px;'>&nbsp;</div>";
	loginHTML += "<form id=\"loginForm\" onsubmit=\"LTSun.showLoadingWindow({afterFinish: function(){oscLogin();}}); return false;\">";
	loginHTML += "<table><tr><td id=\"ltsUsernameLoginTD\" align=\"right\" style=\"font-size:12px;color:#333333;font-weight:bold;\">";
	loginHTML += "E-mail: &nbsp;&nbsp; </td><td> <input id=\"ltsUsername\" type=\"text\" onKeyDown=\"oscRestoreLoginFail();\" />";
	loginHTML += "<div style=\"clear:both\"></div>";
	loginHTML += "</td></tr><tr><td colspan=\"2\" style=\"font-size:1px;line-height:1px;height:4px;\">&nbsp;";
	loginHTML += "</td></tr><tr><td id=\"ltsPasswordLoginTD\" align=\"right\" style=\"font-size:12px;color:#333333;font-weight:bold;\">";
	loginHTML += "Password: &nbsp;&nbsp; </td><td> <input id=\"ltsPassword\" type=\"password\" onKeyDown=\"oscRestoreLoginFail();\" /> <input type=\"submit\" style=\"display:none;visibility:hidden;\" />";
	loginHTML += "<div style=\"clear:both\"></div>";
	loginHTML += "</td></tr></table>";
	loginHTML += "</form>";
	loginHTML += "</center>";

/*	if(loggedIn != "true")
	{
*/		LTSun.showWindow({
			bgColor: "#CCE82E",
			bgFirstColor: "#000000",
			animationSpeed: 100,
			html: loginHTML,
			cancelLabel: "Quit",
			okLabel: "Login",
			okAction: "LTSun.showLoadingWindow({afterFinish: function(){oscLogin();}});",
			afterFinish: function(){$("ltsUsername").focus();}
		});
/*	}
	else
	{
		LTSun.showLoadingWindow({
			afterFinish: function()
			{
				new Ajax.Request
				(
					"LTSun-Engine/ltsun-logout.php",
					{
						onSuccess : function(transport)
						{
							if(transport.responseText == "true")
							{
								setTimeout("window.location.reload(false);", 1200);
							}
							else
							{
								oscLogoutFail();
							}
						},

						onFailure : function(transport)
						{
							oscLogoutFail();
						}
					}
				);
			}
		});
	}
*/
}


function oscLogout()
{
	LTSun.showLoadingWindow({
		afterFinish: function()
		{
			new Ajax.Request
			(
				"catalog/logoff.php",
				{
					onSuccess : function(transport)
					{
						setTimeout("window.location.reload(false);", 1200);
					},
	
					onFailure : function(transport)
					{
						setTimeout("window.location.reload(false);", 1200);
					}
				}
			);
		}
	});
}

function oscLoginFail()
{
	LTSun.hideLoadingWindow({
		afterFinish: function()
		{
			LTSun.morphWindow({bgColor: '#ff0000', textElementIDs:['ltsUsernameLoginTD','ltsPasswordLoginTD'],
				afterFinish: function()
				{
					oscLoginWindowInError = true;
				}
			});
		}
	});
}

function oscRestoreLoginFail()
{
	if(oscLoginWindowInError)
	{
		oscLoginWindowInError = false;
		LTSun.morphWindow({bgColor: '#CCE82E', fgColor: '#333333', textElementIDs:['ltsUsernameLoginTD','ltsPasswordLoginTD']});
	}
}

function oscLogoutFail()
{
	alert('Logout failure?!  Please Report this Error.');
	window.location.reload(false);
}








function showProductArrow(num)
{
	var id = "prodNavTopLeft"+num.toString();
	var arrow = $("productLeftLinksArrow");

	arrow.setStyle({
		top: LTSun.getElementTop(id)-5,
		left: LTSun.getElementLeft(id)-20,
		visibility: 'visible'
	});

	$(id).setStyle({
		color: "#222"
	});
}
function hideProductArrow(num)
{
	$("productLeftLinksArrow").setStyle({
		visibility: 'hidden'
	});

	$("prodNavTopLeft"+num.toString()).setStyle({
		color: '#999'
	});
}


function showProductShadow(num)
{
	var shadow = $("productMouseOverShadow");
	var id = "productCategory0"+num.toString();
	shadow.setStyle({
		top: LTSun.getElementTop(id),
		left: LTSun.getElementLeft(id),
		visibility: 'visible'
	});

	showProductArrow(num);

	shadow.onclick = $(id).onclick;
	shadow.onmouseover = function(){showProductShadow(num);};
	shadow.onmouseout = function(){hideProductShadow(num);};

	id = "underImgsProd"+num.toString();
	$(id).setStyle({
		color: "#222"
	});
}
function hideProductShadow(num)
{
	$("productMouseOverShadow").setStyle({
		visibility: 'hidden'
	});

	hideProductArrow(num);

	$("underImgsProd"+num.toString()).setStyle({
		color: '#999'
	});
}



function addProductToCart(prodId)
{
	new Ajax.Request
	(
		"catalog/index.php?action=buy_now&products_id=" + prodId,
		{
			onSuccess : function(transport)
			{
				getCart(false);
			},

			onFailure : function(transport)
			{
				alert("Error: Unable to add product to cart. Network Connection Disabled.");
			}
		}
	);
}


/*		function addProductToCart_TEMP(prodId)
{
	if(!$("addCartIframe"))
	{
		var iframe = document.createElement("iframe");

		iframe.setAttribute("id", "addCartIframe");
		iframe.setAttribute("frameBorder", "0");
		iframe.setAttribute("marginWidth", "0");
		iframe.setAttribute("marginHeight", "0");
		iframe.setAttribute("leftMargin", "0");
		iframe.setAttribute("topMargin", "0");
		iframe.setAttribute("border", "0");
		iframe.setAttribute("style", "position:absolute;top:0px;left:0px;visibility:hidden;");
		iframe.setAttribute("width", 0);
		iframe.setAttribute("height", 0);
		iframe.setAttribute("allowtransparency", "true");
		iframe.allowTransparency = "true";
		iframe.setAttribute("scrolling", "no");

		iframe.setAttribute("src", "catalog/index.php?action=buy_now&products_id=" + prodId);

		document.body.appendChild(iframe);
	}
}

function finishAddProductToCart()
{
	if($("addCartIframe"))
	{
		getCart();
		document.body.removeChild($("addCartIframe"));
	}
}*/

function getCart(change)
{
	var cart = $("shoppingCartMiddlePadding");

	new Ajax.Request
	(
		"catalog/shopping_cart.php?action=update_product&regCheck=true",
		{
			method     : 'post',
			parameters : (change?($("cart_quantity")?Form.serialize("cart_quantity"):""):""),
			onSuccess  : function(transport)
			{
				cart.innerHTML = transport.responseText;
				setInterval("updateCartHeight()", 500);
			},

			onFailure : function(transport)
			{
				cart.innerHTML = transport.responseText + " Error...";
			}
		}
	);
}

function updateCartHeight()
{
	var leftColUpperH = LTSun.getElementHeight("leftColUpper");
	var mainRightColumnH = LTSun.getElementHeight("mainRightColumn");
	var theDifference = mainRightColumnH - leftColUpperH;

	theDifference = (theDifference>350?theDifference:350);

	if(theDifference > LTSun.getElementHeight("shoppingCartMiddlePadding"))
	{
		$("shoppingCartMiddlePadding").setStyle({
			height: theDifference - 20
		});

		if($("leftColLowerEC"))
		{
			$("leftColLowerEC").setStyle({
				height: theDifference - 30
			});
		}
	}
}

function getProduct(e, prodId)
{
	if($("window_productBgDiv")) destroyProduct(e);

	var productBgDiv = document.createElement("div");
	var productContentDiv = document.createElement("div");

	var posx = 0;
	var posy = 0;

	if(!e) var e = window.event;

	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	/*-------------
	Product BG Div
	-------------*/
	productBgDiv.id = "window_productBgDiv";
	productBgDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='media/popup.png')";
	productBgDiv.innerHTML = "<img style='filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' src='media/popup.png' border='0' width='519' height='360' />";
	productBgDiv.style.width = 519;
	productBgDiv.style.height = 360;
	productBgDiv.style.position = "absolute";
	productBgDiv.style.top = posy;
	productBgDiv.style.left = LTSun.getElementLeft("mainRightColumn")-17;
	productBgDiv.style.zIndex = 500;


	/*------------------
	Product Content Div
	------------------*/
	productContentDiv.id = "window_productContentDiv";
	productContentDiv.style.width = 500;
	productContentDiv.style.position = "absolute";
	productContentDiv.style.top = posy+10;
	productContentDiv.style.left = LTSun.getElementLeft("mainRightColumn")-7;
	productContentDiv.style.zIndex = 501;

/*			if(!$("window_productBgDiv"))
	{
	
*/
		okayToDestroyProduct = false;
		document.body.appendChild(productBgDiv);
		document.body.appendChild(productContentDiv);
/*			}*/


/*			new Ajax.Request
	(
		"catalog/product_info.php?products_id=" + prodId,
		{
			onSuccess : function(transport)
			{
				productContentDiv.innerHTML = transport.responseText + "<textarea style='width:500px;height:300px;'>" + transport.responseText + "</textarea>";
			},

			onFailure : function(transport)
			{
				productContentDiv.innerHTML = transport.responseText + "<textarea style='width:500px;height:300px;'>" + transport.responseText + "</textarea>";
			}
		}
	);*/


	new Ajax.Updater
	(
		"window_productContentDiv",
		"catalog/product_info.php?products_id=" + prodId,
		{
			parameters: "rt89ry=" + loggedIn,
			evalScripts: true,
			onSuccess: function(){okayToDestroyProduct = true;}
		}
	);

/*alert($("window_productContentDiv").innerHTML);*/

}


/*Ajax.Responders.register({
onCreate: function() {
Ajax.activeRequestCount++;
},
onComplete: function() {
Ajax.activeRequestCount--;
}
});*/
var okayToDestroyProduct = true;
function destroyProduct(e)
{
	if($("window_productBgDiv") && okayToDestroyProduct && !$("window_screenLockDiv"))
	{
		var posx = 0;
		var posy = 0;

		var prodBgTop = LTSun.getElementTop("window_productBgDiv");
		var prodBgLeft = LTSun.getElementLeft("window_productBgDiv");

		if(!e) var e = window.event;

		if (e.pageX || e.pageY)
		{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
/*alert(
"posy: " + posy +
"\nprodBgTop: " + prodBgTop + "-" + (prodBgTop+360) +
"\nposx: " + posx +
"\nprodBgLeft: " + prodBgLeft + "-" + (prodBgLeft+519) +
"\n\ny: " + (posy < prodBgTop || posy > prodBgTop+360) +
"\n\nx: " + (posx < prodBgLeft || posx > prodBgLeft+519)
);*/

		if((posy < prodBgTop || posy > prodBgTop+360) || (posx < prodBgLeft || posx > prodBgLeft+519))
		{
			document.body.removeChild($("window_productContentDiv"));
			document.body.removeChild($("window_productBgDiv"));
		}
	}
}


var fullProductDescription = "";
function readMoreProdDesc()
{
	if($("productDescriptionAndAttrib"))
	{
/*
overflow: -moz-scrollbars-vertical;
overflow: auto;
overflow-y: scroll;
overflow-x: hidden;
*/
		$("productDescriptionAndAttrib").setStyle({
			overflow: 'auto',
			overflow: '-moz-scrollbars-vertical',
			overflowY: 'scroll',
			overflowX: 'hidden'
		});

		$("fullProdDescription").innerHTML = fullProductDescription;
	}
}


