/* Copyright (c) 2007, Bureau van Dijk Electronic Publishing. All rights reserved. */


// Function to allow one JavaScript file to be included by another.
// Copyright (C) 2006 www.cryer.co.uk

var SBOJSHost = "http://missingmanuals.com/widget_safari/widgetDistrib/";
function includeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>'); 
}
includeJavaScript(SBOJSHost + 'ajax.js');
includeJavaScript(SBOJSHost + 'panel.js');
includeJavaScript(SBOJSHost + 'bookOverview.js');
includeJavaScript(SBOJSHost + 'format.js');
includeJavaScript(SBOJSHost + 'search.js');
includeJavaScript(SBOJSHost + 'utils.js');
includeJavaScript(SBOJSHost + 'viewer.js');


//
// SBO namespace
//

var SBO = new function()
{
  //
  // method SBO.Extend
  //

  this.Extend = function(sub, base) 
  {
     function inst() {}
     inst.prototype = base.prototype;
     sub.prototype = new inst();
     sub.prototype.constructor = sub;
  }

}


//
// SBO.Config namespace
//


SBO.Config = new function()
{
  //
  // SBO.Config properties
  //
  
  this.Host = null;
  this.Url = null;
  
  this.XmlApi = null;

  //
  // method SBO.Config.Init
  //
  
  this.Init = function()
  {
  /*  A partner/customer using this will be passing in a src param to the SBO script.
   *  This src param will be used to determine the location of the css file. If the
   *  widget source is part of the portal, then the LocalUrl will be the same as the 
   *  Host url. But if the widget code is external to a portal, the Host param must be
   *  modified below. In addition, if a uicode is needed, it must be specified below
   *  in the this.UICode variable.
   *
   *  this.Host - the server against which the safari searches are made
   *             and is used in the links to safari
   *  this.Url - the safari host and path that can be used to find the images. If
   *             local images are to be used, LocalUrl should be used in those specific places
   *  this.LocalUrl - the host and path on the local server where the .js file is found.
   *                This is used just to find the local stylesheet and possibly images
   *  this.XmlApi - identifies the xmlapi host and several search params to which the
   *                other query params will be added
   *  this.UICode - identifies the uicode of the acct if relevant. This is needed to 
   *                properly construct the links to "Read on Safari".
   */ 
    var sbo = document.getElementById("SBO");
    var url = sbo ? sbo.src : "";
    // if no src param was specified in the script, this is the default
    if(url.indexOf("http") != 0)
    {
    
      this.Host = "http://safari5.bvdep.com";
      this.Url = this.Host + "/SBO/";
    }
    // a src was passed; this must be the case for a partner customization
    else
    {
      var hostIdx = url.indexOf("//") + 2;
        
      var pathIdx = url.indexOf("/", hostIdx);
      var fullPathIdx = url.lastIndexOf("/");
      this.LocalUrl = url.slice(0, fullPathIdx);
      /*cmh since the host of the SBO.js is passed in as the src and it is local,
           this line identifies the safari host against which the searches will be done 
           and the safari host for the links to safari
           The Url is used for finding images and other files on the safari server
      */
      this.Host = "http://safari.oreilly.com";
      this.UICode = "";
      this.Url = this.Host + "/SBO";
    }
    this.XmlApi = this.Host + "/xmlapi?Date=" + new Date().valueOf() + "&output=js&displaygrbooks=1&htmldescription=1&authors=1";
    
    var ua = navigator.userAgent;
    
    this.IsIE6 = ua && ua.indexOf("MSIE 6.0") > 0;
  }
  
  this.Init();
}




	

