/*  IE hack: Add mouseover event to navbar list items.  */

// Popup function for shopping cart images.
function popImg( triggerId ) 
{
	var idParts = triggerId.split('-');
	var itemId = parseInt( idParts[1] );

	// Check for existence of item array for popups.
	type = typeof imgInfo;

	if( type != 'undefined' ) {

		// Iterate through imgInfo array.
		for( var i= 0; i < imgInfo.length; ++i ) {

			if( imgInfo[i][0] == itemId ) {

				var imgName = imgInfo[i][1];
				var imgWidth = parseInt(imgInfo[i][2]);
				var imgHeight = parseInt(imgInfo[i][3]);
			}
		}
	} else {
		return false;
	}

	var viewWidth = parseInt( imgWidth ) + 60;
	var viewHeight = parseInt( imgHeight ) + 100;
	viewWidth = viewWidth.toString();
	viewHeight =  viewHeight.toString();

	var uri = "./popup.php?img=" + imgName + "&width=" + imgWidth + "&height=" + imgHeight;

	var look="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + viewWidth + ",height=" + viewHeight;
	imgWin=window.open( uri, "", look );
}

startList = function() 
{
	var navRoots = new Array();
	navRoots[0] = "nav";
	navRoots[1] = "nav2a";
	navRoots[2] = "nav2b";
	navRoots[3] = "nav2c";

	if ( document.all && document.getElementById ) 
	{
		for (root in navRoots)
		{
			navRoot = document.getElementById(navRoots[root]);
			for (var i=0; i<navRoot.childNodes.length; i++) 
			{
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") 
				{
					node.onmouseover=function() 
					{
						this.className+=" over";
					}
  					node.onmouseout=function() 
					{
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
	}

	if ( document.getElementById ) 
	{

		// Set button behavior.
		var buttonParent = document.getElementById("divButtons");
		if ( buttonParent != null ) {
			for (var i=0; i < buttonParent.childNodes.length; i++) {
				node = buttonParent.childNodes[i];
					if (node.nodeName=="INPUT") {
						node.onmouseover=function() {
							this.className=this.className.replace("buttonOff", "buttonOn");
						}
	  					node.onmouseout=function() {
							this.className=this.className.replace("buttonOn", "buttonOff");
						}
					}
				}
		}

		// Check for existence of item array for popups.
		type = typeof imgInfo;

		if( type != 'undefined' ) {

			// Iterate through imgInfo array.
			for( var i= 0; i < imgInfo.length; ++i ) {

				// Create element names.
				var thumbId = 'img-' + imgInfo[i][0];
				var h3Id = 'h3-' + imgInfo[i][0];
				var anchorId = 'a-' + imgInfo[i][0];

				// Get elements for attachments.
				var thumb = document.getElementById( thumbId );
				var h3 = document.getElementById( h3Id );
				var anchor = document.getElementById( anchorId );

				// Attach onclick event to launch popups.
				thumb.onclick = function( ) 
				{
					popImg( this.id );
				}
				h3.onclick = function()
				{
					popImg( this.id );
				}
				anchor.onclick = function()
				{
					popImg( this.id );
					return false;
				}
			}
		}
	}

	// Be sure we can do this.
	if ( document.getElementsByTagName ) {

		// Get the buttons.
		var inputs = document.getElementsByTagName("INPUT");

		// If the page has INPUT tag, search for those with CLASS="submit0"
		// and attach the events.
		if( inputs ) {

			for ( i = 0; i < inputs.length;  i++) {

				var node = inputs[i];

				if (node.className == "submit0") {
					node.onmouseover = function() {
						this.className = this.className.replace("submit0", "submit1");
					}
					node.onmouseout = function() {
						this.className = this.className.replace("submit1", "submit0");
					}
				}
			}
		}
	}
}


/*  Email address writer:  */

function writeEmail(pop, text)
{
   var server = "br-beads.com";
   document.write('<a href=mailto:' + pop + '@' + server + '>' + text + '</a><br />');
}


/*  Popup window writer:  */

function popUp(image_url, width, height) 
{
   var view_width = parseInt(width) + 40;
   var view_height = parseInt(height) + 70;

   var view_width = view_width.toString();
   var view_height =  view_height.toString();

   var look="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + view_width + ",height=" + view_height;

   popwin=window.open("","",look);
   popwin.document.open();
   popwin.document.write('<head><title>Close Up</title>');
   popwin.document.write('<link rel="stylesheet" href="http://www.br-beads.com/style.css" type="text/css" />');
   popwin.document.write('<meta http-equiv="imagetoolbar" content="no">');
   popwin.document.write('</head>');
   popwin.document.write('<body id="imgPop">');
   popwin.document.write('<div align="center">');
   popwin.document.write('<img src="'+image_url+'" />');
   popwin.document.write('<form><input type="submit" value="Close" class="close0" onmouseover="this.className=\'close1\'" onmouseout="this.className=\'close0\'" onclick="self.close();" /></form>');
   popwin.document.write('</div>');
   popwin.document.write('</body>');
   popwin.document.close();

}