﻿/**********************************************
* SIDEBAR SETTINGS
**********************************************/
function SidebarSettings() {
   this.visibleOnStart = false;
   this.height = 0;
   this.width = 200;
   this.sidebarLocation = "right";  /* left right */
   this.backgroundColor = "";
   this.headerHeight = 30;
   this.headerBackgroundColor = "rgb(0,0,255)";
   this.headerTextFont = "";
   this.headerTextStyle = "";
   this.headerTextSize = "8pt";
   this.headerTextWeight = "bold";
   this.headerTextColor = "Black";
   this.headerTextLeft = 20;
   this.headerTextTop = 7;
   this.closeImage = "";
   this.closeImageHeight = 21;
   this.closeImageWidth = 21;
   this.closeImageRightPadding = 5;
   this.tabTop = 40;
   this.tabHeight = 100;
   this.tabWidth = 25;
   this.tabSpacing = 0;
   this.tabBackgroundColor = "";
   this.contentPaddingTop = 0;
   this.contentPaddingBottom = 0;
   this.contentPaddingLeft = 0;
   this.contentPaddingRight = 0;
   this.fixedToolbar = false;
   this.toolbarHeight = 0;
   this.toolbarLocation = "top"; /* top, bottom, left right */
}
/**********************************************
* SIDEBAR
**********************************************/
function Sidebar(fbReference) {
   this.flippingBook = fbReference;
   /* SETTINGS */
   this.settings = new SidebarSettings();
   /* ITEMS */
   this.Items = new Array();
   /* METHODS */
   this.iterateItems = function(callback, extra) {
      for (var key in this.Items) {
         if (key == "length")
            continue;
         callback(this.Items[key], extra);
      }
   };
   this.addItem = function(item) {
      this.Items[item.name] = item;
      if (this.Items.length)
         this.Items.length++;
      else
         this.Items.length = 1;
      item.sidebar = this;
   };
   this.show = function(sidebarItemName) {
      this.element.style.display = "";
   };
   this.hide = function(sidebarItemName) {
      if (!this.selectedItem)
         return;
      this.selectedItem.hide();
      this.selectedItem = null;
      this.tabs.deselectAll();
      this.element.style.display = "none";
      this.redraw();
   };
   this.select = function(sidebarItemName) {
      if (this.selectedItem && this.selectedItem.name == sidebarItemName)
         return;
      if (this.selectedItem)
         this.selectedItem.hide();
      this.selectedItem = this.Items[sidebarItemName];
      this.header.setText(this.selectedItem.headerText);
      this.tabs.select(sidebarItemName);
      this.selectedItem.show();
      this.show();
      this.redraw();
   };
   this.visible = function(sidebarItemName) {
      if (!sidebarItemName)
         return (this.element.style.display == "");
      return (false);
   };
   /* REDRAW */
   this.redraw = function() {
      var windowWidth = getWindowWidth();
      var windowHeight = getWindowHeight();
      this.element.style.height = GetSize(windowHeight);

      if (this.settings.sidebarLocation == "right")
         this.element.style.left = GetSize(windowWidth - this.element.offsetWidth);
      /* TABS */
      var tabLeft;
      switch (this.settings.sidebarLocation) {
         case "left":
            tabLeft = this.visible() ? this.settings.width + this.settings.tabWidth : 0;
            break;
         case "right":
            tabLeft = (this.visible() ? this.element.offsetLeft : windowWidth) - this.settings.tabWidth;
            break;
         default:
            break;
      }
      this.tabs.redraw(tabLeft, windowHeight);
      if (!this.visible())
         return;
      /* CONTENT */
      var contentHeight = this.element.offsetHeight - this.settings.headerHeight - this.settings.contentPaddingTop - this.settings.contentPaddingBottom;
      var contentWidth = this.element.offsetWidth - this.settings.contentPaddingLeft - this.settings.contentPaddingRight;
      if (contentHeight < 0)
         contentHeight = 0;
      if (contentWidth < 0)
         contentWidth = 0;
      this.content.style.marginTop = GetSize(this.settings.contentPaddingTop);
      this.content.style.marginLeft = GetSize(this.settings.contentPaddingLeft);
      this.content.style.height = GetSize(contentHeight);
      /* HEADER */
      this.header.redraw(this.settings.headerHeight, this.element.offsetWidth);
      /* SELECTED ITEM */
      if (this.selectedItem)
         this.selectedItem.redraw(contentHeight, contentWidth);
   };
   this.getItem = function(number) {
      var extra = { currentItem: 0, itemNumber: number, item: null };
      this.iterateItems(function(sidebarItem, extra) {
         if (extra.currentItem == number)
            extra.item = sidebarItem;
         extra.currentItem++;
      },
      extra);
      return (extra.item);
   };
   /* CONSTRUCTOR */
   this.create = function() {
      try {
         /* CONTAINER ELEMENT */
         this.element = document.createElement("div");
         document.body.appendChild(this.element);
         this.element.style.visibility = "hidden";
         this.element.style.backgroundColor = this.settings.backgroundColor;
         this.element.style.position = "absolute";
         this.element.style.width = GetSize(this.settings.width + this.settings.tabWidth);
         this.element.style.height = (this.settings.height ? GetSize(this.settings.height) : "");
         this.element.style.left = "0px";
         this.element.style.top = "0px";
         this.element.style.overflow = "hidden";
         this.element.style.zIndex = "90000";
         /* TABS */
         this.tabs = new SidebarTabContainer(this);
         /* HEADER ELEMENT */
         this.header = new SidebarItemHeader(this);
         /* CONTENT ELEMENT */
         this.content = document.createElement("div");
         this.element.appendChild(this.content);
         this.content.style.overflow = "hidden";
         /* CREATE THE SIDEBAR ITEMS */
         this.iterateItems(function(item) {
            item.create();
            item.sidebar.content.appendChild(item.element);
         });
         this.selectedItem = null;
         this.element.style.visibility = "visible";
         if (this.settings.visibleOnStart)
            this.element.style.display = "";
         else
            this.element.style.display = "none";

         if (this.Items.length > 0 && this.visible())
            this.select(this.getItem(0).name);
      }
      catch (e) {
         window.alert("ERROR Sidebar.create(): " + e.message);
      }
   };
}
/**********************************************
* SIDEBAR ITEM HEADER
**********************************************/
function SidebarItemHeader(sidebar) {
   this.sidebar = sidebar;
   /* HEADER */
   this.element = document.createElement("div");
   this.sidebar.element.appendChild(this.element);
   this.element.style.position = "relative";
   this.element.style.height = GetSize(this.sidebar.settings.headerHeight);
   this.element.style.textAlign = "left";
   this.element.style.backgroundColor = this.sidebar.settings.headerBackgroundColor;
   this.headerTextElement = document.createElement("div");
   this.headerTextElement.style.position = "absolute";
   this.headerTextElement.style.cssFloat = "right";
   this.headerTextElement.style.marginLeft = GetSize(this.sidebar.settings.headerTextLeft);
   this.headerTextElement.style.marginTop = GetSize(this.sidebar.settings.headerTextTop);
   this.headerTextElement.style.fontFamily = this.sidebar.settings.headerTextFont;
   this.headerTextElement.style.fontStyle = this.sidebar.settings.headerTextStyle;
   this.headerTextElement.style.fontSize = this.sidebar.settings.headerTextSize;
   this.headerTextElement.style.color = this.sidebar.settings.headerTextColor;
   this.element.appendChild(this.headerTextElement);
   this.closeElement = document.createElement("div");
   this.closeElement.style.position = "absolute";
   this.closeClick = function(evt) {
      var target = GetTargetFromEvent(evt);
      var header = target.target.header;
      header.sidebar.hide();
      target.event.cancelBubble = true;
   };
   if (this.sidebar.settings.closeImage.length > 0) {
      var closeImage = document.createElement("img");
      closeImage.header = this;
      closeImage.style.cursor = "pointer";
      closeImage.style.paddingRight = "5px";
      closeImage.src = this.sidebar.settings.closeImage;
      closeImage.height = this.sidebar.settings.closeImageHeight;
      closeImage.style.height = GetSize(this.sidebar.settings.closeImageHeight);
      closeImage.width = this.sidebar.settings.closeImageWidth;
      closeImage.style.width = GetSize(this.sidebar.settings.closeImageWidth);
      closeImage.style.paddingRight = "5px";
      closeImage.onclick = this.closeClick;
      this.closeElement.appendChild(closeImage);
   }
   else {
      var anchor = document.createElement("a");
      anchor.header = this;
      anchor.style.color = "Black";
      anchor.appendChild(document.createTextNode("close"));
      anchor.href = "javascript: void(0);";
      anchor.onclick = this.closeClick;
      this.closeElement.appendChild(anchor);
   }
   this.element.appendChild(this.closeElement);
   this.closeElement.style.top = "5px";
   /* METHODS */
   this.setText = function(text) {
      this.headerTextElement.innerHTML = text;
   };
   this.getText = function() {
      return (this.headerTextElement.innerHTML);
   };
   this.redraw = function(height, width) {
      this.element.style.height = GetSize(height);
      this.element.style.width = GetSize(width);
      this.closeElement.style.left = GetSize(width - this.closeElement.offsetWidth);
   };
}
/**********************************************
* TAB CONTAINER
**********************************************/
function SidebarTabContainer(sidebar) {
   this.sidebar = sidebar;
   this.tabs = new Array();
   this.element = document.createElement("div");
   document.body.appendChild(this.element);
   this.element.style.position = "absolute";
   this.element.style.backgroundColor = this.sidebar.settings.tabBackgroundColor;
   this.element.style.zIndex = this.sidebar.element.style.zIndex;
   this.element.style.width = GetSize(this.sidebar.settings.tabWidth);
   /* ADD THE TABS */
   this.sidebar.iterateItems(function(item, tabContainer) {
      tabContainer.tabs[tabContainer.tabs.length] = new SidebarTab(tabContainer, item);
   }, this);
   /* REDRAW */
   this.redraw = function(left, height) {
      this.element.style.left = GetSize(left);
      this.element.style.height = GetSize(height);
   };
   /* METHODS */
   this.select = function(itemName) {
      for (var i = 0; i < this.tabs.length; i++) {
         var tab = this.tabs[i];
         if (tab.sidebarItem.name == itemName)
            tab.select();
         else
            tab.deselect();
      }
   };
   this.deselectAll = function() {
      for (var i = 0; i < this.tabs.length; i++)
         this.tabs[i].deselect();
   };
}
/**********************************************
* TAB
**********************************************/
function SidebarTab(tabContainer, sidebarItem) {
   this.container = tabContainer;
   this.sidebarItem = sidebarItem;
   this.sidebar = sidebarItem.sidebar;
   /* ELEMENT */
   this.element = document.createElement("div");
   this.container.element.appendChild(this.element);
   this.element.style.height = GetSize(this.sidebar.settings.tabHeight);
   this.element.style.width = GetSize(this.sidebar.settings.tabWidth);
   this.element.style.marginTop = GetSize(this.sidebar.settings.tabSpacing);
   this.element.style.cursor = "pointer";
   this.element.tab = this;
   this.element.onclick = function(evt) {
      var target = GetTargetFromEvent(evt);
      var element = target.target;
      try {
         var tab = element.tab;
         tab.sidebar.select(tab.sidebarItem.name);
      }
      catch (error) {
         window.alert("SidebarTab.onclick: " + error.message);
      }
      target.event.cancelBubble = true;
   };
   /* TAB IMAGE */
   this.tabImage = document.createElement("img");
   this.element.appendChild(this.tabImage);
   this.tabImage.tab = this;
   this.tabImage.src = this.sidebarItem.tabImage;
   this.tabImage.height = this.sidebar.settings.tabHeight;
   this.tabImage.width = this.sidebar.settings.tabWidth;
   this.tabImage.style.cursor = "pointer";
   this.tabImage.onclick = this.element.onclick;
   /* SELECTED TAB IMAGE */
   this.tabSelectedImage = document.createElement("img");
   this.tabSelectedImage.style.display = "none";
   this.element.appendChild(this.tabSelectedImage);
   this.tabSelectedImage.tab = this;
   this.tabSelectedImage.src = this.sidebarItem.tabSelectedImage;
   this.tabSelectedImage.height = this.sidebar.settings.tabHeight;
   this.tabSelectedImage.width = this.sidebar.settings.tabWidth;
   this.tabSelectedImage.style.cursor = "pointer";
   /* METHODS */
   this.select = function() {
      this.tabSelectedImage.style.display = "";
      this.tabImage.style.display = "none";
   };
   this.deselect = function() {
      this.tabImage.style.display = "";
      this.tabSelectedImage.style.display = "none";
   };
}
/**********************************************
* SIDEBAR ITEM
**********************************************/
function SidebarItem(name, headerText, tabImage, tabSelectedImage, content) {
   /* MEMBER INITIALIZATION */
   this.sidebar = null;
   this.name = name;
   this.headerText = headerText ? headerText : name;
   this.contentPadding = { left: 0, right: 0, top: 0, bottom: 0 };
   this.tabImage = tabImage;
   this.tabSelectedImage = tabSelectedImage;
   if (content)
      this.setContent(content);
}
/* CREATE */
SidebarItem.prototype.create = function() {
   try {
      /* CONTAINER */
      this.element = document.createElement("center");
      this.element.style.position = "absolute";
      this.element.style.display = "none";
      /* CONTENT */
      /* USER DEFINED CONTENT */
      if (this._cobj) {
         this._cobj.create(this);
      }
      this.hide();
   }
   catch (e) {
      window.alert(e.message);
   }
};
/* REDRAW */
SidebarItem.prototype.redraw = function(height, width) {
   this.element.style.height = GetSize(height);
   this.element.style.width = GetSize(width);
   if (this._cobj && this._cobj.redraw) {
      this._cobj.redraw(height, width);
   }
};
/* METHODS */
SidebarItem.prototype.setContent = function(obj) {
   if (!obj.create) {
      window.alert("SidebarItem.setContent: create() not defined for obj");
      return;
   }
   if (!obj.create) {
      window.alert("SidebarItem.setContent: redraw() not defined for obj");
      return;
   }
   this._cobj = obj;
};
SidebarItem.prototype.visible = function() {
   return (!(this.element.style.display == "none"));
};
SidebarItem.prototype.show = function() {
   this.element.style.display = "";
};
SidebarItem.prototype.hide = function() {
   this.element.style.display = "none";
};
/**********************************************
* THUMBNAIL CONTAINER
thumbs = [{imgUrl, pageNumber, description}]
**********************************************/
function SidebarThumbnailContainerSettings() {
   this.height = 200;
   this.imageDir = "pages/thumbs";
   this.imageHeight = 50;
   this.imageWidth = 50;
   this.imagePaddingTop = 0;
   this.imagePaddingLeft = 0;
   this.imagePaddingRight = 0;
   this.imagePaddingBottom = 0;
   this.paddingTop = 0;
   this.paddingLeft = 0;
   this.paddingRight = 0;
   this.paddingBottom = 0;
   this.selectedBorderColor = "Red";
   this.selectedBorderWidth = 5;
   this.selectedBorderStyle = "solid";
   this.fontFamily = "";
   this.fontSize = "8pt";
   this.fontWeight = "bold";
   this.fontColor = "White";
   this.thumbnailSpacing = 5;
   this.descriptionHeight = "";
   this.descriptionWidth = "";
   this.descriptionPadding = "";
}
function SidebarThumbnailContainer(thumbPropertiesArr, settings) {
   if (thumbPropertiesArr)
      this.thumbProperties = thumbPropertiesArr;
   else
      this.thumbProperties = new Array();
   if (settings)
      this.settings = settings;
   else
      this.settings = new SidebarThumbnailContainerSettings();
   this.thumbs = new Array();
   /* CREATE */
   this.create = function(sidebarItem) {
      this.sidebarItem = sidebarItem;
      this.element = document.createElement("center");
      this.element.style.overflowX = "hidden";
      this.element.style.overflowY = "auto";
      this.container = sidebarItem.element;
      this.container.appendChild(this.element);
      this.settings.selectedThumbnailHeight = this.settings.imageHeight - ((this.settings.selectedBorderWidth * 2) + (this.settings.paddingLeft + this.settings.paddingRight));
      this.settings.selectedThumbnailWidth = this.settings.imageWidth - ((this.settings.selectedBorderWidth * 2) + (this.settings.paddingTop + this.settings.paddingBottom));

      if (this.thumbProperties) {
         this.thumbProperties.sort(function(a, b) {
            return (a.pageNumber - b.pageNumber);
         });
         /* CREATE THUMBNAILS */
         for (var i = 0; i < this.thumbProperties.length; i++) {
            this.addThumbnail(this.thumbProperties[i]);
         }
      }
   };
   /* EVENTS */
   this.OnLayoutThumbnailDescription = null;
   /* METHODS */
   this.addThumbnail = function(properties) {
      var thumbnail = new SidebarThumbnail(properties);
      thumbnail.create(this);
         this.element.appendChild(thumbnail.element);
      this.thumbs[thumbnail.properties.pageNumber] = thumbnail;
      /* RAISE THE DESCRIPTION LAYOUT EVENT */
      if (this.OnLayoutThumbnailDescription)
         this.OnLayoutThumbnailDescription("add", thumbnail.description);
   };
   this.removeThumbnail = function(thumbnail) {
      this.element.removeChild(thumbnail.element);
      this.thumbs[thumbnail.properties.pageNumber] = null;
      if (this.OnLayoutThumbnailDescription)
         this.OnLayoutThumbnailDescription("remove", thumbnail.description);
   };
   this.deselectAll = function() {
      for (var key in this.thumbs) {
         if (!this.thumbs[key])
            continue;
         this.thumbs[key].deselect();
      }
   };
   this.getThumbnail = function(pageNumber) {
      if (!pageNumber)
         return (null);
      return (this.thumbs[pageNumber]);
   };
   /* EVENT HANDLERS */
   this.redraw = function(containerHeight, containerWidth) {
   this.element.style.height = GetSize(containerHeight);
   this.element.style.width = GetSize(containerWidth);
   };
   this.OnThumbnailClicked = null;
   this.ThumbnailClickedHandler = function(evt) {
      var thumbnail = this.thumbnail;
      if (thumbnail.container && thumbnail.container.OnThumbnailClicked) {
         thumbnail.container.OnThumbnailClicked(thumbnail);
      }
   };
}
/* SIDEBAR THUMBNAIL */
function SidebarThumbnail(properties) {
   this.thumbnailContainer = null;
   this.properties = properties;
   /* CONSTRUCTOR */
   this.create = function(container) {
      this.container = container;
      this.settings = this.container.settings;
      /* ELEMENT */
   this.element = document.createElement("div");
      this.element.style.height = GetSize(this.settings.height);
      this.element.style.overflow = "hidden";
      this.element.style.marginBottom = (this.settings.thumbnailSpacing);
      /* IMAGE */
      this.imageContainer = document.createElement("div");
      this.element.appendChild(this.imageContainer);
   this.image = document.createElement("img");
   this.image.thumbnail = this;
      this.image.src = this.settings.imageDir + "/" + properties.imageUrl;
      this.image.alt = (properties.description && properties.description.length > 0) ? properties.description : "Page " + properties.pageNumber;
      this.imageContainer.appendChild(this.image);
      this.imageContainer.style.width = GetSize(this.settings.imageWidth);
      this.imageContainer.style.height = GetSize(this.settings.imageHeight);
      this.imageContainer.style.paddingTop = GetSize(this.settings.imagePaddingTop);
      this.imageContainer.style.paddingLeft = GetSize(this.settings.imagePaddingLeft);
      this.imageContainer.style.paddingRight = GetSize(this.settings.imagePaddingRight);
      this.imageContainer.style.paddingBottom = GetSize(this.settings.imagePaddingBottom);
      this.imageContainer.style.paddingBottom = GetSize(this.settings.imagePaddingBottom);
      this.imageContainer.style.borderColor = "Transparent";
      this.imageContainer.style.borderStyle = this.settings.selectedBorderStyle;
      this.imageContainer.style.borderWidth = this.settings.selectedBorderWidth;
      this.image.height = this.settings.imageHeight;
      this.image.width = this.settings.imageWidth;
      this.image.style.height = GetSize(this.settings.imageHeight);
      this.image.style.width = GetSize(this.settings.imageWidth);
   this.image.style.cursor = "pointer";
   /* IMAGE CLICK HANDLER */
      this.image.onclick = this.container.ThumbnailClickedHandler;
      this.description = document.createElement("div");
      this.description.thumbnail = this;
      this.description.style.height = GetSize(this.settings.descriptionHeight);
      this.description.style.width = GetSize(this.settings.imageWidth);
      var descPadding = GetSize(this.settings.descriptionPadding);
      this.description.style.paddingTop = descPadding;
      this.description.style.paddingLeft = descPadding;
      this.description.style.paddingRight = descPadding;
      this.description.style.paddingBottom = descPadding;
      this.description.style.fontFamily = this.settings.fontFamily;
      this.description.style.fontSize = this.settings.fontSize;
      this.description.style.color = this.settings.fontColor;
      this.description.style.overflow = "hidden";
      this.element.appendChild(this.description);
      /* If the description is given in properties, set it */
      if (this.properties.description.length > 0) {
         this.description.content = document.createElement("span");
         this.description.content.appendChild(document.createTextNode(properties.description));
         this.description.appendChild(this.description.content);
      }
   };
   this.select = function() {
      /*this.element.style.borderColor = this.settings.selectedBorderColor;
      this.element.style.borderStyle = this.settings.selectedBorderStyle;
      this.element.style.borderWidth = this.settings.selectedBorderWidth;*/
      this.imageContainer.style.borderColor = this.settings.selectedBorderColor;
   };
   this.deselect = function() {
      //this.element.style.borderColor = "Transparent";
      this.imageContainer.style.borderColor = "Transparent";
   };
}
/* BOOKMARK THUMBNAIL CONTAINER */
function SidebarBookmarkThumbnailSettings() {
   this.deleteImage = "img/close2.gif";
}
function SidebarBookmarkThumbnailContainer(indexContainer, bookmarks, settings) {
   this.index = indexContainer;
   if (bookmarks)
      this.thumbProperties = bookmarks;
   if (settings)
      this.settings = settings;
   this.thumbnailSettings = new SidebarBookmarkThumbnailSettings();
}
SidebarBookmarkThumbnailContainer.prototype = new SidebarThumbnailContainer();
SidebarBookmarkThumbnailContainer.prototype.SaveBookmarks = function() {
   var newBookmarks = "";
   var Expires = new Date();
   Expires.setTime(Expires.getTime() + (365 * 24 * 60 * 60 * 1000));
   for (var key in this.thumbs) {
      if (this.thumbs[key]) {
         newBookmarks = newBookmarks + (newBookmarks.length > 0 ? bms : "") + key;
      }
   }
   SetCookie(bmk, newBookmarks, Expires, "", "");
};
SidebarBookmarkThumbnailContainer.prototype.OnFlipPage = null;
SidebarBookmarkThumbnailContainer.prototype.OnThumbnailClicked = null;
SidebarBookmarkThumbnailContainer.prototype.OnLayoutThumbnailDescription = function(action, container) {
   switch (action) {
      case "add":
         if (container.content) {
            container.removeChild(container.content);
         }

         container.de = document.createElement("div");
         container.appendChild(container.de);
         container.de.style.position = "relative";

         var description = document.createElement("div");
         description.style.cssFloat = "left";
         description.style.overflow = "hidden";
         description.appendChild(document.createTextNode(container.thumbnail.properties.description));
         container.de.appendChild(description);

         var imageContainer = document.createElement("div");
         imageContainer.style.position = "absolute";
         imageContainer.style.top = "0px";
         imageContainer.style.left = GetSize(container.thumbnail.settings.descriptionWidth - 15);
         imageContainer.style.height = GetSize(15);
         imageContainer.style.width = GetSize(15);
         container.de.appendChild(imageContainer);
         var image = document.createElement("img");
         imageContainer.appendChild(image);
         image.src = this.thumbnailSettings.deleteImage;
         image.alt = "delete bookmark";
         image.style.height = GetSize(15);
         image.style.width = GetSize(15);
         image.style.cursor = "pointer";
         image.style.cssFloat = "left";
         image.style.marginTop = "2px";
         image.thumbnail = container.thumbnail;
         image.onclick = function(evt) {
            var target = GetTargetFromEvent(evt);
            var thumbnail = target.target.thumbnail;
            thumbnail.container.removeThumbnail(thumbnail);
            thumbnail.container.SaveBookmarks();
         };
         break;
      case "remove":
         container.removeChild(container.de);
         break;
      default:
         break;
   }
};
SidebarBookmarkThumbnailContainer.prototype.BookmarkPage = function() {
   var saveBookmarks = false;

   if (this.currentPageLeft) {
      if (!this.getThumbnail(this.currentPageLeft)) {
         saveBookmarks = true;
         this.addThumbnail(this.index.getThumbnail(this.currentPageLeft).properties);
         this.getThumbnail(this.currentPageLeft).select();
      }
   }
   if (this.currentPageRight) {
      if (!this.getThumbnail(this.currentPageRight)) {
         saveBookmarks = true;
         this.addThumbnail(this.index.getThumbnail(this.currentPageRight).properties);
         this.getThumbnail(this.currentPageRight).select();
      }
   }

   this.sidebarItem.sidebar.select("bookmarks");
   if (saveBookmarks) {
      this.SaveBookmarks();
   }
};

function GetBookmarks() {
   var bookmarks = GetCookie(bmk);
   if (bookmarks && bookmarks.length > 0)
      return (bookmarks.split(bms));
   return (null);
};
/* MISC */
function GetTargetFromEvent(evt) {
   var target = null;
   if (!evt)
      evt = window.event;
   if (evt && evt.srcElement)
      target = evt.srcElement;
   if (evt && evt.target)
      target = evt.target;
   return ({ target: target, event: evt });
}
function GetSize(size) {
   if (typeof (size) == "number")
      return (size + "px");
   return (size);
}
