// #
// ######################################
// ###
// ### Main Navigation Button Functions
// ###
// ######################################
// #

var gs_Previous_Content_Div = "";
var gs_Previous_Menu_Div = "";
var gb_Currently_Hovering_Over_Menu_Item = false;

// #
// ### Declare Div Id's for each Dropdown Menu
// #

var s_Menu_Ids = ["div_Services", "div_Solutions", "div_About_Us", "div_Partners", "div_Contact"];
var s_Menu_Child_Ids = ["div_Services_Content", "div_Solutions_Content", "div_About_Us_Content", "div_Partners_Content", "div_Contact_Content"];

// #
// ### Set the properties of the Dropdown Menu's
// #

var l_Menu_Option_Count = [5,4,5,5,2];
var l_Menu_Height = [0,0,0,0,0];
var l_Menu_Target = [0,0,0,0,0];
var lk_MENU_OPTION_HEIGHT = 34;
var obj_Active_Timer;
var obj_Hide_Menu_Timer;

// #
// ### Get the page name from the URL and convert to Lower Case
// #

var gs_Entity_Name = JS_Extract_Page_From_Url();

var img_src=["dropdown_normal.gif", "dropdown_mouseover.gif", "dropdown_select.gif"];
var img=new Array();


// #
// ### 
// #

for (var i=0;i<img_src.length;i++)
{
  img[i] = new Image(192,32);
  img[i].src = "../images/" + img_src[i];
}

function JS_Get_Menu_Id(s_parm_Menu_Name)
{
  var i, result=-1;
  
  for (i=0;i<s_Menu_Ids.length; i++)
  {
     
    if (s_Menu_Ids[i] == s_parm_Menu_Name)
    {
      result = i;
      continue;
    }
  }
  
  return result;
}

// #
// ### Using the page name from the URL, match this to the correct menu section.
// #

function JS_Get_Section(s_parm_Page)
{
  var s_Page = new String(s_parm_Page);
  var s_Parent;
  switch(s_Page.toLowerCase())
  {
    case "home"          : s_Parent = "Home"; break;
    
    case "services":
    case "managed_services":
    case "consulting":
    case "reporting":
    case "support":
    case "development"   : s_Parent = "Services"; break;
    
    case "solutions":
    case "isb_sms":
    case "isb_mobile":
    case "isb_mortgage":
    case "isb_form"      : s_Parent = "Solutions"; break;
    
    case "about_us":  
    case "history":
    case "industry_focus":
    case "security":
    case "accreditations":
    case "media_room"    : s_Parent = "About_Us"; break;

    case "partners":
    case "o2":
    case "mblox":
    case "microsoft":
    case "the_bunker":
    case "infinity"      : s_Parent = "Partners"; break;
	
    case "contact":
    case "address":
    case "careers"       : s_Parent = "Contact"; break;
  }

  return s_Parent;
}

// #
// ### Calculate the height of the Dropdown Div
// #

function Start_Move_Down(s_parm_Menu_Name)
{
  var l_Menu_Id = JS_Get_Menu_Id(s_parm_Menu_Name);
  
  var obj_Div = document.getElementById(s_Menu_Ids[l_Menu_Id]);
  
  if (l_Menu_Id >= 0)
  {
    var l_Menu_Target_Height = l_Menu_Option_Count[l_Menu_Id] * lk_MENU_OPTION_HEIGHT;
    
    clearTimeout(obj_Active_Timer); 
    
    l_Menu_Height[l_Menu_Id] = 0;
    l_Menu_Target[l_Menu_Id] = l_Menu_Target_Height;
    
    obj_Div.style.height = "0px";
    
    obj_Active_Timer = setTimeout("Move_Down(" + l_Menu_Id + ");", 10);
  }
}

// #
// ### Move_Down
// #

function Move_Down(l_Parm_Menu_Id)
{
  var l_delta;
  var obj_Div;
  
  obj_Div = document.getElementById(s_Menu_Ids[l_Parm_Menu_Id]);

  l_delta = (l_Menu_Target[l_Parm_Menu_Id] - l_Menu_Height[l_Parm_Menu_Id]) / 10.0;

  
  if ((l_Menu_Target[l_Parm_Menu_Id] - l_Menu_Height[l_Parm_Menu_Id]) <= 1)
  {
     l_Menu_Height[l_Parm_Menu_Id]  = l_Menu_Target[l_Parm_Menu_Id];
     
     obj_Div.style.height = l_Menu_Height[l_Parm_Menu_Id] + "px";
     
     clearTimeout(obj_Active_Timer);
     
  }
  else
  {
    l_Menu_Height[l_Parm_Menu_Id] += l_delta;
    
    obj_Active_Timer = setTimeout("Move_Down(" + l_Parm_Menu_Id + ");", 10);
  }  
 
 
  obj_Div.style.height = parseInt(l_Menu_Height[l_Parm_Menu_Id]) + "px";
  
}


// #
// ### JS_Menu_Mouseout
// ### Shows Normal Navigation Button & Hides Dropdown Menu
// #
	
function JS_Menu_Mouseout(obj_parm_img, s_parm_entity_name)
{
	// #
	// ### Check that the entity name is not the same as in the url
	// #

	if (s_parm_entity_name.toLowerCase() != JS_Get_Section(gs_Entity_Name).toLowerCase())
	{
		// #
		// ### Construct the Filename
		// #
		
		//var filename = "images/menubar_" + s_parm_entity_name + ".gif";
		
		// #
		// ### Assign the Image
	  // #
		
		//obj_img.src = filename;
    obj_parm_img.setAttribute("class", "MenuButton_Normal");
    obj_parm_img.setAttribute("className", "MenuButton_Normal");
	}
	
  obj_Hide_Menu_Timer = setInterval("JS_Hide_Menu(\"" + s_parm_entity_name + "\")",200);
}

	
// #
// ### JS_Menu_Mouseover
// ### Shows the selected button image
// ### Hides the previous menu and shows the recently selected one
// #

	function JS_Menu_Mouseover(obj_parm_img, s_parm_entity_name, s_parm_div)
	{
	
		var l_Image_Top;
		var l_Image_Left;
		var l_Image_Height;
		var l_Image_Width;
		
		var l_Menu_Height_Top;
		var l_Menu_Height_Left;
		
		// #
		// ### Check that the entity name is not the same as in the url
		// #

		if (s_parm_entity_name.toLowerCase() != JS_Get_Section(gs_Entity_Name).toLowerCase())
    {

			// #
			// ### Construct the Filename
			// #

			//var filename="images/menubar_" + s_parm_entity_name + "_select.gif";

			// #
			// ### Assign the Image
			// #

			//obj_parm_img.src = filename;
      
      obj_parm_img.setAttribute("class","MenuButton_Mouseover");
      obj_parm_img.setAttribute("className", "MenuButton_Mouseover");

			
		}
	
		// #
		// ### Check to see if we have a previous menu open
		// #

		if (gs_Previous_Menu_Div != "")
		{

			// #
			// ### If so, hide it
			// #

			document.getElementById(gs_Previous_Menu_Div).style.display = "none";

		}


		// #
		// ### Grab the position of the image that was clicked on
		// #

		l_Image_Top = 0;
		l_Image_Left = 0;
		
	  var obj_Element = obj_parm_img;
		var window_width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
		var x_offset = (window_width-800) < 0 ? 0 : window_width-800;
		
		x_offset /= 2;
		
		if (obj_Element.offsetParent) 
		{
			do 
			{
				l_Image_Left += obj_Element.offsetLeft;
				l_Image_Top += obj_Element.offsetTop;
        obj_Element = obj_Element.offsetParent;
			} while (obj_Element.offsetParent);
			
		}

		l_Menu_Height_Top = l_Image_Top + 1;
		l_Menu_Height_Left = parseInt(l_Image_Left - x_offset);
				
		// #
		// ### Show the requested menu
		// #

		
		document.getElementById(s_parm_div).style.top = l_Menu_Height_Top + 31 + "px";
		document.getElementById(s_parm_div).style.left = l_Menu_Height_Left + "px";
    document.getElementById(s_parm_div).style.height = "0px";
		document.getElementById(s_parm_div).style.display = "inline";

		// #
		// ### Store the menu for future reference
		// #

		gs_Previous_Menu_Div = s_parm_div;
		
   
    Start_Move_Down(s_parm_div);
		
    clearInterval(obj_Hide_Menu_Timer);
	}

// #
// ### JS_Menu_Mouseover_Close_Button
// ### Shows the selected button image on the Close Button
// #

	function JS_Menu_Mouseover_Close_Button(obj_parm_img, s_parm_entity_name)
	{
		
		// #
		// ### Construct the Filename
		// #

		var filename="images/menubar_" + s_parm_entity_name + "_select.gif";

		// #
		// ### Assign the Image
		// #

		obj_parm_img.src = filename;
			
	}
	
// #
// ### JS_Menu_Click
// ### Creates Hyperlink to Selected Page
// #

function JS_Menu_Click(obj_img, my_url)
{

  // #
  // ### Assign the Hyperlink
  // #


  document.location.href=my_url;
}

	
// #	
// ######################################
// ###
// ### Dropdown Menu Button Functions
// ###
// ######################################
// #
	
function JS_Hide_Menu(s_parm_entity_name)
{
  var s_Section = JS_Get_Section(s_parm_entity_name);
  
  if (!gb_Currently_Hovering_Over_Menu_Item)
  {
    document.getElementById("div_" + s_Section).style.display = "none";

    clearInterval(obj_Hide_Menu_Timer);
  }
}

	
// #
// ### JS_Menu_Option_Mouseout
// ### Shows the Normal Dropdown Button
// #

function JS_Menu_Option_Mouseout(obj_img, s_parm_entity_name)
{
	
	// #
	// ### Check that the entity name is not the same as in the url
	// #

	if (s_parm_entity_name.toLowerCase() != gs_Entity_Name.toLowerCase())
	{
    obj_img.setAttribute("class", "DropdownOptionNormal");
    obj_img.setAttribute("className", "DropdownOptionNormal");
	}
  
  gb_Currently_Hovering_Over_Menu_Item = false;
  
  obj_Hide_Menu_Timer = setInterval("JS_Hide_Menu(\"" + s_parm_entity_name + "\")",200);
}


// #
// ### JS_Menu_Option_Mouseover
// ### Shows the Mouseover Dropdown Button
// #

	function JS_Menu_Option_Mouseover(obj_img, s_parm_entity_name)
	{
		
		// #
		// ### Check that the entity name is not the same as in the url
		// #
		
		if (s_parm_entity_name.toLowerCase() != gs_Entity_Name.toLowerCase())
		{
      obj_img.setAttribute("class", "DropdownOptionMouseover");
      obj_img.setAttribute("className", "DropdownOptionMouseover");
  	}
    
    gb_Currently_Hovering_Over_Menu_Item = true;
    clearInterval(obj_Hide_Menu_Timer);
	}

// #
// ### JS_Menu_Option_Click
// ### Shows the Selected Dropdown Button
// #

function JS_Menu_Option_Click(obj_img, s_parm_entity_name, my_url)
{

  obj_img.setAttribute("class", "DropdownOptionSelect");
  obj_img.setAttribute("className", "DropdownOptionSelect");

  // #
  // ### Assign the Hyperlink
  // #

  document.location.href=my_url;
}



// #
// ### JS_Extract_Page_From_Url
// ### Extracts the page name from the end of the Url.
// #


function JS_Extract_Page_From_Url()
{
  var s_URL = document.location.href;


  //remove everything before the last slash in the path
  s_URL = s_URL.substring(s_URL.lastIndexOf("/") + 1, s_URL.length).replace(".asp", "");

  //return
  return s_URL;
}


function JS_Show_Current_Page()
{
	var obj_Current_Page_Menu_Option;
	var obj_Current_Page_Menu;
	var b_Success = false;

	// #
	// ### Construct the Filename
	// #

	try 
	{
		obj_Current_Page_Menu_Option = document.getElementById("Dropdown_Option_" + gs_Entity_Name);
		b_Success = true;
	}
	catch (e)
	{
		b_Success = false;
	}

	if (b_Success && obj_Current_Page_Menu_Option)
	{
    obj_Current_Page_Menu_Option.setAttribute("class", "DropdownOptionSelect");
    obj_Current_Page_Menu_Option.setAttribute("className", "DropdownOptionSelect");  
	}
	
  try 
  {
    obj_Current_Page_Menu = document.getElementById("Img_Nav_Menu_" + JS_Get_Section(gs_Entity_Name));
    b_Success = true;
  }
  catch (e)
  {
    b_Success = false;
  }

  if (b_Success && obj_Current_Page_Menu)
  {
    // #
    // ### Construct the Filename
    // #

    //var filename="images/menubar_" + JS_Get_Section(gs_Entity_Name) +"_select.gif";


    // #
    // ### Assign the Image
    // #

    //obj_Current_Page_Menu.src = filename;
    obj_Current_Page_Menu.setAttribute("class", "MenuButton_Select");
    obj_Current_Page_Menu.setAttribute("className", "MenuButton_Select");
  }
  
}

// #
// ######################################
// ###
// ### Media_Room.asp Functions
// ###
// ######################################
// #


// #
// ### JS_Show_Content
// ### Hides and shows page content 
// #


function JS_Show_Content(obj_parm_img, s_parm_milestone_content)
{ 
  var filename;
  var s_parm_div;
  
  // #
	// ### Construct the div name
	// #
		
	s_parm_div = "Milestone" + s_parm_milestone_content + "Content";
  
  
	// #
	// ### Check to see if we have a previous div open
	// #

	if (gs_Previous_Content_Div != "")
	{	
		// #
		// ### If so, hide it
		// #
		
		document.getElementById(gs_Previous_Content_Div).style.display = "none";
		
		if (obj_parm_img != gobj_Previous_Content_Image)
		{
			gobj_Previous_Content_Image.src="Images/plus.gif";
		}
	}
	
	if (obj_parm_img.src.indexOf("Images/plus.gif") != -1)
	{
		// #
		// ### Construct the filename
		// #	
		
		filename="Images/minus.gif";
		
		// #
		// ### Construct the filename
		// #	
		
		obj_parm_img.src = filename;
		

		// #
		// ### Show the requested menu
		// #
		
		document.getElementById(s_parm_div).style.display = "inline";
    
    gs_Previous_Content_Div = s_parm_div;
    gobj_Previous_Content_Image = obj_parm_img;
	
	}
	else 
	{

		// #
		// ### Construct the filename
		// #	
		
		filename="Images/plus.gif";
		
		// #
		// ### Construct the filename
		// #	
		
		obj_parm_img.src = filename;
		
		// #
		// ### Show the requested menu
		// #
		
		document.getElementById(s_parm_div).style.display = "none";
    
    gs_Previous_Content_Div = "";

	}
	
	
}


