﻿/*********************************************************************************************
 *	This script generates the header, navigation menus and popups for the Prepac html pages.
 *	It also contains utility functions for these main functions.
 *
 *	Main functions:
 *
 *				generateMainNavigation		writes the html for the page top navigation
 *				generateSubnavigation			writes the html for the page sub navigation items
 *				generateFooterNavigation	writes the html for the page footer navigation
 *				swapVideo									writes html for video objects
 *				zoomImage									writes html for showing/hiding thumbnail and large images
 *				popUp											opens a popup window for a url centered in the browser window
 *
***********************************************************************************************/
 
	var defaultNavPath 				= "../"; // all sub and form pages use this path
	var defaultImageHolderId 	= "imgHolder";
	var defaultVideoHolderId	= "videoHolder";
	
	var menu;
	var menuArrow = '<span style="color:#efefef;font-size:11px;">&nbsp;&darr;</span>';
	var menuSelectedSubnav;
	
	/********************************************************
	* Generate the main navigation for the page. (WITH DROPDOWN MENUS)
	*
	*	Arguments:
	*	selectedItem:		(required) 	id of the link to highlight for the page eg: 'navHome'
	*	path:						(optional) 	path to the resources; default is $defaultNavPath
	*
	********************************************************/	
	function generateMainNavigation2(selectedItem, path) {
	
		var submenu_navProfile = {
				"-"											: "~about/index.html",
				"The Prepac Advantage"	: "~about/advantage.html",
				"Company History" 			: "~about/history.html",
				"Contact Us"						: "~about/corporatecontact.html",
				"Careers"								: "~about/careers.html",
				"Locations"							: "~about/locations.html"
			};
      
      var submenu_navProducts = {
				"-"											                  : "~products/index.html",
				"Bedroom Furniture"	                      : "~products/bedroom.html",
				"Platform Storage Beds and Headboards" 	  : "~products/storagebeds.html",
				"Audio-Video Furniture and Media Storage"	: "~products/avmedia.html",
				"Entryway and Office"							        : "~products/entryoffice.html",
        "Utility Storage and Kitchens" 	          : "~products/utilitykitchens.html",
				"Product Features and Construction"			  : "~products/features.html",
				"Request a Product Catalog"							  : "~about/contactform.html"
			};  
	 			
		var submenu_navSupport = {
				"-"													: "~support/index.html",
	      "Shipping Damage"						: "~support/damage.html",
		  "Order Parts" 					: "~support/order.html",
	      "Request Instructions"			: "~support/instructions.html", 
	      "Assembly Help" 						: "~support/assemblyhelp.html",
	      "Assembly Help & Videos"						: "~support/assemblyvideos.html",	
	      "Return / Refund Policy"		: "~support/policies.html",
	      "Order Tracking"						: "~support/ordertracking.html",
	      "Product Care and Warranty"	: "~support/care.html" 
		};
	
		var submenu_navNew = {
				"News & Events"										: "~new/index.html",
	      "Las Vegas Showroom"	: "~new/showroom.html",
			  "Events" 							: "~new/events.html"
			};
			
		menu = { 
				"navProfile" 	: submenu_navProfile,
        "navProducts" : submenu_navProducts,
				"navSupport" 	: submenu_navSupport, 
				"navNew" 			: submenu_navNew 
		};

		path = (path ? path : defaultNavPath);
		menu = convertMenu(menu, path);
		
		var menuArray = new Array(
				'<table class="mast" cellpadding="0" cellspacing="0">',
				'	<tr>',
				'		<td width="100%" colspan="2" style="background:#cc0000;" nowrap><a	href="~index.html" title="www.prepacmfg.com"><img	src="~images/logo-top.gif"',
				'			alt="Prepac Manufacturing - RTA Furniture, Casual Home Furnishings, Home and Kitchen and Entertainment Storage"',
				'			width="120" height="32" border="0" /></a></td>',
				'	</tr>',
				'	<tr>',
				'		<td width="355"><a href="~index.html" title="www.prepacmfg.com"><img',
				'			src="~images/logo-bottom.gif" alt="" width="120" height="21"',
				'			border="0" /></a><br />',
				'		<img src="~images/spacer.gif" width="1" height="5" border="0" /></td>',
				'		<td width="420" align="right" valign="top"><img',
				'			src="~images/RTA.gif" width="125" height="18" alt="RTA Furniture Manufacturer" style="margin-right:3px;" border="0" /></td>',
				'	</tr>',
				'	<tr>',
				'		<td width="100%" colspan="2" valign="top"><!--- top navigation --->',
				'		<table width="100%" cellpadding="0" cellspacing="0">',
				'			<tr>',
				'				<td width="100%" style="background:#9c9a9c;">',
				'				<div class="navMenu">',
				'				<div class="horz_menu">',
				'					<a id="navHome" href="~index.html">Home</a><span style="color:#efefef;font-size:9px;">&nbsp;|</span>',
				'					<a id="navProfile" href="~about/index.html">Company	Profile*</a>',
				'					<a id="navProducts" href="~products/index.html">Products*</a>',
				'					<a id="navSupport"  href="~support/index.html">Product Support*</a>',
				'					<a id="navNew" href="~new/index.html">News & Events*</a>',
				'				</div>',
				'				<div id="dropdownMenu" style="background:#fefefe;height:10px;"></div>',
				'				</td>',
				'			</tr>',
				'		</table>',
				'		</td>',
				'	</tr>',
				'</table>'
		);
	
		writeNavArray(menuArray, path, selectedItem);
		addEvent(window, 'load', buildMenu); // to build the menu when page loads
	}

	/**************************************************************************************
	*	Generate the main navigation for the page. (NO DROPDOWN MENU)
	*
	*	Arguments:
	*	selectedItem:		(required) 	id of the link to highlight for the page eg: 'navHome'
	*	path:						(optional) 	path to the resources; default is $defaultNavPath
	*
	***************************************************************************************/
	function generateMainNavigation(selectedItem, path) {
	
		// generate a text array substituting "~" for the relative path
		var htmlArray = new Array(
				'  <table class="mast" cellpadding="0" cellspacing="0">',
				'    	<tr>',
				'    		<td width="100%" colspan="2" style="background:#cc0000;" nowrap><a href="~index.html" title="www.prepacmfg.com"><img src="~images/logo-top.gif" alt="Prepac Manufacturing - RTA Furniture, Casual Home Furnishings, Home and Kitchen and Entertainment Storage" width="120" height="32" border="0" /></a></td>',
				'    	</tr>',
				'    	<tr>',
				'    		<td width="355"><a href="~index.html" title="www.prepacmfg.com"><img src="~images/logo-bottom.gif" alt="" width="120" height="21" border="0" /></a><br/><img src="~images/spacer.gif" width="1" height="5" border="0" /></td>',
				'    		<td width="420" align="right" valign="top"><img src="~images/RTA.gif" alt="RTA Furniture Manufacturer" width="125" height="18" style="margin-right:3px;" border="0" /></td>',
				'    	</tr>',
				'      <tr>',
				'    		<td width="100%" colspan="2" valign="top">',
				'<!--- top navigation --->',
				'        <table width="100%" cellpadding="0" cellspacing="0">',
				'    			<tr>',
				'    				<td class="nav">',
				'								<a id="navHome" href="~index.html">Home</a> |',
				'								<a id="navProfile" href="~about/index.html">About</a> | ',
				'								<a id="navProducts" href="~products/index.html">Products</a> | ',
				'								<a id="navSupport" href="~support/index.html">Product Support</a> | ',
				'								<a id="navNew" href="~new/index.html">News & Events</a></td>',
				'    			</tr>',
				'        </table>',
				'<!--- END top navigation --->',
				'        </td>',
				'    	</tr>',
				'    </table>'
	 		);
	 		
	 		writeNavArray(htmlArray, (path ? path : defaultNavPath), selectedItem);
	}

	/**************************************************************************************
	*	Generate the footer navigation
	*
	*	Arguments:
	*	path:		(optional) path to the resources - default is $defaultNavPath
	*
	***************************************************************************************/
	function generateFooterNavigation(path) {
		var htmlArray = new Array(
				'  <table class="footer" cellpadding="0" cellspacing="0">',
				'    	<tr>',
				'    		<td align="center"><a href="~index.html">Home</a> | <a href="~about/index.html">About</a> | <a href="~products/index.html">Products</a> | <a href="~support/index.html">Product Support</a> | <a href="~new/index.html">News & Events</a></td>',
				'    	</tr>',
				'  </table>'
	 		);
	 		
 		writeNavArray(htmlArray, (path ? path : defaultNavPath));
	}
	/**************************************************************************************
	*	Generate the page sub navigation for the type (title)
	*
	*	Arguments:
	*	title:			(required) 	The title of the sub navigation, used to get the array of sub nav items
	*	path:				(optional) 	path to the sub nav page resources; default is blank for the current directory.
	*	selectItem:	(optional) 	page name to match the item that should be selected.  default is current page
	*							This is only needed when the link to be selected is different from the page displayed.
	*							[eg: use "corporatecontact.html" for forms/contact/thanks.html]
]	*
	***************************************************************************************/
	function generateSubnavigation(title, path, selectedItem) {
		var htmlArray = new Array(
			 '      <table width="100%" cellpadding="0" cellspacing="0">',
			 '         <tr>',
			 '           <td class="pageID">',
			 '             <a class="selected" href="index.html">~TITLE~</a>',
			 '           </td>',
			 '         </tr>',
			 '       	<tr>',
			 '       		<td valign="top">',
			 '           <!--subnav-->',
			 '       		<table class="subnav" cellpadding="0" cellspacing="0">',
			 '       			<tr>',
			 '       				<td valign="top">',
			 '                 ~SUBNAVITEMS~',
			 '              </td>',
			 '       		  </tr>',
			 '           </table>',
			 '           <!--END subnav-->',
			 '           </td>',
			 '         </tr>',
			 '   	  </table>'
			);
		var subnavArray;
		
		if (title == "About") {
			subnavArray = new Array(
				"advantage.html", 			"The Prepac Advantage",
 				"history.html", 				"Company History",
 				"corporatecontact.html","Contact Us",
 				"careers.html", 				"Careers",
 				"locations.html", 			"Locations"
 			);
 			
 		} else if (title == "Products") {
			subnavArray = new Array(
        "bedroom.html",         "Bedroom Furniture"	,                      
				"storagebeds.html",     "Platform Storage Beds and Headboards",	  
				"avmedia.html",         "Audio-Video Furniture and Media Storage",	
				"entryoffice.html",     "Entryway and Office",						        
        "utilitykitchens.html", "Utility Storage and Kitchens", 	          
				"features.html",        "Product Features and Construction",			  
				"../about/contactform.html", "Request a Product Catalog"							  
			);
      
 		} else if (title == "Product Support") {
			subnavArray = new Array(
        "damage.html", 					"Shipping Damage",
			  "order.html", 					"Order Parts",
               "instructions.html", 		"Request Instructions",
        "assembly.html",	"Assembly Help & Videos",
        "policies.html", 				"Return / Refund Policy",
        "ordertracking.html",		"Order Tracking",
        "care.html", 						"Product Care and Warranty"
			);
      		
 		} else if (title == "News & Events") {
			subnavArray = new Array(
        "showroom.html", 				"Las Vegas Showroom",
			  "events.html", 					"Events"
			);
 		}
 	 	
 	 	menuSelectedSubnav = (selectedItem ? selectedItem : getPageName());
 	
 		writeSubnavArray(htmlArray, title, subnavArray, path, menuSelectedSubnav);
	}

 	/**************************************************************************************
	*	Zoom Image - swapping routine to zoom thumbnail images
	*
	*	Arguments:
	*	id:						(required) 	The id of the image to be zoomed
	*	imgHolderId:	(optional) 	The id of the zoomed image place holder; default is $defaultImageHolderId
	*
	***************************************************************************************/
	var currentZoomedImage; // hold the current zoomed image
 	
 	/** Zoom an image when link or image is clicked **/
 	function zoomImage(id, imgHolderId) {
  	var image = document.getElementById(id);
  	if (!image) {
  		return;
  	}
 		if (image.src == currentZoomedImage) {
 			zoomImageOff();
 		} else {
 			currentZoomedImage = image.src;
 			imgHolderId = (imgHolderId ? imgHolderId : defaultImageHolderId);
 			var imgHolder = document.getElementById(imgHolderId);
 			imgHolder.firstChild.src = image.src;
 			imgHolder.style.top = findPosY(image) + "px";
 			imgHolder.style.left = findPosX(image) + "px";
 			imgHolder.style.display='block';
		}	
 	}
 	
 	/***************************************************************************************
	*	Zoom an image OFF when zoomed image is clicked
	*
	*	Arguments:
	*	imgHolderId:	(optional) 	The id of the zoomed image place holder; default is $defaultImageHolderId
	*
	****************************************************************************************/
 	function zoomImageOff(imgHolderId) {
 		currentZoomedImage = "";
 		imgHolderId = (imgHolderId ? imgHolderId : defaultImageHolderId);
 		document.getElementById(imgHolderId).style.display='none';
 	}
 	
  /*****************************************************************************
	*  Loads a video name in the video place holder
	*
	*	 Arguments:
	*			videoName:			(required) 	The url of the video to be displayed
	*			videoHolderId:	(optional)	The id of the place holder for the video; default is $defaultVideoHolderId
	*			width:					(optional)  The width of the video; default is 425
	*			height:					(optional)  The height of the video; default is 200
	*
	******************************************************************************/
	function swapVideo(videoName, videoHolderId, width, height) {
	
		if (!videoHolderId) {
				videoHolderId = defaultVideoHolderId; // default video place holder name
			}
			var videoHolder = document.getElementById(videoHolderId);
			
			var w = (width && width > 10 ? width : 400);
			var h = (height && height > 10 ? height : 256);
			var ext = getExtensionType(videoName);
			
			var objectHtmlArray;
			
			// MP4, MPEG, MOV - Quicktime 
			if (ext == "mp4" || ext == "mov" || ext == "mpeg") {
				objectHtmlArray = new Array(
					'<object id="videoplayer" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"  width="~W~" height="~H~"',
					'		codebase="http://www.apple.com/qtactivex/qtplugin.cab">',
					'   <param name="standby" value="Media is loading..." />',
					'		<param name="src" value="~VIDEONAME~">',
					'		<param name="autoplay" value="true">',
					'   <param name="autoStart" value="1">',
 					'		<param name="controller" value="true">',
					'		<param name="showcontrols" value="true">',
					'		<embed type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" src="~VIDEONAME~" width="~W~" height="~H~" controller="true" autoplay="true" showcontrols="true">',
					'</object>'
				);
				
			// WMV	- Windows Media File
			} else if (ext == "wmv") {
				objectHtmlArray = new Array(
			    '<object id="videoplayer" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="~W~" height="~H~"',
					'		codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"',
					'		standby="Loading Microsoft Windows Media Player components..."',
					'		type="application/x-oleobject">',
					'		<param name="src" value="~VIDEONAME~">',
					'		<param name="autostart" value="true">',
					'		<param name="controller" value="true">',
					'		<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="~VIDEONAME~"	HEIGHT="~H~" WIDTH="~W~" controller="true" autostart="true"	> </embed>',
					'</object>'
				);
			} else {
				(alert("Unknown media type for " + videoName));
				return;
			}
			var scriptArray = new Array(
					 '<script language="JavaScript">',
					 '<!--',
					 '   if ( navigator.appName == "Netscape" ) {',
					 '       navigator.plugins.refresh();',
					 '       document.write("\x3C" + "applet MAYSCRIPT Code=NPDS.npDSEvtObsProxy.class" )',
					 '       document.writeln(" width=5 height=5 name=appObs\x3E \x3C/applet\x3E")',
					 '    }',
					 '//-->',
					'</script>'
			);
			
			// Generate the html for the videoHolder object
			var innerHtml = "";
			var str = "";
			
		 	for (var i = 0; objectHtmlArray && i < objectHtmlArray.length; i++) {
		 		var str = objectHtmlArray[i];
		 		str = str.replace(/~VIDEONAME~/g, videoName);
				str = str.replace(/~W~/g, w);
				str = str.replace(/~H~/g, h);
				innerHtml = innerHtml + str;
	 		}
	 		// Add the script for Netscape plugin refresh
	 		for (var i = 0; i < scriptArray.length; i++) {
	 			innerHtml = innerHtml + scriptArray[i];
	 		}
	 		
	 		videoHolder.innerHTML=innerHtml;
		}
		
	/*****************************************************************************
	*	Open a popup window centered on the page
	*
	*	Arguments:
	*			URL:			(required) 	The url of the page to be opened in the popup
	*			width:		(optional)  The width of the popup window; default is 500
	*			height:		(optional)  The height of the popup window; default is 450
	*
	******************************************************************************/
	var popupWindow;
	
	function popUp(URL, width, height) {
		var w = (width ? width : 500); 		// if no width argument passed, use default 500
		var h = (height ? height : 450);	// if no height argument passed, use default 450
		var x = findCenterX(w);
		var y = findCenterY(h);
		var id = "popupWin";
		eval("popupWindow = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = " + x + ",top = " + y + "');");
		popupWindow.focus();
	}
	
	/*****************************************************************************
	*					U T I L I T Y  M E T H O D S   B E L O W
	******************************************************************************/
	
	/*****************************************************************************
	*		Build the dropdown menus - automatically called when page loads
	******************************************************************************/
	function buildMenu() {
 		var submenuHTML = "";
		submenuHTML = dhtmlmenu_build(menu, submenuHTML, menuSelectedSubnav);
		
		//alert(submenuHTML);
		document.getElementById("dropdownMenu").innerHTML = submenuHTML;
		dhtmlmenu_attachEvents(menu);
	}
	
	/**************************************************************************************
	*		Convert the dropdown menus - translate the path
	**************************************************************************************/
	function convertMenu(menu, path) {
		for (var i in menu) {
    	if (typeof menu[i] == "object")  {
      	menu[i] = convertMenu(menu[i], path);
    	} else {
    		menu[i] = menu[i].replace(/~/g, path);
    	}
		}
		return menu;
	}
	
	/*****************************************************************************
	*	Document write  the text array substituting the path for "~"
	******************************************************************************/
	function writeNavArray(arr, path, selectedItem) {
	 		// document write  the text array substituting the path above for "~" and submenu arrow for '*'
	 		
	 		var text = "";
	 		
	 		for (var i = 0; i < arr.length; i++) {
	 			var str = arr[i];

				// add class=selected for the selectedItem
	 			if (selectedItem) {
	 				var selected = '<a id="' + selectedItem + '"';
	 				if (str.indexOf(selected) >= 0) {
	 					str = str.replace(selected, '<a class="selected" id="' + selectedItem + '"'); 
	 				}
	 			}
	 			str = str.replace(/\*/, menuArrow);
	 			str = str.replace(/~/g,path);
				//document.write(str);
				text = text + str;
	 		}
	 		document.write(text);
			//alert("t=" + text);
		}
	
	/*****************************************************************************
	*	Document write the text array substituting the title and subnav items
	******************************************************************************/
	function writeSubnavArray(arr, title, subnavArray, path, selectedItem) {
	
			// get the subnav items html links string
	 		var subnavHtml = "";
	 		var pageName = ""+location.href;
	 		path = (path ? path : ""); // make sure path is not null
	 		
	 		for (var i = 0; i < subnavArray.length; i+=2) {
	 				var selected = false;
	 				if (selectedItem == subnavArray[i]) {
	 					selected = true;
	 				} else if (pageName.indexOf("/" + subnavArray[i]) != -1) {
	 					selected = true;
	 				}
	 				var prefix = (selected ? '<div class="selected">' : '<div>');
	   			subnavHtml = subnavHtml + prefix + '<a href="' + path + subnavArray[i] + '">' + subnavArray[i+1] + '</a></div>';
	 		}
	 		
	 		// document write  the text array substituting the title and subnav html links
		 	for (var i = 0; i < arr.length; i++) {
		 		var str = arr[i];
		 		str = str.replace(/~TITLE~/g, title);
		 		str = str.replace(/~SUBNAVITEMS~/, subnavHtml);
				document.write(str);
	 		}
	}
	
	/*****************************************************************************
	*	returns the url extension - used to determine video file type 
	******************************************************************************/
	function getExtensionType(data) {
     data = data.replace(/^\s|\s$/g, "");

     if (/\.\w+$/.test(data)) {
         var m = data.match(/([^\/\\]+)\.(\w+)$/);
         return (m ? m[2] : null);
     } 
     return null;
 	} 
 	
	/**************************************************************************************
	*		Returns the page name with extension from a URL
	**************************************************************************************/
	function getPageName() {
		var data = ""+location.href;
    var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
    return (m ? m[2] : "");
  }
	
	/*****************************************************************************
	*	Finds the left (x) position for an object - utility method
	******************************************************************************/
	function findPosX(obj)	{
		var left = 0;
		if (obj.offsetParent) {
			left = obj.offsetLeft
			while (obj = obj.offsetParent) {
				left += obj.offsetLeft
			}
		}
		return left;
	}
	
	/*****************************************************************************
	*	Finds the top (y) position for an object - utility method
	******************************************************************************/
	function findPosY(obj)	{
			var top = 0;
			if (obj.offsetParent) {
				top = obj.offsetTop
				while (obj = obj.offsetParent) {
					top += obj.offsetTop
				}
			}
			return top;
	}
	
	/*****************************************************************************
	*	Finds the centered left position in the browser window for a specified width
	******************************************************************************/
	function findCenterX(width) {
		var pageWidth = (navigator.appName == "Microsoft Internet Explorer" ? window.screen.availWidth : window.outerWidth);
		var left = (pageWidth - width) / 2;
		return (navigator.appName == "Microsoft Internet Explorer" ? left + window.screenLeft : left + window.screenX);
   } 	
	
	/*****************************************************************************
	*	Finds the centered top position in the browser window for a specified height
	******************************************************************************/
	function findCenterY(height) {
		var pageHeight = (navigator.appName == "Microsoft Internet Explorer" ? window.screen.availHeight : window.outerHeight);
		var top = (pageHeight - height) / 2;
		return (navigator.appName == "Microsoft Internet Explorer" ? top + window.screenTop : top + window.screenY);
   } 	
	
	/*****************************************************************************
	*	Adds an event to an object eg: addEvent(window, 'load', someFunction);
	******************************************************************************/
	function addEvent(obj, evType, fn){ 
		 if (obj.addEventListener){ 
		   obj.addEventListener(evType, fn, false); 
		   return true; 
		 } else if (obj.attachEvent){ 
		   var r = obj.attachEvent("on"+evType, fn); 
		   return r; 
		 } else { 
		   return false; 
		 } 
	}

/*********************************************************************************
*		DHTML METHODS ARE BELOW - REMOVE and PUT IN SEPARATE JS FILE AFTER TESTING
**********************************************************************************/
// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/menu.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.


function at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ***** DropDown Control ******************************************************

var at_timeout = 50;

// ***** Show Aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  //p.className        = "active";

  if (c.offsetWidth <= 0)
  {
    c.style.position   = "absolute";
    c.style.visibility = "visible";
    c.style.display    = "block";
   }

  var direction = undefined;
  if (p.parentNode && p.parentNode["at_position"] == "x")
    direction = p.parentNode["at_direction"];

  var top   = (c["at_position"] == "y") ?  p.offsetHeight : 0;
  var left1 = (c["at_position"] == "x") ?  p.offsetWidth  : 0;
  var left2 = (c["at_position"] == "x") ? -c.offsetWidth  : 0;
  var left3 = (c["at_position"] == "x") ?  p.offsetWidth  : 0;

  for (; p; p = p.offsetParent)
  {
    if (p.style.position != 'absolute')
    {
      left1 += p.offsetLeft;
      left2 += p.offsetLeft;
      top   += p.offsetTop;
    }
    left3 += p.offsetLeft;
  }

  if (direction)
  {
    left = (direction == 'right') ? left1 : left2;
    c['at_direction'] = direction;
  }
  else
  {
    left = (left3+c.offsetWidth < document.body.offsetWidth) ? left1 : left2;
    c['at_direction'] = (left3+c.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }

  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display    = "block";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
}

// ***** Hide Aux *****

function at_hide_aux(parent, child)
{
  //document.getElementById(parent).className        = "parent";
  document.getElementById(child ).style.visibility = "hidden";
  document.getElementById(child ).style.display    = "block";
}

// ***** Show *****

function at_show(e)
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);

  clearTimeout(c["at_timeout"]);
}

// ***** Hide *****

function at_hide()
{
  var c = document.getElementById(this["at_child"]);

  c["at_timeout"] = setTimeout("at_hide_aux('"+this["at_parent"]+"', '"+this["at_child" ]+"')", at_timeout);
}

// ***** Attach *****

function at_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child );

  p["at_child"]    = c.id;
  c["at_child"]    = c.id;
  p["at_parent"]   = p.id;
  c["at_parent"]   = p.id;
  c["at_position"] = position;

  p.onmouseover = at_show;
  p.onmouseout  = at_hide;
  c.onmouseover = at_show;
  c.onmouseout  = at_hide;
}

// ***** DropDown Menu *********************************************************

// ***** Build Aux *****

function dhtmlmenu_build_aux(parent, child, position, str, selectedItem)  {
  //document.getElementById(parent).className = "parent";
  str = str + '<div class="vert_menu"' + ' id="'+parent+'_child">';
 
  var n = 0;
  var isSelected = (document.getElementById(parent).className == 'selected');
  
  for (var i in child)  {
    if (i == '-')    {
      document.getElementById(parent).href = child[i];
      continue;
    }

    if (typeof child[i] == "object")  {
      str = str + '<a id="'+parent+'_'+n+'">'+i+'</a>';
      str = dhtmlmenu_build_aux(parent+'_'+n, child[i], "x", str);
    }
    else { 
    	var href = child[i];
   		var selected= (isSelected && (href.indexOf("/" + selectedItem) >= 0) ? ' class="selected" ' : '');
     	str = str + '<a style="z-index:9;" id="'+parent+'_'+n+'" href="'+href+'" ' + selected + '>'+i+'</a>';
    }
    n++;
  }
	str = str + '</div>';
  return str;
}

/****** Attach Events Aux *******/
function dhtmlmenu_attachEvents_aux(parent, child, position)  {
	var n = 0;
  for (var i in child)  {
    if (i == '-')    {
      continue;
    }

    if (typeof child[i] == "object")  {
      dhtmlmenu_attachEvents_aux(parent+'_'+n, child[i], "x");
    }
    n++;
  }
 	at_attach(parent, parent+"_child", position);
}

/****** Attach Events  *******/
function dhtmlmenu_attachEvents(menu) {
  for (var i in menu) {
  	dhtmlmenu_attachEvents_aux(i, menu[i], "y");
  }
}

// ***** Build *****

function dhtmlmenu_build(menu, str, selectedItem)
{
	//alert("menu=" + menu);
  for (var i in menu) {
  	str = dhtmlmenu_build_aux(i, menu[i], "y", str, selectedItem);
  }
  return str;
}


/***used in Careers screen for JobPostings****/
function showDetails(obj) {
 // var parent = obj.parentNode;
  var el = obj.nextSibling;
  if (el.tagName == 'DIV') {
    var target = el;
    target.className = 'jobView';
  }
  else {
    var target = el.nextSibling;
    target.className = 'jobView';
  }
  obj.className = 'tabOn';
}

function hideDetails(obj) {
  var parent = obj.parentNode;
  var target = parent.parentNode;
  var tarLink = target.previousSibling;
  if(tarLink.tagName == 'A') {
     tarLink.className = 'tabOff';
  }
  else {
    tarLink = tarLink.previousSibling;
    tarLink.className = 'tabOff';
  }
  target.className = 'jobHide';
}



/***used in New At Prepac section for NEW Product Introductions changeable subnavigation****/
function loadProd(src) {
  var prodIMG = document.getElementById('prodIMG');
  prodIMG.src = src;
}
    
function markItem(obj) {
  var spanList = document.getElementsByTagName('SPAN');
  var n=0;
  if(spanList.length > 0) {
    for (n = 0; n < spanList.length; n++) {
      if (spanList.item(n).className == 'arrR') {
        var arr = spanList.item(n);
        arr.className = 'arr';
      }
    }
  }
  var sibling = obj.nextSibling;
  sibling.className = 'arrR';
}
