// JavaScript Document
// globals

var currentPage;
var item;
var timer;
var cnt;
var max;
var current;
$(function()
{

  currentPage = $("body").attr("id")
  //==============================================================
  // menu handling
  // hide all submenus
  $("#leftSidebar .menu .submenu").hide();

  $("li."+currentPage+" ul.submenu" ).show();
  // show this pages submentu
  $("#leftSidebar .menu ul li > div").each(function()
  {
    var text = "<div> "+ $(this).html() + "</div>"
    $(this).html(text)
  });
  $("#sitemap #mainContent .flyout").removeClass("flyout").css("display","none")
  
  $("#leftSidebar .menu > ul > li a").hover(function(event)
  {
      if (! $(this).parent().attr("class").match(currentPage))
      {
        event.stopPropagation();
        $(".menu .flyout").hide();
        item = $(this).parent()
        timer = setTimeout('showMenuItem()',50)
      }
      return false;
  },
  function(event)
  {
      event.stopPropagation();
      $(".menu  .flyout").hide();
      return false;
  })
  // end of menu section
  //==============================================================
  // open and close 
  $(".openclose >  h2").removeClass("open").addClass("closed")
  $(".openclose >  h2").next().hide()
/*   do the open and close on the vertical markets and technology practices and bios*/
  $(".openclose >  h2").click(function()
  {

    $(this).next().slideToggle()
    if ($(this).attr("class").match(/opened/))
    {
        $(this).addClass("closed").removeClass("opened")
    }
    else
    {
        $(this).addClass("opened").removeClass("closed")
    }
  
  });
  // end of practices section
  //==============================================================
  // search button
      $(".searchBoxText").focus(function()
      {
          if ($(this).attr("value") == "Search")
          {
             $(this).attr("value","")
          }
      });
      $(".searchBoxText").blur(function()
      {
          if ($.trim($(this).attr("value")) == "")
          {
             $(this).attr("value","Search")
          }
      });  
      //==============================================================
      // home page whats new section
      cnt = $("#whatsnew .section").length;
	  cnt2 = $("#whatsnew2 .section").length;
      max = 0;
	  max2 = 0;
      $("#whatsnew .section").each(function()
      {
          if ($(this).height() > max) { max = $(this).height() + 40 };     
      })
	  
	  $("#whatsnew2 .section").each(function()
      {
          if ($(this).height() > max2) { max2 = $(this).height() + 40 };     
      })
	  
	  if (max2 > max) {max=max2}
	  
      $("#whatsnew").css("height",max)
      current = 0;
      if (cnt > 1) { $("#whatsnew .controls").show(); }
      $("#whatsnew .section").hide().eq(current).fadeIn(400) 
      $("#whatsnew #next").click(function()
      {
        // $("#whatsnew .section").eq(current).slideUp(400);
		 $("#whatsnew .section").eq(current).fadeOut(400);
         current = current + 1;
         if (current >= cnt) { current = 0;}
         //$("#whatsnew .section").eq(current).slideDown(500);
		 $("#whatsnew .section").eq(current).delay(400).fadeIn(500);
         return false;
      });
      $("#whatsnew #prev").click(function()
      {
        // $("#whatsnew .section").eq(current).slideUp(400);
		 $("#whatsnew .section").eq(current).fadeOut(400);
         current = current - 1;
         if (current < 0 ) { current = cnt-1;}
        // $("#whatsnew .section").eq(current).slideDown(500);
		 $("#whatsnew .section").eq(current).delay(400).fadeIn(500);
         return false;
      });   
	  //----------------------------------------------------
	 
      
      $("#whatsnew2 .section").each(function()
      {
          if ($(this).height() > max) { max = $(this).height() + 30 };     
      })
      $("#whatsnew2").css("height",max)
      current = 0;
      if (cnt > 1) { $("#whatsnew2 .controls").show(); }
      $("#whatsnew2 .section").hide().eq(current).fadeIn(400) 
      $("#whatsnew2 #next2").click(function()
      {
        // $("#whatsnew .section").eq(current).slideUp(400);
		 $("#whatsnew2 .section").eq(current).fadeOut(400);
         current = current + 1;
         if (current >= cnt) { current = 0;}
         //$("#whatsnew .section").eq(current).slideDown(500);
		 $("#whatsnew2 .section").eq(current).delay(400).fadeIn(500);
         return false;
      });
      $("#whatsnew2 #prev2").click(function()
      {
        // $("#whatsnew .section").eq(current).slideUp(400);
		 $("#whatsnew2 .section").eq(current).fadeOut(400);
         current = current - 1;
         if (current < 0 ) { current = cnt-1;}
        // $("#whatsnew .section").eq(current).slideDown(500);
		 $("#whatsnew2 .section").eq(current).delay(400).fadeIn(500);
         return false;
      });   
      //==============================================================
      // animate back to top links
             
    //Click event handler for any anchor that has an href that ends in top
      $('#linecard a.scroll').click(function() {
       
        //Animates scroll to the top of the page...and take 1 second to do it.
          $('html, body').animate({ scrollTop:0 }, '1000');
   
        //return false to prevent the default action of the anchor tag when clicked.
          return false;
 
      }); 
      //==============================================================
      // no flash on home page
      $("#noflash").click(function()
      {
        $("#flashHeader").html("<img src='/images/flashFPO.jpg' />")
        return false;
      });
});
function showMenuItem()
{
          clearTimeout(timer);
          pos = item.children("a").innerWidth();
          //if ($(this).children("div:visible")) { return false; }
          item.children("div").css("left",pos).fadeIn();
}

