var popupTexts = new Array(
    "World Class Wakefield, Who first Are",
    "Investment, Financial Support, Supporting New Business, Marketing",
    "Commercial Land and Property",
    "first Friday Events",
    "Award Categories, Entry Forms"
  );

function updateHoverInStyles( id )
{
  $( "#" + id + " .topMainMenuItemL" ).css( "background-position", "0% -22px" );
  $( "#" + id + " .topMainMenuItemR" ).css( "background-position", "100% -22px" );
  $( "#" + id + " .topMainMenuItemR a" ).css( "color", "#002E5F" );
  $( "#" + id + " .topMainMenuItemR a" ).css( "text-decoration", "none" );
}

function updateHoverOutStyles( id )
{
  $( "#" + id + " .topMainMenuItemL" ).removeAttr( "style" );
  $( "#" + id + " .topMainMenuItemR" ).removeAttr( "style" );
  $( "#" + id + " .topMainMenuItemR a" ).removeAttr( "style" );
}

function findPos( obj )
{
  var curleft = 0;
  var curtop  = 0;

  if( obj.offsetParent )
  {
    if( typeof( obj.posDims ) == "undefined" || typeof( obj.posDims.length ) == "undefined" )
    {
      var currObj = obj;

      do
      {
        curleft += currObj.offsetLeft;
        curtop  += currObj.offsetTop;
      } while( currObj = currObj.offsetParent );

      obj.posDims = [curleft, curtop];
    }

    return obj.posDims;
  }
}

function positionTextPopup(obj, indexText)
{
  if( indexText == null )
  {
    return;
  }

  var topMainMenuObj = $( "#topMainMenu" );
  var parentDims = findPos( topMainMenuObj[0] );

  var dims = findPos( obj );

  $( "#popupText" ).css( "top",  dims[1] - parentDims[1] - 28 );
  $( "#popupText" ).css( "left", dims[0] - parentDims[0] + obj.offsetWidth - 15 );

  $( ".menutextInner" ).text( popupTexts[indexText] );

  $( "#popupText" ).show();
}

function setShowPanel( colour )
{
  var colours = new Array( 'purple', 'green', 'orange' );

  //set tab states
  for( var i=0; i<colours.length; i++ )
  {
    if( colours[i] != colour )
    {

      if( $( "#" + colours[i] + "MainMenuTab" ).hasClass( colours[i] + "MainMenuTab_On" ) )
      {
        $( "#" + colours[i] + "MainMenuTab" ).removeClass( colours[i] + "MainMenuTab_On" );
        $( "#" + colours[i] + "MainMenuTab" ).addClass( colours[i] + "MainMenuTab" );
      }
    }
  }

  $( "#" + colour + "MainMenuTab" ).removeClass( colour + "MainMenuTab" );
  $( "#" + colour + "MainMenuTab" ).addClass( colour + "MainMenuTab_On" );

}

function setPanelItem( containerId, pageType, colour )
{
  //console.log( containerId );
  //console.log( pageType );
  //console.log( colour );

  $( "#" + containerId ).load( "/lists/showPanelItem.jsp", { l:pageType, maxItems:1, hideHeader:true, hideDate:true, boxColour: colour  }, function(){
    //alert("tara");
  } );
}

