    // This script is copywrited and is the soleproperty of 4D Internet Solutions, Inc.
    // It may not be used, copied, sold or reproduced in any form without the express written consent of 4D Internet Solutions, Inc.
	
    // convert all characters to lowercase
    var agt=navigator.userAgent.toLowerCase();

    // Check browser version
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
  
   if (is_ie5up) {
 document.write('<LINK HREF="/lib/cupidshut/styles-ie2.css" TYPE="text/css" REL="stylesheet">');
    } else {
 document.write('<LINK HREF="/lib/cupidshut/styles-ff2.css" TYPE="text/css" REL="stylesheet">');
    }
 

var currentMenu = null;

var isMenuOn = false;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function checkMenu() {
	if (isMenuOn == false && currentMenu != null) {
        currentMenu.style.visibility = "hidden";
	}
}
	
function initializeMenu(menuId, triggerId, menuHeight) {
    var menu = document.getElementById(menuId);
    var trigger = document.getElementById(triggerId);

    if (menu == null || trigger == null) return;

    //menu with can be set here instead of stylesheet
    //menu.style.width = 230 + "px";

    document.onclick = function() {
        if (currentMenu != null) {
            currentMenu.style.visibility = "hidden";
        }
    }

	
    trigger.onmouseover = function(event) {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu(menuHeight,event);
        } else {
	    this.showMenu(menuHeight,event);		
		}
		isMenuOn = true;
		trigger.className = 'bg-on';
    }
	
    trigger.onmouseout = function() {
		trigger.className = 'bg';
		isMenuOn = false;
		setTimeout("checkMenu()", 800);
	}
	
	menu.onmouseout = function() {
		isMenuOn = false;
		setTimeout("checkMenu()", 100);
	}

	menu.onmouseover = function() {
		isMenuOn = true;
	}
  
    //displays sub menu and ties it to bounding box  
    trigger.showMenu = function(navHeight, e) {
	//get mouse location
        var posx = 0;
	var posy = 0;
	
        if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY - window.pageYOffset;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX; //+ document.body.scrollLeft;
		posy = e.clientY; // + document.body.scrollTop;
	}

        //get menu height        
        var myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
          //Non-IE
          myHeight = window.innerHeight;
        } else if( document.documentElement &&
            ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          //IE 6+ in 'standards compliant mode'
          myHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
          //IE 4 compatible
          myHeight = document.body.clientHeight;
        }

        if((navHeight + posy) > myHeight) {
            if (navHeight > posy) 
              { var heightmodifier = posy + 10;  }
            else
              { var heightmodifier = navHeight; }
          }
        else
          { var heightmodifier = 0; }


        if (is_ie5up) {
   	  menu.style.left = document.body.scrollLeft + this.getBoundingClientRect().left + 200 + "px";
          // if to get IE to show upward nav in correct place
         if (heightmodifier > 0) {
             var heightmodifier = heightmodifier - 23;
             }
          menu.style.top = document.body.scrollTop + this.getBoundingClientRect().top - heightmodifier - 3 + "px";
        } else {
          // if to let upward FF nav show in correct place because down nav had to be modified
          if (heightmodifier > 0) {
             var heightmodifier = heightmodifier - 23;
             }
           menu.style.top = document.getBoxObjectFor(this).y + document.getBoxObjectFor(this).height - heightmodifier - 23 + "px";
           menu.style.left = document.getBoxObjectFor(this).x + 150 + "px";
 
       }
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

