var gColumnId;
var gUserId;
var gTagViewMode;
var gPanelFunctionLoaders = new Object();
gPanelFunctionLoaders['notification'] = nopremNotificationPanel;
gPanelFunctionLoaders['tagcloud'] = nopremTagCloudPanel;
gPanelFunctionLoaders['profile'] = nopremProfilePanel;
gPanelFunctionLoaders['network'] = nopremNetworkPanel;
function toggleRightColumnVisible( columnId, userId, tagViewMode )
{
  var thePal = document.getElementById( 'palette_' + columnId + '_collapsible' );
  var newVisibility = 'true';
  if( thePal.style.display == 'block' || thePal.style.display == '' || thePal.style.display == 'undefined' )
  {
    newVisibility = 'false';
  }
  var url = '/widgetController.dobbb?op=updateWindowPreference';
  var prefVal = newVisibility == 'true' ? 'max' : 'min'
  var params = 'prefKey=' + columnId + '&prefVal=' + prefVal;
  gColumnId = columnId;
  gUserId = userId;
  gTagViewMode = tagViewMode;
  ajaxRequest( url, params, toggleColumnVisibility );
}
function executePanelLoader( columnId, userId, tagViewMode, async )
{
  var paramMap = new Object();
  paramMap['user_id'] = userId;
  paramMap['tagViewMode'] = tagViewMode;
  var loaderFunction = gPanelFunctionLoaders[columnId];
  //alert('executePanelLoader. col=' + columnId + ', func' + loaderFunction );
  loaderFunction( paramMap, async );
}
function nopremNotificationPanel( paramMap, async )
{
  loadNotificationWidget( 'palette_notification_collapsible', checkForNewNotificationsCount, async );
}
function nopremTagCloudPanel( paramMap, async )
{
  showTagCloud( 'palette_tagcloud_collapsible', paramMap['tagViewMode'], 'true', paramMap['user_id'], null, async );
}
function nopremProfilePanel( paramMap, async )
{
  //do nothing, it's not an ajax call
}
function nopremNetworkPanel( paramMap, async )
{
  loadNetworkWidget( paramMap['user_id'], 'palette_network_collapsible', null, async );
}
function toggleColumnVisibility()
{
  var thePal = document.getElementById( 'palette_' + gColumnId + '_collapsible' );
  var theImg = document.getElementById( 'palette_' + gColumnId + '_img' );
  if( thePal.style.display == 'block' || thePal.style.display == '' || thePal.style.display == 'undefined' )
  {
    thePal.style.display = 'none';
    theImg.src = '/images/palette_expand.gif';
  }
  else
  {
    var needToLoad = $( gColumnId + '_needs_loading' );
    //alert('need to load?' + needToLoad + ' from ' + gColumnId + '_needs_loading')
    if( needToLoad )
    {
      executePanelLoader( gColumnId, gUserId, gTagViewMode, true );
    }
    thePal.style.display = 'block';
    theImg.src = '/images/palette_contract.gif';
  }
}
//take the count div and move it into the header 
function checkForNewNotificationsCount()
{
  var countDiv = $( 'newNotificationsCount' );
  //alert(' found new notificationz div: ' + countDiv )
  if( countDiv )
  {
    var newContainer = $( 'notificationHeaderContainer' );
    newContainer.appendChild( countDiv );
  }
}
