/*** 
 * Shop@ JavaScript Menu System
 *
 * COPYRIGHT 2000 AMERICA ONLINE, INC.
 * Version: 1.4.0 -- generic to service
 * History:
 * [2000/06/14] creation by EK 
 * [2000/07/14] added hook for support for 2.x and 3.x browsers
 * [2000/08/03] added more constants, support for submenu colors,
 * 	and drop down menus (KJB)
 * [2000/08/07] changed implementation to support Netscape (EK)
 *              - Wrapped Label
 * [2000/08/10] added Unsupported function, Mac detection (KJB)
 */

/** CONSTANTS */
COLOR_MENU_ITEM    = "Black"; 
COLOR_MENU_ITEM_SELECTED = "Navy";
COLOR_SUBMENU_ITEM = "Navy";
COLOR_SUBMENU_ITEM_SELECTED	= "Blue";
WIDTH_MAINMENU = 150;
WIDTH_SUBMENU = 150;
TIMER_MOUSE_OUT_DELAY = 400;
TYPE = 1;
TYPE_DROPDOWN = 0;
TYPE_FLYOUT = 1;
TOP_FONT_SPECS = "<FONT FACE='Verdana, sans-serif' COLOR='White'>"
SUB_FONT_SPECS = "<FONT FACE='Verdana, sans-serif' COLOR='White'>";
BULLET_CODE = "&nbsp;&#183;&nbsp;"
EXPAND_CODE = "<img src='dane/pcmedia_podmenu.gif' border=0 align='bottom' width='8' height='10'>"
HTML_OLD_BROWSER = "<b>Please enable JavaScript or upgrade your web browser. This menu requires JavaScript 1.2.</b>";

/** GLOBAL VARIABLES */
gCurrentResource = null;
gMouseOutTimer   = null;
gMenuBarName	  = "TheMenuBar";

/** Mapping */
var version = window.navigator.appVersion;
var isMac = (version.indexOf("Mac") != -1) || (version.indexOf("PPC") != -1);
if( version != null ) {
    version = parseInt( version );
} else {
    version = 0;
}
if( version >= 3) { /** && ( document.all || document.layers ) ) { */
	/**if (navigator.appName == "Netscape") {
		DisplayMenu		 = NSCP_DisplayMenu;
		SetLeft			 = NSCP_SetLeft;
		SetTop			 = NSCP_SetTop;
		GetLeft			 = NSCP_GetLeft;
		GetTop			 = NSCP_GetTop;
		GetHeight			 = NSCP_GetHeight;
		GetWidth		   	 = NSCP_GetWidth;
		SetContent		 = NSCP_SetContent;
		SetVisibility		 = NSCP_SetVisibility;
		SetBackgroundColor	 = NSCP_SetBackgroundColor;
		ItemAsHTML		 = NSCP_ItemAsHTML;
	} else { */
		DisplayMenu		 = IE_DisplayMenu;
		SetLeft			 = IE_SetLeft;
		SetTop			 = IE_SetTop;
		GetLeft			 = IE_GetLeft;
		GetTop			 = IE_GetTop;
		GetHeight			 = IE_GetHeight;
		GetWidth			 = IE_GetWidth;
		SetContent		 = IE_SetContent;
		SetVisibility		 = IE_SetVisibility;
		SetBackgroundColor	 = IE_SetBackgroundColor;
		ItemAsHTML		 = IE_ItemAsHTML;
	//}
} else {
		DisplayMenu = Unsupported;
}


/** GLOBAL HELPER FUNCTIONS */

function IE_DisplayMenu(){

	if (isMac) {
		Unsupported();
	} else {

		document.write( "<div id='TheFloatingMenu' style='width:"+WIDTH_SUBMENU+"' class='FloatingMenu' onmouseover='OnHandleFMMouseOver()' onmouseout='OnHandleFMMouseOut()' onselectstart='return false;'></div>" );
	
		SetBackgroundColor( "TheFloatingMenu", COLOR_MENU_ITEM );

		var tagName = "div";
		if( TYPE == TYPE_DROPDOWN ){
			tagName = "span";
		}
		
		for( var rid in __oMenuModel ){
			var res  = __oMenuModel[rid];
			var html = "";
			if( res.isContainer() ){
				html= "<" + tagName + " id='"+rid+"' style='width:" + WIDTH_MAINMENU + "' class='MenuItem' onselectstart='return false;' onmouseout='OnHandleMouseOut(\""+rid+"\")' onmouseover='OnHandleMouseOver(\""+rid+"\")'>" + TOP_FONT_SPECS 
					+ BULLET_CODE
					+		__oMenuModel[rid].asHTML() 
   				    + EXPAND_CODE
					+ "</font></" + tagName + ">";
			} else {
				html= "<" + tagName + " id='"+rid+"' style='width:" + WIDTH_MAINMENU + "' class='MenuItem' onselectstart='return false;' onmouseout='OnHandleMouseOut(\""+rid+"\")' onmouseover='OnHandleMouseOver(\""+rid+"\")' onclick='OnHandleClick(\""+rid+"\")'>" + TOP_FONT_SPECS  
					+ BULLET_CODE
					+		__oMenuModel[rid].asHTML() 
					+ "</font></" + tagName + ">";		
			}
			document.write( html );
	
			SetBackgroundColor( rid, COLOR_MENU_ITEM );
		}
	}
}

function NSCP_DisplayMenu(){

	document.write( "<layer id='TheFloatingMenu' width='" + WIDTH_SUBMENU + "' onmouseover='OnHandleFMMouseOver()' onmouseout='OnHandleFMMouseOut()'></layer>" );

	SetBackgroundColor( "TheFloatingMenu", COLOR_MENU_ITEM );

	var totItems = 0;
	for( var rid in __oMenuModel ){
		totItems ++;
	}
	
	var width = WIDTH_MAINMENU;
	if( TYPE == TYPE_DROPDOWN ){
		width = totItems * WIDTH_MAINMENU
	}

	var counter = 0;
		
   document.write( "<table cellpadding=0 cellspacing=0 border=0 width="+width+"><tr><td>" );	
   document.write( "<ilayer id='" + gMenuBarName + "'>" );	
	for( var rid in __oMenuModel ){
		var res  = __oMenuModel[rid];
		var html = "";

		if( res.isContainer() ){
			html= "<layer id='" + rid + "' class='NSMenuItem' width='" + WIDTH_MAINMENU + "' onmouseout='OnHandleMouseOut(\""   + rid + "\")' onmouseover='OnHandleMouseOver(\"" + rid + "\")'>" + TOP_FONT_SPECS 
			+  BULLET_CODE
			+ "<A HREF='#' class='NSMenuItem' onclick='return false'>" + TOP_FONT_SPECS
			+	__oMenuModel[rid].asHTML() 
 			+ "</font></A>"
  			+ EXPAND_CODE
			+ "</font></layer>"
			+ "<ilayer id='" + rid + "Shadow' class='NSMenuItem' visibility = 'hidden'>" + TOP_FONT_SPECS 
			+  BULLET_CODE
			+ "<A HREF='#' class='NSMenuItem' onclick='return false'>" + TOP_FONT_SPECS
			+	__oMenuModel[rid].asHTML() 
 			+ "</font></a>"
  			+ EXPAND_CODE
			+ "</font></ilayer>"

		} else {
			html= "<layer id='" + rid + "' class='NSMenuItem' width='" + WIDTH_MAINMENU + "' onmouseout='OnHandleMouseOut(\"" + rid + "\")' onmouseover='OnHandleMouseOver(\"" + rid + "\")'>" + TOP_FONT_SPECS
			+ BULLET_CODE
			+ "<A HREF='#' class='NSMenuItem' onmouseout='OnHandleMouseOut(\"" + rid + "\")' onmouseover='OnHandleMouseOver(\"" + rid + "\")' onclick='OnHandleClick(\"" + rid + "\")'>" 
 			+ TOP_FONT_SPECS
			+   __oMenuModel[rid].asHTML() 
			+ "</font></a>"
			+ "</font></layer>"
			+ "<ilayer id='" + rid + "Shadow' class='NSMenuItem' visibility = 'hidden'>" + TOP_FONT_SPECS
			+ BULLET_CODE
			+ "<A HREF='#' class='NSMenuItem' onmouseout	='OnHandleMouseOut(\"" + rid + "\")' onmouseover='OnHandleMouseOver(\"" + rid + "\")' onclick    ='OnHandleClick(\"" + rid + "\")'>" 
 			+ TOP_FONT_SPECS
			+   __oMenuModel[rid].asHTML()     
			+ "</font></a>"
			+ "</font></ilayer>"
		}
		
		if( TYPE == TYPE_FLYOUT ){
			html = html + "<br>";
		}
		counter ++;
		document.write( html );
	}
	document.write( "</ilayer></td></tr></table>" );
	var previousItem = null;
	for( var rid in __oMenuModel ){
		if( previousItem != null ){
			var dx = document.layers[gMenuBarName].document.layers[ previousItem ].clip.width;
			var dy = document.layers[gMenuBarName].document.layers[ previousItem ].clip.height;

			if( TYPE == TYPE_FLYOUT ){
				dx = 0;
			} else {
				dy = 0;
			}
 			document.layers[gMenuBarName].document.layers[ rid ].top  = 
							document.layers[gMenuBarName].document.layers[ previousItem ].top  + dy ;
 			document.layers[gMenuBarName].document.layers[ rid ].left = 
							document.layers[gMenuBarName].document.layers[ previousItem ].left + dx ;
		}	

		SetBackgroundColor( rid, COLOR_MENU_ITEM );
		SetVisibility( rid, "visible" );
		previousItem = rid;
	}
}

function OnHandleMouseOver( resID ){
	ClearMouseOutTimer();
	HideSubmenu();
	ShowSubmenu( __oMenuModel[resID] );
}

function OnHandleMouseOut( resID ){
	InitMouseOutTimer();
}

function OnHandleClick( resID ){
	ClearMouseOutTimer();
	HideSubmenu();
	var res = __oMenuModel[resID];
	OpenItem( res.getURL() );
}

function OnHandleFMMouseOver(){
	ClearMouseOutTimer();
}

function OnHandleFMMouseOut(){
	InitMouseOutTimer();
}

function InitMouseOutTimer(){
	ClearMouseOutTimer();
	gMouseOutTimer = setTimeout("HideSubmenu();", TIMER_MOUSE_OUT_DELAY)
}

function ClearMouseOutTimer(){
	clearTimeout(gMouseOutTimer);
}

function OpenFlyout( x0, y0, htmlContent ){
	SetLeft( "TheFloatingMenu", x0 );
	SetTop( "TheFloatingMenu", y0 );
	SetContent( "TheFloatingMenu", htmlContent );
	SetVisibility( "TheFloatingMenu", "visible" );
}

function CloseFlyout(){
	SetVisibility( "TheFloatingMenu", "hidden" );
	SetContent( "TheFloatingMenu", "" );
}

function IE_SetLeft( id, x0 ){
	var view = eval( id );
	if( view != null ){
		view.style.pixelLeft = x0; 
	}		
}

function NSCP_SetLeft( id, x0 ){
	var view = document.layers[ id ];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		view.left = x0; 
	}		
}

function IE_SetTop( id, y0 ){
	var view = eval( id );
	if( view != null ){
		view.style.pixelTop = y0; 
	}			
}

function NSCP_SetTop( id, y0 ){
	var view = document.layers[ id ];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		view.top = y0; 
	}			
}

function IE_GetLeft( id ){
	var view = eval( id );
	if( view != null ){
		return view.offsetLeft; 
	} else {
		return 0;
	}	
}

function NSCP_GetLeft( id ){
	var view = document.layers[ id ];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		return view.pageX; 
	} else {
		return 0;
	}	
}

function IE_GetTop( id ){
	var view = eval( id );
	if( view != null ){
		return view.offsetTop; 
	} else {
		return 0;
	}	
}

function NSCP_GetTop( id){
	var view = document.layers[ id ];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		return view.pageY; 
	}			
}

function IE_GetHeight( id ){
	var view = eval( id );
	if( view != null ){
		return view.offsetHeight; 
	} else {
		return 0;
	}	
}

function NSCP_GetHeight( id ){
	var view = document.layers[ id ];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		return view.clip.height; 
	} else {
      return 0;
   }	
}

function IE_GetWidth( id ){
	return WIDTH_MAINMENU;
}

function NSCP_GetWidth( id ){
	return WIDTH_MAINMENU;
}

function IE_SetContent( id, htmlContent ){
	var view = eval( id );
	if( view != null ){
		view.innerHTML = htmlContent; 
	}		
}

function NSCP_SetContent( id, htmlContent ){
	var view = document.layers[id];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		view.document.open();
		view.document.write( htmlContent );
		view.document.close(); 
	}		
}

function IE_SetVisibility( id, str ){
	var view = eval( id );
	if( view != null ){
		view.style.visibility = str; 
	}	
}

function NSCP_SetVisibility( id, str ){
	var view = document.layers[id];
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[id];
	}
	if( view != null ){
		if( str == "hidden" ){
			view.visibility = "hidden" ;
		} else {
			view.visibility = "show" ;
		}	 
	}	
}

function IE_SetBackgroundColor( rid, color ){
	var view = eval( rid );
	if( view != null ){
		view.style.backgroundColor = color; 
	}
}

function NSCP_SetBackgroundColor( rid, color ){
	var view = document.layers[rid];
	if( view == null ){
		view = document.layers['TheFloatingMenu'].document.layers[rid]
	}
	if( view == null ){
		view = document.layers[gMenuBarName].document.layers[rid]   
	}
	if( view != null ){
		view.bgColor = color; 
	}
}

function OnHandleFMIMouseOver( id ){
	SetBackgroundColor( id, COLOR_SUBMENU_ITEM_SELECTED );
}

function OnHandleFMIMouseOut( id ){
	SetBackgroundColor( id, COLOR_SUBMENU_ITEM );
}


function ShowSubmenu( res ){
   if( gCurrentResource == res ){
		return;
	}

	var id = res.id;
	if( id == null ){
		alert( "Resource does not have an id" );
		return;
	}

	SetBackgroundColor( id, COLOR_MENU_ITEM_SELECTED );

	if(  res.isContainer() ){	
		var html = "";
		var counter = 0;
		for( var label in res.map ){
			html += ItemAsHTML( counter, label, res.map[label] );
			counter ++;
		}

		if (TYPE == TYPE_DROPDOWN ) {
			var x0 = GetLeft( id );
			var y0 = GetTop( id ) + GetHeight( id );
		} else {
			var x0 = GetLeft( id ) + GetWidth( id );
			var y0 = GetTop( id );
		}

		OpenFlyout( x0, y0, html );
	}

	gCurrentResource = res;
}

function IE_ItemAsHTML( id, label, url ){
	var html = "<div id='FMI" + id + "' width='100%' STYLE='background:" + COLOR_SUBMENU_ITEM + "' class='MenuItem' onselectstart='return false;' onmouseout='OnHandleFMIMouseOut( this.id )' onmouseover='OnHandleFMIMouseOver( this.id )' onclick='OpenItem(\""+ url +"\")'>" + SUB_FONT_SPECS 
			 +  BULLET_CODE
			 +  label			  
			 +  "</font></div>";
	return html;		
}

function NSCP_ItemAsHTML( id, label, url ){
	var html = "<ilayer id='FMI" + id + "' top=0 width='" + WIDTH_SUBMENU + "' bgcolor='" + COLOR_SUBMENU_ITEM + "'>" +  SUB_FONT_SPECS
			+ BULLET_CODE
			+ "<a href='#' class='NSMenuItem' onmouseout='OnHandleFMIMouseOut ( \"FMI" + id + "\" )' onmouseover='OnHandleFMIMouseOver( \"FMI" + id + "\" )' onclick     = 'OpenItem(\"" + url + "\")'>" +  SUB_FONT_SPECS
			+ label
			+ "</font></a>"
			+ "</font></ilayer><BR>"
	return html;		
}

function HideSubmenu(){
	if( gCurrentResource == null ){
		return;
	}
	CloseFlyout();
	SetBackgroundColor( gCurrentResource.id, COLOR_MENU_ITEM );
	gCurrentResource = null;
}

function OpenItem( url ){
	document.location = url;
}

function Unsupported(){
	document.write(HTML_OLD_BROWSER);
}

/* + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + 
 *			O B J E C T        M O D E L
 * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * */
function __I( id, label, itemURL ){
	this.id			= id;
	this.label	 	= label;
	this.targetURL  = itemURL;

	this.getURL	= function(){
		return this.targetURL;	
	}

	this.asHTML	= function(){
		return label;
	}
	
	this.label = function(){
		return label;
	}

	this.isItem = function(){
		return true;
	}

	this.isContainer = function(){
		return false;
	}
}

function __C( id, label, map ){
	this.label 	= label;
	this.map 	= map;
	this.id		= id;

	this.asHTML	= function(){
		return label;
	}

	this.label = function(){
		return this.label;
	}

	this.isItem = function(){
		return false;
	}

	this.isContainer = function(){
		return true;
	}
}

/** INITIALIZATION */
__oMenuModel = new Object();
if( __menuModel ){

	var counter = 1;
	for( var label in __menuModel ){

		var id = "resource" + counter;
		counter ++;

		var obj = new Object();
		var res = __menuModel[label];
		if( res.length ){
			__oMenuModel[id] = new __I( id, label, res );	
		} else {
			__oMenuModel[id] = new __C( id, label, res );				
		}
	}
}
