﻿///////////////////////////////////////////////////////////////////////////////
//
//  wcoDocumentLibraryManager.js
//
// © 2007-2009 Wco iEnterprise Solutions Pty Ltd. ALL RIGHTS RESERVED.
// This file is licensed as part of the DataPortal 2.0 Managed Web Presence Solution, for details look here: http://www.wco.com.au
//
///////////////////////////////////////////////////////////////////////////////

//--------------------------------------------------------------------------------
HtmlDocumentObject = function(parentObject, index, parentElement, xhtmlDataNode) {
  this.parent = parentObject;
  this.index = index;
  this.name = 'document_' + this.index;
  this.title = xhtmlDataNode.childNodes[0].innerHTML;
  this.linkUrl = xhtmlDataNode.childNodes[1].innerHTML;
  
  var html = '<ul>';
  html += '<li>';
  html += this.title;
  html += '';
  html += '';
  html += '</li>';
  html += '</ul>';
  var newContent = document.createElement('DIV');
  newContent.id = 'newContent';
  newContent.innerHTML = html;
  newContent.style.display = 'none';
  this.rootElement = newContent.childNodes[0];
  parentElement.appendChild(this.rootElement);
  
  // and hook up the mouse events for the new document list item
  var linkElement = this.rootElement.childNodes[0];
  linkElement.onmouseover = positioning.createDelegate(this, this.onMouseOver);
  linkElement.onmouseout = positioning.createDelegate(this, this.onMouseOut);
  linkElement.onclick = positioning.createDelegate(this, this.onMouseUp);
}

HtmlDocumentObject.prototype = {
  onMouseOver: function(e) {
    var element;

    if (!e) var e = window.event;
    if (e.target) element = e.target;
    else if (e.srcElement) element = e.srcElement;
    if (element.nodeType == 3) element = element.parentNode;
    
    element.className = 'Over';
  },

  onMouseOut: function(e) {
    var element;

    if (!e) var e = window.event;
    if (e.target) element = e.target;
    else if (e.srcElement) element = e.srcElement;
    if (element.nodeType == 3) element = element.parentNode;

    element.className = '';
  },

  onMouseUp: function(e) {
    var element;

    if (!e) var e = window.event;
    if (e.target) element = e.target;
    else if (e.srcElement) element = e.srcElement;
    if (element.nodeType == 3) element = element.parentNode;
    
    element.className = '';
    window.open(this.linkUrl, '_blank');
  }

}

//--------------------------------------------------------------------------------
HtmlDocumentCollection = function(parentObject, parentElement, width, height) {
  this.parent = parentObject;
  
  //var html = '<div style="position:absolute; top:0px; left:0px; width:' + width + 'px; height:' + height + 'px; overflow:auto; scrollbar-base-color:#666; scrollbar-face-color:#444; scrollbar-arrow-color:#222; scrollbar-track-color:#333; scrollbar-highlight-color:#666; scrollbar-shadow-color:#666; scrollbar-darkshadow-color:#666; scrollbar-3dlight-color:#666;">';
  var html = '<div style="position:absolute; top:0px; left:0px; width:' + width + 'px; height:' + height + 'px; overflow:auto;">';
  html += '<p class="ContactDetails">Welcome to the <b>Contraceptive Services document library</b> where you can discover even more in-depth answers to your questions...</p>';
  html += '</div>';
  var newContent = document.createElement('DIV');
  newContent.id = 'newContent';
  newContent.innerHTML = html;
  newContent.style.display = 'none';
  this.rootElement = newContent.childNodes[0];
  parentElement.appendChild(this.rootElement);
  
  this.item = new Array();
}

HtmlDocumentCollection.prototype = {
  add: function(xhtmlDataNode) {
    // get the index of the new menu item object
    var index = this.item.length;
    
    // create the new menu item object
    this.item[index] = new HtmlDocumentObject(this.parent, index, this.rootElement, xhtmlDataNode);
  },
  
  init: function(xhtmlDataNode) {
    // retrieve each document from the collection and add it to the library manager
    for (var i=0; i<xhtmlDataNode.childNodes.length; i++) {
      for (var c=0; c<xhtmlDataNode.childNodes[i].childNodes.length; c++) {
        if (xhtmlDataNode.childNodes[i].childNodes[c].nodeType == 3) {
          var html = '<p class="ListHeading">' + xhtmlDataNode.childNodes[i].childNodes[c].nodeValue + '</p>';
          var newContent = document.createElement('DIV');
          newContent.id = 'newContent';
          newContent.innerHTML = html;
          newContent.style.display = 'none';
          this.rootElement.appendChild(newContent.childNodes[0]);
        }
        else {
          var docData = xhtmlDataNode.childNodes[i].childNodes[c];
          this.add(docData);
        }
      }
    }
  }
  
}