function LoocosSite( )
{
  this.readyHandlers_ = new Array();
  this.args_ = this.parseUrlArgs_();
  this.parseNodeName_();
}

LoocosSite.instance = null;

LoocosSite.getInstance = function()
{
  if ( LoocosSite.instance == null ){
    LoocosSite.instance = new LoocosSite();
  }
  return LoocosSite.instance;
}

LoocosSite.prototype.addReadyHandler = function( f )
{
  this.readyHandlers_.push( f );
}

LoocosSite.prototype.callReadyHandlers = function()
{
  var a = this.readyHandlers_;
  for ( var i = 0; i < a.length; i++ ){
    var func = a[i];
    if ( typeof func == 'function' )
      func();
  }
}

LoocosSite.prototype.parseUrlArgs_ = function()
{
  var args = {};
  var q = location.search.substring( 1 );
  var items = q.split( '&' );
  for ( var i = 0; i < items.length; i++ ){
    var item = items[i];
    var eqpos = item.indexOf( '=' );
    if ( eqpos == -1 )
      continue;
    var name = item.substring( 0, eqpos );
    args[name] = decodeURIComponent( item.substring( eqpos + 1 ) );
  }
  return args;
}

LoocosSite.prototype.parseNodeName_ = function()
{
  var args = {};
  var p = location.pathname.substring( 1 );
  var items = p.split( '/' );
  var op = items[0];
  var node = items[1];
  if ( op == 'n' && node ){
    this.args_['n'] = decodeURIComponent( node );
  }
}

LoocosSite.prototype.getUrlArg = function( name )
{
  return this.args_[name];
}

LoocosSite.prototype.JXError = function( data )
{
  var html = '<div id="jxerror"><div class="head">JX error</div><div class="msg">' +
    '<img src="/images/alert.png">' +
    data['message'] + '<div class="ok">Click here to continue</div>' + '</div></div>' + 
    '<div id="blockdisplay"></div>';
  $( html ).appendTo('body');
  $( '#jxerror' ).css( 'display', 'block' );
  $( '#blockdisplay' ).css( 'display', 'block' );
  $( '#jxerror' ).click( function( event ) {
    $(this).css( 'display', 'none' );
    $( '#blockdisplay' ).css( 'display', 'none' );
  });
}

