// Use Freely as long as following disclaimer is intact ::
//---------------------------------------------------------------
// Cross Browser Multi-Orientation Menu v1.5 17th August 2004
// This script written by Rik Comery. www.ricom.co.uk
// For support, visit the "Resources" section at www.ricom.co.uk           
// All rights reserved.   
// Featured in the SimplytheBest DHTML Scripts Library at http://simplythebest.net/scripts/
// code modified by Matthew Gonyea


//  MENU ITEMS //
var Menu1 = new Array ()
var subMenu1 = new Array ()
Menu1[0] = new Array("x", "x","x", "x")
	subMenu1[0] = new Array()	
Menu1[1] = new Array("x", "x","x", "x")
	subMenu1[1] = new Array()
Menu1[2] = new Array("x", "x","x", "x")
	subMenu1[2] = new Array()
Menu1[3] = new Array("x", "x","x", "x")
	subMenu1[3] = new Array()
	subMenu1[3][0] = new Array ("Product Line", URLLocation+"products.aspx","_top")
	subMenu1[3][1] = new Array ("How to Order", URLLocation+"order.aspx","_top")	
	subMenu1[3][2] = new Array ("Transportation", URLLocation+"transportation.aspx","_top")	
Menu1[4] = new Array("x", "x","x", "x")
	subMenu1[4] = new Array()
	subMenu1[4][0] = new Array ("About ICI", URLLocation+"about.aspx","_top")
	subMenu1[4][1] = new Array ("ICI News", URLLocation+"news.aspx","_top")
	subMenu1[4][2] = new Array ("Career Opportunities", URLLocation+"careers.aspx","_top")
	subMenu1[4][3] = new Array ("Company Directory", URLLocation+"directory.aspx","_top")
	subMenu1[4][4] = new Array ("Locations", URLLocation+"locations.aspx","_top")
Menu1[5] = new Array("x", "x","x", "x")
	subMenu1[5] = new Array()



/// FORMAT MENU  ///
menuStyle = "flat"                                  // Menu Style (flat, 3d)
cellPadding = "3"                                   // Cell Padding
cellBorder = 1                                      // Border width (for no border, enter 0)  THIS VALUE APPLIES TO ALL MENUS
verticalOffset = "0"                                // Vertical offset of Sub Menu. 
horizontalOffset = "0"                              // Horizontal offset of Sub Menu. 
subMenuDelay = 2                                    // Time sub menu stays visible for (in seconds). THIS VALUE APPLIES TO ALL MENUS
subIndicate = 1                                     // Show if a sub menu is present (use 0 for "no")  THIS VALUE APPLIES TO ALL MENUS
//indicator = "<img src='quickmenu/downloads.gif' border='0'>" // Symbol to show if a sub menu is present (subIndicate must be to set to 1)
indicator = ""
													// Use standard HTML <img> tag. You can use a character instead of an image. 
													// e.g.      indicator = ">"
// Main Menu Items
menuWidth = "0"                  // Width of menu item.  Use 0 for default
borderColor = "Black"            // Border Colour (flat mode only)
borderHighlight = "#97BBD3"      // Border Highlight Colour (3d mode only)
borderShadow = "#31556D"         // Border Shadow Colour (3d mode only)
menuBackground = "#2b83c4"       // Cell Background Colour
menuHoverBackground = "beige"    // Cell Background Colour on mouse rollover
fontFace = "arial"               // Font Face
fontColour = "#FFFFFF"           // Font Colour
fontHoverColour = "#2b83c4"      // Font Colour on mouse rollover
fontSize = "8pt"                 // Font Size
fontDecoration = "none"          // Style of the link text (none, underline, overline, line-through)
fontWeight = "normal"            // Font Weight (normal, bold)

// Sub Menu Items
smenuWidth = "0"                 // Width of sub menu item.  Use 0 for default
sborderColor = "Black"           // Border Colour (flat mode only)
sborderHighlight = "#E9E9E2"     // Border Highlight Colour (3d mode only)
sborderShadow = "#83837C"        // Border Shadow Colour (3d mode only)
smenuBackground = "#CCCCCC"      // Cell Background Colour
smenuHoverBackground = "#CCCCCC" // Cell Background Colour on mouse rolloverr
sfontFace = "arial"              // Font Face
sfontColour = "Black"            // Font Colour
sfontHoverColour = "#990000"     // Font Colour on mouse rollover
sfontSize = "8pt"                // Font Size
sfontDecoration = "none"         // Style of the link text (none, underline, overline, line-through)
sfontWeight = "bold"           // Font Weight (normal, bold)

quantity = 1
/// END FORMAT MENU  ////

/// DO NOT EDIT BELOW THIS LINE  ///
// Browser Sniffer
var isIE = (document.getElementById && document.all)?true:false;
var isNS4 = (document.layers)?true:false;
var isNS6 = (document.getElementById && !document.all)?true:false;
var timer;
var obj = (isIE)?"document.all":"document.getElementById"
// Menu Styles
function createStyles(quant){
	styleBorder=(menuStyle.split(",")[quant-1].toLowerCase() == "flat")?cellBorder:0 
	document.writeln ('<style>');
	document.writeln ('.rcMenuStatic'+quant+' {font-family:'+fontFace.split(",")[quant-1]+';font-size:'+fontSize.split(",")[quant-1]+';color:'+fontColour.split(",")[quant-1]+';font-weight:'+fontWeight.split(",")[quant-1]+';background-color:'+menuBackground.split(",")[quant-1]+'; cursor:hand; text-decoration:'+fontDecoration.split(",")[quant-1]+'}');
	document.writeln ('.rcMenuHover'+quant+'  {font-family:'+fontFace.split(",")[quant-1]+';font-size:'+fontSize.split(",")[quant-1]+';color:'+fontHoverColour.split(",")[quant-1]+';font-weight:'+fontWeight.split(",")[quant-1]+';background-color:'+menuHoverBackground.split(",")[quant-1]+'; cursor:hand; text-decoration:'+fontDecoration.split(",")[quant-1]+'}');
	document.writeln ('.rcSubMenuStatic'+quant+' {font-family:'+sfontFace.split(",")[quant-1]+';font-size:'+sfontSize.split(",")[quant-1]+';color:'+sfontColour.split(",")[quant-1]+';font-weight:'+sfontWeight.split(",")[quant-1]+';text-decoration:'+sfontDecoration.split(",")[quant-1]+';background-color:'+smenuBackground.split(",")[quant-1]+'; cursor:hand}');
	document.writeln ('.rcSubMenuHover'+quant+'  {font-family:'+sfontFace.split(",")[quant-1]+';font-size:'+sfontSize.split(",")[quant-1]+';color:'+sfontHoverColour.split(",")[quant-1]+';font-weight:'+sfontWeight.split(",")[quant-1]+';text-decoration:'+sfontDecoration.split(",")[quant-1]+';background-color:'+smenuHoverBackground.split(",")[quant-1]+'; cursor:hand}');
	document.writeln ('</style>');
}

// Build and show the main menu items
function showMenus(quant)
{
	createStyles(quant);							
	// Build the sub menu items
	for (x=0; x<eval("Menu"+quant).length; x++){ 
		if (eval("subMenu"+quant)[x].length > 0){     
			document.writeln ('<div id="'+quant+'MENU'+x+'" style="visibility:hidden; position:absolute; z-index:2" >');
			document.writeln ('<table width="'+smenuWidth.split(",")[quant-1]+'" border="0" cellpadding="'+cellPadding.split(",")[quant-1]+'" cellspacing="'+styleBorder+'" bgColor="'+sborderColor.split(",")[quant-1]+'">');
			for (y=0; y<eval("subMenu"+quant)[x].length; y++)
			{
				document.writeln ('<tr>');
				if (eval("subMenu"+quant)[x][y][1].indexOf("#") != -1){
					document.writeln ('<td bgColor="'+eval("subMenu"+quant)[x][y][2]+'" id="'+quant+'subMenu'+x+y+'" onMouseOver="hoverMenu(); highlightMenu(\'sub\','+x+','+y+',\'\','+quant+')" nowrap')
					document.writeln ('><p style="font-family:'+sfontFace.split(",")[quant-1]+'; font-size:'+sfontSize.split(",")[quant-1]+'; color:'+eval("subMenu"+quant)[x][y][1]+'"id="'+quant+'subLink'+x+y+'">'+eval("subMenu"+quant)[x][y][0]+'</p></td></tr>');
				}
				else{
					document.writeln ('<td width=150 id="'+quant+'subMenu'+x+y+'" class="rcSubMenuStatic'+quant+'" onMouseOver="hoverMenu(); highlightMenu(\'sub\','+x+','+y+',\'\','+quant+')" onMouseOut="clearMenu('+quant+','+x+');" onclick="tdMouseClick(\''+quant+'subLink'+x+y+'\')" nowrap')
					document.writeln ('><a id="'+quant+'subLink'+x+y+'" href="'+eval("subMenu"+quant)[x][y][1]+'" target="'+eval("subMenu"+quant)[x][y][2]+'" class="rcSubMenuStatic'+quant+'">'+eval("subMenu"+quant)[x][y][0]+'</a></td></tr>');
				}
			}
			document.writeln ('</table></div>');
			}
		}
} 

// Change colour or menu and submenu items when the mouse hovers over.  
function highlightMenu(element,mainMenu,dropMenu,state,quant)
{	
	hoverMenu();
		
	var oldstate
	oldstate=state
	state=(state == "hover")?"rcMenuHover"+quant:"rcMenuStatic"+quant
	
	
	
	if (element == "sub")
	{	
		//turn off roll pick
		swap('roll_pic',"header_off.src");			
		for (x=0; x < eval("subMenu"+quant)[mainMenu].length; x++)
		{
			if (eval("subMenu"+quant)[mainMenu][x][1].indexOf("#") == -1){
				eval(obj+'("'+quant+'subMenu'+mainMenu+x+'").className = "rcSubMenuStatic'+quant+'"')
				eval(obj+'("'+quant+'subLink'+mainMenu+x+'").className = "rcSubMenuStatic'+quant+'"')
			}
		}
		if (eval("subMenu"+quant)[mainMenu][dropMenu][1].indexOf("#") == -1)  {
			eval(obj+'("'+quant+'subMenu'+mainMenu+dropMenu+'").className="rcSubMenuHover'+quant+'"')
			eval(obj+'("'+quant+'subLink'+mainMenu+dropMenu+'").className="rcSubMenuHover'+quant+'"')
			activate('img'+quant+mainMenu)
		}
	}
	else
	{
		//eval(obj+'("'+quant+'cell'+mainMenu+'").className = "'+state+'"')
		//eval(obj+'("'+quant+'mainLink'+mainMenu+'").className = "'+state+'"')
		//if (subIndicate == 1&&eval("subMenu"+quant)[mainMenu].length>=1){	
		//	eval(obj+'("'+quant+'cell'+mainMenu+'a").className = "'+state+'"')
		//	eval(obj+'("'+quant+'mainLink'+mainMenu+'a").className = "'+state+'"')
		//}
		if(state == "rcMenuStatic"+quant){			
			deactivate('img'+quant+mainMenu);
		}		
	}	
}
// Find positioning for sub menus
function getOffset(obj, dim) {
	if(dim=="left") {     
		oLeft = obj.offsetLeft;    
		while(obj.offsetParent!=null) {    
			oParent = obj.offsetParent     
			oLeft += oParent.offsetLeft 
			obj = oParent 	
		}
		return oLeft
	}
	else if(dim=="top"){
		oTop = obj.offsetTop;
		while(obj.offsetParent!=null) 
		{
			oParent = obj.offsetParent
			oTop += oParent.offsetTop
			obj = oParent 	
		}
		return oTop
	}
	else if(dim=="width"){
		oWidth = obj.offsetWidth
		return oWidth
	}  
	else if(dim=="height"){
		oHeight = obj.offsetHeight
		return oHeight
	}    
	else{
		alert("Error: invalid offset dimension '" + dim + "' in getOffset()")
		return false;
	}
}
// Show sub menus
function popDown(quant, param, id, orientation){
	var cellBorderOffset = (isNS6)?cellBorder:eval(cellBorder*2)
	var browserAdjustment = (isNS6)?cellBorder:0
	var menu;
	var button;
		
	
				
	if (id){    
		
	
		//mouseover img
		activate('img'+quant+param)
	
		getOffset(eval(obj+'(id)'),'left');
		getOffset(eval(obj+'(id)'),'top');    
		getOffset(eval(obj+'(id)'),'width');  
		getOffset(eval(obj+'(id)'),'height');
		
		if (eval("Menu"+quant+"["+param+"][3]")=="right" && eval("subMenu"+quant+"["+param+"].length")>0) { 
			oLeft=oLeft  
			oLeft=oLeft+oWidth; 
			getOffset(eval(obj+'("'+quant+'MENU'+param+'")'),'width');
			oLeft=oLeft-oWidth ;
			alignAdjustment = cellBorder*2 + 1
		}
		else {
			alignAdjustment = 0
			oLeft=oLeft
		}  
	  
	}  
	else{
		//fired after you leave a button & its dropdown
		swap('roll_pic',"header_off.src");
	}

		
	n = 0;    
	while (n < eval("Menu"+quant).length){          
		menu = quant+"MENU"+n
		if (param == n){
			theObj = eval(obj+'(menu)');
			if (theObj)
			{
				theObj.style.visibility = "visible"
				theObj.style.left=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oLeft-cellBorder+parseInt(horizontalOffset.split(",")[quant-1])+alignAdjustment:oLeft+parseInt(horizontalOffset.split(",")[quant-1])-browserAdjustment+alignAdjustment;
				theObj.style.top=(menuStyle.split(",")[quant-1].toLowerCase()=="flat")?oTop+oHeight+cellBorder+parseInt(verticalOffset.split(",")[quant-1]):oTop+oHeight+cellBorderOffset+parseInt(verticalOffset.split(",")[quant-1]);}
				
			highlightMenu('main',n,'','hover',quant)
			if (eval("subMenu"+quant)[param].length > 0){
				for (x=0; x<eval("subMenu"+quant)[param].length; x++){
					if(eval("subMenu"+quant)[param][x][1].indexOf("#") == -1){
						eval (obj+'("'+quant+'subMenu'+param+x+'").className = "rcSubMenuStatic'+quant+'"')
						eval (obj+'("'+quant+'subLink'+param+x+'").className = "rcSubMenuStatic'+quant+'"')  
					}       
				}
			}
		}
		else {  
			for (x=1; x<quantity+1; x++){       
				menu = x+"MENU"+n   
				//alert(menu)     
				if (eval(obj+'(menu)')){
					eval(obj+'(menu).style.visibility = "hidden"')            
				}
				highlightMenu ('main',n,'','static',quant)
			}
		}
		n++
	}  
}
// Re-set timer for sub menus
function hoverMenu(){
	if(timer){
		clearTimeout(timer)
	}
}
// Set timer for sub menus
function clearMenu(quant,menu){
	setDelay = subMenuDelay*100
	delay = (eval("subMenu"+quant)[menu].length > 0)?setDelay:1			  
	timer = setTimeout("popDown("+quant+","+(eval("Menu"+quant).length + 1)+")",delay)
}
	
// when you click the box, perform the same function as if the user had clicked the hyperlink
function tdMouseClick(theElement){
	//eval(obj+'(theElement).click()')
}

function activate(imgName) {
	swap(imgName,imgName+"_on.src");
	swap('roll_pic',imgName+"_header_on.src");
}
function deactivate(imgName) {
	swap(imgName,imgName+"_off.src");		
}

//preloaded images
var img10_off = new Image();
img10_off.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_news_off.jpg";			
var img10_on = new Image();
img10_on.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_news_on.jpg";

var img11_off = new Image();
img11_off.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_weather_off.jpg";
var img11_on = new Image();
img11_on.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_weather_on.jpg";
var img12_off = new Image();
img12_off.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_markets_off.jpg";
var img12_on = new Image();
img12_on.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_markets_on.jpg";
var img13_off = new Image();
img13_off.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_products_off.jpg";			
var img13_on = new Image();
img13_on.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_products_on.jpg";
var img14_off = new Image();
img14_off.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_corporate_off.jpg";			
var img14_on = new Image();
img14_on.src = imgLocation+"http://ici-grain.com/images/e0028701/mm_corporate_on.jpg";
var img15_off = new Image();
img15_off.src = imgLocation+"http://icigrain.com/images/mm_gbids_off.jpg";			
var img15_on = new Image();
img15_on.src = imgLocation+"http://icigrain.com/images/mm_gbids_on.jpg";

var header_off = new Image();
header_off.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_home.jpg";
var img10_header_on = new Image();
img10_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_news.jpg";
var img11_header_on = new Image();
img11_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_weather.jpg";
var img12_header_on = new Image();
img12_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_markets.jpg";
var img13_header_on = new Image();
img13_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_products.jpg";
var img14_header_on = new Image();
img14_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_corporate.jpg";
var img15_header_on = new Image();
img15_header_on.src = imgLocation+"http://ici-grain.com/images/e0028701/roll_products.jpg";

var sm_home_off = new Image();
sm_home_off.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_home_off.jpg";
var sm_home_on = new Image();
sm_home_on.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_home_on.jpg";
var sm_map_off = new Image();
sm_map_off.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_map_off.jpg";
var sm_map_on = new Image();
sm_map_on.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_map_on.jpg";
var sm_contact_off = new Image();
sm_contact_off.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_contact_off.jpg";
var sm_contact_on = new Image();
sm_contact_on.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_contact_on.jpg";
var sm_help_off = new Image();
sm_help_off.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_help_off.jpg";
var sm_help_on = new Image();
sm_help_on.src = imgLocation+"http://ici-grain.com/images/e0028701/sm_help_on.jpg";

//mouseover code
function swap(imgID,newImgName){
	document.images[imgID].src = eval(newImgName);
}
