/* Vars related to main category menu */
	var currentSubMenu = "";
	var lastMenu = "";
	var currentMenu = "";
	var menuHover = false;
	var hideMenu = false;
	var currentRootCategory = "";
	var leftMenu = "";
	var rightMenu = "";
	var isLeftMenu = false;
	var isRightMenu = false;
	var rd = false;
	var menuLoaded = new Object();
/* Vars related to main category menu */

function searchFormValidate(boxid){
	var searchValue = (document.searchform.q.value=='Search');
	if (searchValue == false){
		document.searchform.action="http://search.franklinplanner.com/";
		document.searchform.submit();
	} 
			
}
		
function showSearchBubble(boxid){
	var posX = findPositionX(document.getElementById("search_box"));
	var posY = findPositionY(document.getElementById("search_box"));
	document.searchform.action="http://search.franklinplanner.com/";
        if (document.searchform.q.value.length < 1) {
		document.getElementById(boxid).style.left=posX - 130;
		document.getElementById(boxid).style.top=posY - 75;
		document.getElementById(boxid).style.display="block";
		document.searchform.q.focus();
		return false;
	} else {   
	   document.searchform.submit();
	   return true;	 
	}
}

function hideSearchBubble(boxid){
   document.getElementById(boxid).style.display="none";
}	

function toggleGreenArrow(imgName,hover) {
 // Toggle the image shown in the link
  if ( document[imgName] ) {
    if ( hover ) {
      document[imgName].src = "http://www.franklinplanner.com/images/shop_template/green_arrow.gif";
    } else {
      document[imgName].src = "http://www.franklinplanner.com/images/shop_template/gray_arrow.gif";
    }
  }
  
}
function toggleGreenOption(option,hover) {

  // Toggle the image shown in the link
  if ( document[option] ) {
    if ( hover ) {
      document[option].src = "http://www.franklinplanner.com/images/shop_template/" + option + "_on.gif";
    } else {
      document[option].src = "http://www.franklinplanner.com/images/shop_template/" + option + "_off.gif";
    }
  }
}

function toggleGreenMenu(option,hover,lr) {
  var lr_on = "";
  var lr_off = "";
  if ( lr == "menu_left" ) {
    lr_on = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_on.gif";
    lr_off = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_off.gif";
  }
  if ( lr == "menu_right" ) {
    lr_on = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_on.gif";
    lr_off = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_off.gif";
  }
  if ( document.getElementById(option) ) {
    var td = document.getElementById(option);
    if ( hover ) {
      td.className = "menu_item_on";
      if ( lr_on != "" ) {
        document[lr].src = lr_on;  
      }
    } else {
      td.className = "menu_item_off";
      if ( lr_off != "" ) {
        document[lr].src = lr_off;
      }
    }
  }
}

function subMenu(catId,store,on) {

  if ( document.getElementById('sub_'+catId) ) {
    var el = document.getElementById('sub_' + catId);
    el.style.width = "300px";
    if ( on == true ) {
      $("#sub_"+catId).load("/shopping/common/ajx_submenucategories.jsp?currentRootCategory="+catId);
      el.style.display = "block";
      el.style.height = "300px";
    } else {
      el.style.display = "none";
    }
  }
}

function whatsThis(which,state,parent)
{
	//close all other open windows
	closeWhatsThis();
	
	var whatsThisDiv = document.getElementById("sub_menu_2_whats_this_"+which);
	if (whatsThisDiv) 
	{
		if (state=="block")
		{
			var whatsThisParent = document.getElementById("sub_menu_2_"+which);
			var menuParent = document.getElementById("subcat_"+parent);
			var parentCoords = getObjCoords(whatsThisParent);
			var menuCoords = getObjCoords(menuParent);
			//var newLeft=parentCoords.x - menuCoords.x + 110;
			//var newTop = parentCoords.y - menuCoords.y + 5;
			var newLeft = parentCoords.x+110;
			var newTop = parentCoords.y+5;
			whatsThisDiv.style.top=newTop+"px";
			whatsThisDiv.style.left=newLeft+"px";
		}
		whatsThisDiv.style.display=state;
	}
}

function closeWhatsThis()
{
	var these = getElementsByClass("sub_menu_2_whats_this",null,"div");
	if (these!=null)
	{
		for (i=0; i<these.length; i++)
		{
			these[i].style.display="none";
		}
	}	
	
}

function buildMenu(url) {

   $.ajaxSetup({
        global  : true,
        dataType: 'jsonp',
        jsonp   : 'jsoncallback',
        cache   : true
	}); 
  	var specialOffersSelected = false;
  	if (-1!=document.location.href.indexOf("promotions.jsp")) specialOffersSelected = true;
	
	// Get the categories with a JSON call
	menu = document.getElementById("menuDiv");	
	var tbl = document.createElement("table");
	tbl.style.width = "900px";
	tbl.setAttribute("id","topNavTbl");
	
	var tbdy = document.createElement("tbody");
	var trw = document.createElement("tr");
  		//contentType: "application/json",	
	$.ajax({
		type:"GET", cache:true, processData:false, url:url,
    		success:function(jsonp) {
			var len = jsonp.categories.length;
			var email_area = document.getElementById("email_banner");
			var email_ad = document.getElementById("email_ad");
			var footer_ad = document.getElementById("footer_ad");
			var assist_line = document.getElementById("call_assist_line");
			
			var isLast = false;
			var isFirst = false;
          
            if ( jsonp.status && jsonp.status == "success" && jsonp.categories ) {
            
            
            	if ( assist_line && jsonp.call_assist_line && jsonp.call_assist_line != "" ) {
				  assist_line.innerHTML = jsonp.call_assist_line;
				}
				if ( email_area && jsonp.email_banner_img && jsonp.email_banner_img != "" ) {
				  email_area.innerHTML = '<a href="' + jsonp.email_banner_href + '"><img src="' + jsonp.email_banner_img + '" border="0" alt="' + jsonp.email_banner_alt + '"/></a>';
				}
				if ( footer_ad ) {
				  if ( jsonp.footer_ad && jsonp.footer_ad != "" ) {
				    footer_ad.innerHTML = jsonp.footer_ad;
				  } else {
				    footer_ad.innerHTML = '<img src="http://shopping.franklinplanner.com/shopping/images/clear.gif" border="0"/>';
				  }
				}
				if ( email_ad ) {
				  if ( jsonp.email_ad && jsonp.email_ad != "" ) {
				    email_ad.innerHTML = jsonp.email_ad;
				  } else {
				    email_ad.innerHTML = '<img src="http://shopping.franklinplanner.com/shopping/images/clear.gif" border="0"/>';
				  }
				}
				
				if ( jsonp.first_name && jsonp.first_name != "" ) {
				    var login = document.getElementById("login_line");
					var welcome = document.getElementById("welcome_line");
					welcome.innerHTML = "<span id='welcome_message'>Welcome " + jsonp.first_name + "</span>";
					login.innerHTML = "<a class='nav_link' href='http://shopping.franklinplanner.com/shopping/common/autoLogout.jsp'>Log Out <img name='arrow_1' src='http://shopping.franklinplanner.com/shopping/images/shop_template/gray_arrow.gif' border='0'/></a>";
				}
				var domain = document.location.protocol + "//" + document.location.host;
				var itm = " Items ";
				var cart = document.getElementById("cart_line");
				var cartbtn = document.getElementById("cart_button");
				if ( jsonp.cart_count && jsonp.cart_count > 0 ) {
				  if ( jsonp.cart_count == 1 )
				  	itm = " Item ";
				  	cart.innerHTML = "<span id='cart_items'>" + jsonp.cart_count + itm + "</span><span id='cart_amount'>" + jsonp.cart_total + "</span>";
				    cartbtn.innerHTML = "<a href='http://shopping.franklinplanner.com/shopping/checkout/viewcart.jsp'><img src='http://shopping.franklinplanner.com/shopping/images/shop_template/my_cart_bottom.gif' style='display:block;border:none;' alt='Checkout'/></a>";
				} else {
				  cart.innerHTML = "<span id='cart_items'>0" + itm + "</span><span id='cart_amount'>"+jsonp.cart_total+"</span>";
				  cartbtn.innerHTML = "<img src='http://www.franklinplanner.com/shopping/images/shop_template/my_emptycart_bottom.gif' style='display:block;border:none;' alt='My Cart Header'/>";
				}       
				
				$.each(jsonp.categories, function(i,item){
                    if ( item.currentRootCategory != "" && currentRootCategory == "") {
                    	currentRootCategory = item.currentRootCategory;
                   	}
					var hasSubs = false;
					if ( item.subcategories && item.subcategories.length > 0 ) {
						hasSubs = true;
					}
                	var lr = "";
                	
					if ( i == 0 ) {
     					// Add the left round corner
     					lr = "l";
     					leftMenu = item.id;
     					var td = document.createElement("td");
     					td.style.height = "32px";
     					td.style.width = "6px";
     					if ((currentRootCategory && currentRootCategory == item.id)) {
     						currentMenu = currentRootCategory;
     						td.innerHTML = "<img name='menuLeft' src='http://www.franklinplanner.com/shopping/images/shop_template/lft_nav_corn_on.gif' border='0'/>";
     					} else {
     						td.innerHTML = "<img name='menuLeft' src='http://www.franklinplanner.com/shopping/images/shop_template/lft_nav_corn_off.gif' border='0'/>";
     					}
     					trw.appendChild(td);
   					}
   					if ( i+1 == len ) {
   						isLast = true;
   						lr = "r";
   						rightMenu = item.id;
   					}
   					var tda = document.createElement("td");
   					tda.style.fontSize = "11px";
  	 				tda.setAttribute("id", "td_" + item.id);
  	 				if ( (currentRootCategory && currentRootCategory == item.id && !isGC()) ||
  	 					 (item.id=="gift_cards" && isGC()) ||
  	 					 (item.id=="special_offers" && specialOffersSelected)
  	 				) {
  	 					if (currentRootCategory && !isGC()) currentMenu = currentRootCategory;
  	 					tda.className = 'menu_bg_on';	 					
  	 					if ( i == 0 ) {
  	 						td.innerHTML = "<img name='menuLeft' src='http://www.franklinplanner.com/shopping/images/shop_template/lft_nav_corn_on.gif' border='0'/>";
  	 					}
  	 				} else {
  	 					tda.className = 'menu_bg_off';
  	 				}
   					
     		    	//tda.style.backgroundRepeat = "repeat-x";
   		 
   					var catDiv = document.createElement("div");
   					catDiv.style.overflow = "hidden";
   					catDiv.style.height = "32px";
   					catDiv.style.textAlign = "center";
   					catDiv.style.color = "#ffffff";
   					catDiv.setAttribute("id","cat_" + item.id);
   				        if ( i == 0 ) {
   				        catDiv.innerHTML = "<img style='display:block;border:none;' src='http://www.franklinplanner.com/shopping/images/shop_template/clear_pixel.gif' height='8px' border='0'/>" + 
  				  		"<a onMouseOut='isRightMenu=false;isLeftMenu=true;menuHover=false;hideMenu=true;' onMouseOver='menuHover=true;showSubMenu(\"" + item.id + "\",\"" + lr + "\");' class='topnav_link' href='" + item.templateUrl + "'>" + item.name + "</a>";
   				        } else if ( isLast ) {
   				        catDiv.innerHTML = "<img style='display:block;border:none;' src='http://www.franklinplanner.com/shopping/images/shop_template/clear_pixel.gif' height='8px' border='0'/>" + 
  				  		"<a onMouseOut='isRightMenu=true;isLeftMenu=false;menuHover=false;hideMenu=true;' onMouseOver='menuHover=true;showSubMenu(\"" + item.id + "\",\"" + lr + "\");' class='topnav_link' href='" + item.templateUrl + "'>" + item.name + "</a>";
   				        } else {
   				        catDiv.innerHTML = "<img style='display:block;border:none;' src='http://www.franklinplanner.com/shopping/images/shop_template/clear_pixel.gif' height='8px' border='0'/>" + 
  				  		"<a onMouseOut='isRightMenu=false;isLeftMenu=false;menuHover=false;hideMenu=true;' onMouseOver='menuHover=true;showSubMenu(\"" + item.id + "\",\"" + lr + "\");' class='topnav_link' href='" + item.templateUrl + "'>" + item.name + "</a>";
   				        }
   						
   				 
   		
   					// Loop through subcategories and build up the options
   					var subCatDiv = null;
   				
   					if ( hasSubs == true ) {
   						subCatDiv = document.createElement("div");
   						$(subCatDiv).hover(
   						  function () {
   						    menuHover = true;
   						  },
   					  	function () {
   					  		menuHover = false;
   					  	}
   						);
   						//subCatDiv.style.display = "none";
   						$(subCatDiv).hide();
   						
   				   	 	subCatDiv.className = "sub_menu_on";
   						subCatDiv.setAttribute("id","subcat_" + item.id);
   						subCatDiv.style.width=((item.subcategories.length*175)+15)+"px";
   						eval("menuLoaded."+item.id+" = false; ");
   				
   						$.each(item.subcategories, function(j,subitem){
   							var subDivMain = document.createElement("div");
   							subDivMain.className = "sub_menu_1";

	   						$.each(subitem, function(j,subitem2){
   								var subDiv = document.createElement("div");
   								subDiv.className = "sub_menu_2";
   								subDiv.id="sub_menu_2_"+subitem2.id;
   								subDiv.innerHTML = "<b>" + subitem2.name + "</b>";

								//looks for what's this:
								if (subitem2.whatsThis)
								{
									subDiv.innerHTML+="<a href=\"#\" onclick=\"whatsThis('"+subitem2.id+"', 'block', '"+item.id+"'); return false;\" class=\"whatsThis\">what's this?</a>";
									var subDivWhatsThis = document.createElement("div");
			   						$(subDivWhatsThis).hover(
			   						  function () {
			   						    menuHover = true;
			   						  },
			   					  	function () {
			   					  		menuHover = false;
			   					  	}
			   						);
									
									subDivWhatsThis.className="sub_menu_2_whats_this";
									subDivWhatsThis.id="sub_menu_2_whats_this_"+subitem2.id;
									subDivWhatsThis.innerHTML = subitem2.whatsThis;
									menu.appendChild(subDivWhatsThis);
								}
   								
   								if (subitem2.thirdcategories) {
		   						$.each(subitem2.thirdcategories, function(j,subitem3){
	   								var subDiv2 = document.createElement("div");
	   								subDiv2.className = "sub_menu_3";
	   								subDiv2.innerHTML = "<a class='unav_link' href=\"" + subitem3.templateUrl + "\">" + subitem3.name + "</a>";
	   								subDiv.appendChild(subDiv2);
	   							});
	   							}

	   							subDivMain.appendChild(subDiv);
   							});

   							subCatDiv.appendChild(subDivMain);

   				 		});
   				 		
   				 		//if ( isLast )
   							//subCatDiv.style.marginLeft = "-95px";
   					}
   				
   				
   					tda.appendChild(catDiv);
   			   	 	if ( subCatDiv != null )
   						tda.appendChild(subCatDiv);
   							
   					trw.appendChild(tda);
   					if ( isLast ) {
     					// Add the right rounded corner
     					var td = document.createElement("td");
     					td.style.height = "32px";
     					td.style.width = "6px";
     					if (currentRootCategory && currentRootCategory == item.id && !isGC()) {
     						currentMenu = currentRootCategory;
     						td.innerHTML = "<img name='menuRight' src='http://shopping.franklinplanner.com/shopping/images/shop_template/rt_nav_corn_on.gif' border='0'/>";
						} else if (specialOffersSelected) {
     						td.innerHTML = "<img name='menuRight' src='http://shopping.franklinplanner.com/shopping/images/shop_template/rt_nav_corn_on.gif' border='0'/>";
     					} else {
     						td.innerHTML = "<img name='menuRight' src='http://shopping.franklinplanner.com/shopping/images/shop_template/rt_nav_corn_off.gif' border='0'/>";
     					}
     					trw.appendChild(td);
   					}
            	});
            } else {             
            	// The menu items are unavailable for some reason.
            	// Just show an empty bar with no options.
            	var tdl = document.createElement("td");
     			tdl.style.height = "32px";
     			tdl.style.width = "6px";
   				tdl.innerHTML = "<img name='menuLeft' src='http://shopping.franklinplanner.com/shopping/images/shop_template/lft_nav_corn_off.gif' border='0'/>";  
   					
   				var tda = document.createElement("td");  				
   				tda.innerHTML = "&nbsp;";  				
   				tda.className = 'menu_bg_off';				
   				var tdr = document.createElement("td");
     			tdr.style.height = "32px";
     			tdr.style.width = "6px";
   				tdr.innerHTML = "<img name='menuRight' src='http://shopping.franklinplanner.com/shopping/images/shop_template/rt_nav_corn_off.gif' border='0'/>";
   				trw.appendChild(tdl);
   				trw.appendChild(tda);
   				trw.appendChild(tdr);			
            }
            tbdy.appendChild(trw);
		    tbl.appendChild(tbdy);
		    if (document.getElementById('defaultTopNav')) document.getElementById('defaultTopNav').style.display="none";
   		    menu.appendChild(tbl);
        },
        error:function() {
        	// The menu items are unavailable for some reason.
            	// Just show an empty bar with no options.
            	var tdl = document.createElement("td");
     			tdl.style.height = "32px";
     			tdl.style.width = "6px";
   				tdl.innerHTML = "<img name='menuLeft' src='http://shopping.franklinplanner.com/shopping/images/shop_template/lft_nav_corn_off.gif' border='0'/>";  
   					
   				var tda = document.createElement("td");  				
   				tda.innerHTML = "&nbsp;";
   				tda.className = 'menu_bg_off';			
   				var tdr = document.createElement("td");
     			tdr.style.height = "32px";
     			tdr.style.width = "6px";
   				tdr.innerHTML = "<img name='menuRight' src='http://shopping.franklinplanner.com/shopping/images/shop_template/rt_nav_corn_off.gif' border='0'/>";
   				trw.appendChild(tdl);
   				trw.appendChild(tda);
   				trw.appendChild(tdr);	
   				tbdy.appendChild(trw);
		    	tbl.appendChild(tbdy);
			    if (document.getElementById('defaultTopNav')) document.getElementById('defaultTopNav').style.display="none";
   		   		menu.appendChild(tbl);	
        }
	});
}


function setPos(itemId)
{
	//DON't reset the position if it has already been set
	var isLoaded = eval("menuLoaded."+itemId);
	if (!isLoaded) 
	{
		//determine proper position for subNav elements
		var cell = document.getElementById("td_"+itemId);
		var submenu = document.getElementById("subcat_"+itemId);
		var topNavTbl = document.getElementById("topNavTbl");
		var menuDiv = document.getElementById("menuDiv");
		var cellLeft = getObjCoords(submenu);
		var menuLeft = getObjCoords(menuDiv);
		
		//get left position of highlighted menu option, relative to nav table.
		var pos = cellLeft.x - menuLeft.x;
		var navTableWidth=getDivWidth(topNavTbl);
		var topNavWidth=getDivWidth(cell);
		var subMenuWidth=getDivWidth(submenu);
		var relPos = pos+subMenuWidth;
		var relPos2 = relPos+topNavWidth;
		//if the submenu is wider than space available, then we'll need to adjust its x-coord
	
		/*//center the submenus under the top tops
		var center = subMenuWidth/2;
		var centerPx = (cellLeft.x+(topNavWidth/2))-center;
		//alert("cellPos: "+cellLeft.x+"\nsubMenuWidth: "+subMenuWidth+"\ncenteredPx: "+centerPx);
		if (centerPx < menuLeft.x+6) { centerPx = menuLeft.x+6; }
		else if (centerPx+subMenuWidth > menuLeft.x+navTableWidth) { 
			centerPx = menuLeft.x+navTableWidth-subMenuWidth-6; 
		}
		submenu.style.left= centerPx+"px";
		*/
		
		var leftAlign=cellLeft.x+topNavWidth-subMenuWidth;		
		//right-align elements that are past center section of topNavTbl
		if (pos > navTableWidth/2)
		{
			if (leftAlign>menuLeft.x)
			{
				//align with right side of topNav button
				submenu.style.left=leftAlign+"px";
			}
			else
			{
				submenu.style.left=menuLeft.x+6+"px";
			}
		}
		//alternate option, left-align submenu with top tab where possible
		else if (pos+subMenuWidth>navTableWidth)
		{
			//first see if we can just left-align the sub-menu, without it going past the leftCoord
			if (subMenuWidth<pos+subMenuWidth)
			{
				
				if (leftAlign>menuLeft.x)
				{
					//align with right side of topNav button
					//submenu.style.left=leftAlign+"px";
		
					//or rightAlign with right-most boundary of table
					submenu.style.left=(menuLeft.x+navTableWidth-subMenuWidth-6)+"px";
				}
				else
				{
					submenu.style.left=menuLeft.x+6+"px";
				}
				
			}
			//otherwise, just left-align it
			else
			{
				submenu.style.left=(cellLeft.x)+"px";
			}
			
		}
		eval("menuLoaded."+itemId+"=true");

	}
}


function isGC()
{
  	var gcSelected = false;
  	if (-1!=window.location.search.indexOf("prod290002")) gcSelected = true;
	return gcSelected;
}

function showSubMenu(catId,lr) {
  //alert(currentRootCategory);
    var currTd = document.getElementById("td_" + currentMenu);
	var catTd  = document.getElementById("td_" + catId);
	
  	var specialOffersSelected = false;
  	if (-1!=document.location.href.indexOf("promotions.jsp")) specialOffersSelected = true;

	closeWhatsThis();
    hideAllSubs(false);

  if ( currentSubMenu != "" ) {
  	$(currentSubMenu).hide();
  	//document.getElementById(currentSubMenu).style.display = "none";
  }
  if ( currentMenu != "") {
  	if (
  		(currentMenu == currentRootCategory && !isGC()) ||  
  		(specialOffersSelected && currentMenu=="special_offers") ||
  		(isGC() && currentMenu=="gift_cards")
  	) 
  	{
  		//do nothing
		currTd.className = 'menu_bg_off';
		//document.getElementById("td_" + currentMenu).style.backgroundImage = "url('http://www.franklinplanner.com/images/shop_template/nav_spcr_off.gif')";
  	}
  	else
	{
		currTd.className = 'menu_bg_off';
	  	//document.getElementById("td_" + currentMenu).style.backgroundImage = "url('http://www.franklinplanner.com/images/shop_template/nav_spcr_off.gif')";
	}
  }
  
  if ( lr != "" ) {
  	if ( lr == "l" ) 
  		document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_on.gif";
  	if ( lr == "r" ) 
  		document['menuRight'].src = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_on.gif";    
  } else {
    if ( currentMenu != "" && currentMenu != currentRootCategory && !specialOffersSelected) {
  		document['menuRight'].src = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_off.gif";
  		document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_off.gif";
  	}
  }
  if ( currentRootCategory != "" && leftMenu == currentRootCategory ) {
  	document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_on.gif";
  }
  if ( currentRootCategory != "" && rightMenu == currentRootCategory ) {
  	document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_on.gif";
  }
  catTd.className = 'menu_bg_on';
  //var bg  = document.getElementById('td_' + catId);
  //bg.style.backgroundImage = "url('http://www.franklinplanner.com/images/shop_template/nav_spcr_on.gif')";
  if (   document.getElementById('subcat_' + catId) ) {
  	var sub = document.getElementById('subcat_' + catId);

	//div must be set to 0 opacity & display = block in order to get the values for the submenu width and position
	changeOpac(0, 'subcat_'+catId);
	sub.style.textAlign = "left";
    sub.style.zIndex = '500';
  	sub.style.display = "block";
  	//set proper pos of submenu
  	setPos(catId);
  	sub.style.display="none";
	changeOpac(100, 'subcat_'+catId);
	$(sub).slideDown(200);
	//sub.style.display="block";
  	currentSubMenu = "subcat_" + catId;
	
  	lastMenu = currentMenu;
	hideAllSubs(true);
  	currentMenu = catId;
  } else {
    if ( currentSubMenu != "" ) {
      currentSubMenu = '';
      hideAllSubs();
    }
  }
  currentMenu = catId;
}

function hideSubMenu() {
  	var specialOffersSelected = false;
	var currTd = document.getElementById("td_" + currentMenu);
  	if (-1!=document.location.href.indexOf("promotions.jsp")) specialOffersSelected = true;



  if ( document.getElementById(currentSubMenu) ) 
  {
    //document.getElementById(currentSubMenu).style.display = "none";   
    $(currentSubMenu).hide();
	closeWhatsThis();
  }

  if ( document.getElementById("td_" + currentMenu))
  {
  	if (
  		(currentMenu == currentRootCategory && !isGC()) ||  
  		(specialOffersSelected && currentMenu=="special_offers") ||
  		(isGC() && currentMenu=="gift_cards")
  	) 
  	{
  		//do nothing
		currTd.className = 'menu_bg_off';
		//document.getElementById("td_" + currentMenu).style.backgroundImage = "url('http://www.franklinplanner.com/images/shop_template/nav_spcr_off.gif')";
  	}
  	else
  	{
		currTd.className = 'menu_bg_off';
	  	//document.getElementById("td_" + currentMenu).style.backgroundImage = "url('http://www.franklinplanner.com/images/shop_template/nav_spcr_off.gif')";
  	}
  }
  if ( document['menuLeft'] ) {
  	if ( currentRootCategory != "" && leftMenu == currentRootCategory ) {
  		document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_on.gif";
 	 } else {
 	   	if ( isLeftMenu ) {
  			document['menuLeft'].src = "http://www.franklinplanner.com/images/shop_template/lft_nav_corn_off.gif";
  			isLeftMenu = false;
  		}
  	}
  }
  
  if ( document['menuRight'] ) {
  	if (( currentRootCategory != "" && rightMenu == currentRootCategory) || specialOffersSelected ) {
  		document['menuRight'].src = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_on.gif";
  	} else {
  	    if ( isRightMenu ) {
  		document['menuRight'].src = "http://www.franklinplanner.com/images/shop_template/rt_nav_corn_off.gif";
  			rightMenu = false;
  		}
  	}
  }
  	hideAllSubs(true);
 
}

 // Generates a go nav menu
 function goNav() {
	    if ( document.getElementById('go_nav') ) {
	    	var url = "http://www.franklinplanner.com/fc/common/json_leftnav.jsp";
		$.ajaxSetup({
        		global  : true,
       			dataType: 'jsonp',
        		jsonp   : 'jsoncallback',
        		cache   : true
		}); 
		    
		$.ajax({ type:"GET", processData:false, url:url,
    			success:function(jsonp) {
				if ( jsonp.items && jsonp.items.length > 0 ) {
					// Build up a dom element with the menu items
					var goDiv = document.getElementById('go_nav');
					var goTable = document.createElement('table');
					goTable.setAttribute('style','width:170px;');
					var goTbody = document.createElement('tbody');
					// The Title
					var titleTr = document.createElement('tr');
					var titleTd = document.createElement('td');
					titleTd.style.paddingLeft = "5px";
					titleTd.innerHTML = "<b>" + jsonp.title + "</b>";
					titleTr.appendChild(titleTd);
					goTbody.appendChild(titleTr);

					$.each(jsonp.items, function(i,item) {
						var aTr = document.createElement('tr');
						var aTd = document.createElement('td');
						aTd.style.paddingLeft = "7px";
						aTd.style.paddingRight = "5px";
						aTd.style.paddingTop = "2px";
						aTd.innerHTML = "<a href='" + item.url + "' class='gonav_link'>" + item.name + "</a>";
						aTr.appendChild(aTd);
						goTbody.appendChild(aTr);
					});
					goTable.appendChild(goTbody);
					goDiv.appendChild(goTable);
				}
			}
		});
	    }
    }
function findPositionX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function findPositionY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

// In normal fc_nav.  But included here for third party stuff
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if (els[i].className && els[i].className.match(pattern)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function getDivHeight(pNode)
{ 
	return pNode.innerHeight?pNode.innerHeight:pNode.offsetHeight+document.body.offsetTop; 
}
function getDivWidth(pNode)
{ 
	return pNode.innerWidth?pNode.innerWidth:pNode.offsetWidth; 
}

function setPos(itemId)
{
	//DON't reset the position if it has already been set
	var isLoaded = eval("menuLoaded."+itemId);
	if (!isLoaded) 
	{
		//determine proper position for subNav elements
		var cell = document.getElementById("td_"+itemId);
		var submenu = document.getElementById("subcat_"+itemId);
		var topNavTbl = document.getElementById("topNavTbl");
		var menuDiv = document.getElementById("menuDiv");
		var cellLeft = getObjCoords(submenu);
		var menuLeft = getObjCoords(menuDiv);
		
		//get left position of highlighted menu option, relative to nav table.
		var pos = cellLeft.x - menuLeft.x;
		var navTableWidth=getDivWidth(topNavTbl);
		var topNavWidth=getDivWidth(cell);
		var subMenuWidth=getDivWidth(submenu);
		var relPos = pos+subMenuWidth;
		var relPos2 = relPos+topNavWidth;
		//if the submenu is wider than space available, then we'll need to adjust its x-coord
	
		/*//center the submenus under the top tops
		var center = subMenuWidth/2;
		var centerPx = (cellLeft.x+(topNavWidth/2))-center;
		//alert("cellPos: "+cellLeft.x+"\nsubMenuWidth: "+subMenuWidth+"\ncenteredPx: "+centerPx);
		if (centerPx < menuLeft.x+6) { centerPx = menuLeft.x+6; }
		else if (centerPx+subMenuWidth > menuLeft.x+navTableWidth) { 
			centerPx = menuLeft.x+navTableWidth-subMenuWidth-6; 
		}
		submenu.style.left= centerPx+"px";
		*/
		
		var leftAlign=cellLeft.x+topNavWidth-subMenuWidth;		
		//right-align elements that are past center section of topNavTbl
		if (pos > navTableWidth/2)
		{
			if (leftAlign>menuLeft.x)
			{
				//align with right side of topNav button
				submenu.style.left=leftAlign+"px";
			}
			else
			{
				submenu.style.left=menuLeft.x+6+"px";
			}
		}
		//alternate option, left-align submenu with top tab where possible
		else if (pos+subMenuWidth>navTableWidth)
		{
			//first see if we can just left-align the sub-menu, without it going past the leftCoord
			if (subMenuWidth<pos+subMenuWidth)
			{
				
				if (leftAlign>menuLeft.x)
				{
					//align with right side of topNav button
					//submenu.style.left=leftAlign+"px";
		
					//or rightAlign with right-most boundary of table
					submenu.style.left=(menuLeft.x+navTableWidth-subMenuWidth-6)+"px";
				}
				else
				{
					submenu.style.left=menuLeft.x+6+"px";
				}
				
			}
			//otherwise, just left-align it
			else
			{
				submenu.style.left=(cellLeft.x)+"px";
			}
			
		}
		eval("menuLoaded."+itemId+"=true");

	}
}

function Point(x, y) {
    this.x = x;
    this.y = y;
}

function getObjCoords(o) {
    var oX = 0;
    var oY = 0;
    if (o.offsetParent) {
        while (1) {
            oX+=o.offsetLeft;
            oY+=o.offsetTop;
                if (!o.offsetParent) {
                    break;
                }
            o=o.offsetParent;
        }
    } else if (o.x) {
        oX+=o.x;
        oY+=o.y;
    }
    //alert(oX + ":" + oY);
    return new Point(oX, oY);
}

function hideAllSubs(pCheckCurrent)
{
  // Turn off all other menus - if any are on
  	var menuNode= document.getElementById('topNavTbl');
  	var subMenus = getElementsByClass("sub_menu_on", menuNode, "div");
  	if (null!=subMenus && ""!=subMenus)
  	{
  		for (i=0; i<subMenus.length; i++)
  		{
  			if ( pCheckCurrent && menuHover == true && currentSubMenu != "" && currentSubMenu==subMenus[i].id )
  			{ /*do not hide this submenu*/ }
  			else
  			{
			  	$(subMenus[i]).hide();
			}
  		}
  	}
}

