//Site-wide functions

sfHover = function() {
	var sfEls = document.getElementById("topNav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function printprod(prodId) {
	window.open('/prodprint.asp?prodId='+prodId, 'prodpopup', 'width=700,height=500,toolbar=1,scrollbars=1')
}

function swapProdPic(picid,newpath) {
	document.getElementById(picid).src = newpath;
	//Effect.BlindDown(picid);
}

var escapeOverlay = {
	fx: function(e) 
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
		
		// If keypressed is escape and the new entry field is empty
		if(kC==Esc) {
			closeDialogue('signup');
			closeDialogue('email');
		}
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup(divprefix,dowhat) {
	showOverlay(divprefix);
	
	$(divprefix+'dialogue').show();
	
	if(dowhat == 'form') {
		$('senderform').show();
		$('thanks').hide();
	}else if(dowhat == 'thanks') {
		$('senderform').hide();
		$('thanks').show();
	}
}
 
// Shows the overlay and starts the ESCAPE event listener
function showOverlay(divprefix) {
	$(divprefix+'overlay').show();
	Event.observe(document, 'keypress', escapeOverlay.bfx);
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay(divprefix) {
	$(divprefix+'overlay').hide();
	Event.stopObserving(document, 'keypress', escapeOverlay.bfx);
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue(divprefix) {
	hideOverlay(divprefix);
	$(divprefix+'dialogue').hide();
}
