var BaynoteRecBuilder = {
  baynote_title: "",
  baynote_insertbefore: "",
  baynote_display: "",
  baynote_thumb: "",
  baynote_count:"",
  baynote_stylesheet:"",
  containerId:"",
  interal: "true",

  init: function(baynote_title, baynote_insertbefore, baynote_display, baynote_thumb, baynote_count, containerId) {
    this.baynote_title = baynote_title;
    this.baynote_insertbefore = baynote_insertbefore;
    this.baynote_display = baynote_display;
    this.baynote_thumb = baynote_thumb;
    this.baynote_count = baynote_count;
    this.containerId = containerId;

    var baynoteDisplay = $("baynoteContainer");
    if(baynoteDisplay == null) return;

    this.setBaynoteStyleSheet();

  },

  moveAndDisplayBaynoteRec: function() {
    if ($('nonbn-recommendation-header')) {
      // There is a header title bar for other recommendations.
      Element.remove($('nonbn-recommendation-header'));
    }

    /*
    *For OM if they require the vertical widget to be wider then design
    *Required in HTML Source for the container <div id="vertical_wide" name="270"></div>
    *
    */
    if (this.containerId == 'vertical_wide' && BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '7') {
        var newStyleLength = $('vertical_wide').getAttribute("name");
     	var baynoteChildNodes = $('bn_guidearea0').childNodes[1].childNodes;
     	for(var i=0; i < baynoteChildNodes.length; i++)  {
     		baynoteChildNodes[i].style.width = newStyleLength + "px";
     	}
    }


    $("baynoteBookCatTitle").innerHTML = this.baynote_title + ":";

    var baynoteRecomendations = $("bn_placeholder0");

    if(baynoteRecomendations == null) return;
    baynoteRecomendations.style.display = "none";

    var bayNoteRecs = $("bn_placeholder0");
    $("baynoteBookHintDisplay").appendChild(bayNoteRecs);


    var container = $(this.containerId);
    if(container != null) {
      if(this.baynote_insertbefore != "") {
        container.insertBefore($("baynoteContainer"), $(this.baynote_insertbefore));
      } else {
        container.appendChild($("baynoteContainer"));
      }

    }

    var isSafari = navigator.userAgent.indexOf('Safari');
    var isVersionThreeOrGreater = navigator.userAgent.indexOf('Version');

    if(isSafari == -1 || (isSafari != -1 && isVersionThreeOrGreater != -1 )) {
      setTimeout('Effect.SlideDown($("baynoteContainer"))', 300);
      setTimeout('Effect.Appear($("bn_placeholder0"), { duration: 2.0 })', 500);
    } else {
      $("baynoteContainer").style.display = "block";
      $("bn_placeholder0").style.display = "block";
    }
  },

  setBaynoteStyleSheet: function() {
    var stylesheet = "/docs/CSS/baynote/baynote-guide-";
    var rightStyleSheet = "";
    var css = ".css";

    switch(this.baynote_display) {
      case "vertical":
        rightStyleSheet = rightStyleSheet + "v";
        break;
      case "horizontal":
        rightStyleSheet = rightStyleSheet + "h";
        break;
    }

    switch(this.baynote_thumb) {
      case "large":
          rightStyleSheet = rightStyleSheet + "large";
      break;
      case "small":
          rightStyleSheet = rightStyleSheet + "small";
      break;
    }

    this.baynote_stylesheet = rightStyleSheet;


    if(rightStyleSheet == "hlarge") {

      if(this.baynote_count >= 4)
        $("baynoteContainer").style.height = "360px";


      if(this.baynote_count == 6 || this.baynote_count == 3)
        stylesheet += "3or6-";

    }


    if(rightStyleSheet == "hsmall") {

      if(this.baynote_count <= 4)
        $("baynoteContainer").style.height = "135px";

        if(typeof(PricingService) != "undefined") {
         $("baynoteContainer").style.height = "155px";
        }


      if(this.baynote_count == 4 || this.baynote_count == 8)
        stylesheet += "4or8-";

    }


    var sheetpath = stylesheet + this.baynote_stylesheet + css;


    this.getBaynoteStyleSheet(sheetpath);


  },

  getBaynoteStyleSheet: function(sheetpath) {
    var fileref = document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", sheetpath);

    document.getElementsByTagName("head")[0].appendChild(fileref);
  }
}
