/**
 * TGD Epaper
 **/
tgdEPaperObject = function()
{
   var idFlashLayer = "TGD_epaperFlashLayer";
   var idFlashLayerOverlay = "TGD_epaperFlashLayerOverlay";
   var idFlashLayerInner = "TGD_epaperFlashLayerInner";
   var fl;
   var fo;
   var fi;
   var isInit = false;
   var isLoad = false;

   this.init = function()
   {
      fl = document.getElementById(idFlashLayer);
      fo = document.getElementById(idFlashLayerOverlay);
      fi = document.getElementById(idFlashLayerInner);
      if (!fi)
      {
         fi = document.createElement("div");
         fi.id = idFlashLayerInner;
         fi.style['backgroundColor'] = '#fff';
         fi.style['textAlign'] = 'center';
         fi.style['fontSize'] = '10px';
         fi.style['color'] = 'black';
         fi.style['border'] = '1px black solid';
         fi.style['padding'] = '4px';
         fi.style['width'] = '200px';
         fi.style['margin'] = '0 auto';
         fi.innerHTML = '<strong>This page requires FlashPlayer 9</strong><br/><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_adobe_flash_player.png" alt="Get Adobe Flash player" border="0"/></a><br/><a href="javascript:tgdEPaper.close();">close</a>';
      }
      if (!fl) {
         fl = document.createElement("div");
         fl.id = idFlashLayer;
         fl.style['zIndex'] = '1001';
         fl.style['position'] = 'absolute';
         fl.style['left'] = '25px';
         fl.style['top'] = '0px';
         fl.appendChild(fi);
      }
      if (!fo) {
         fo = document.createElement("div");
         fo.id = idFlashLayerOverlay;
         fo.style['zIndex'] = '1000';
         fo.style['position'] = 'fixed';
         fo.style['left'] = '0';
         fo.style['top'] = '0';
         fo.style['width'] = '100%';
         fo.style['height'] = '100%';
         fo.style['backgroundColor'] = '#333';
         fo.style['opacity'] = '0.5';
         if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
         {
            fo.style['filter'] = "Alpha(opacity=50)";
         }
         fo.onclick = closeEPaper;
      }
      isInit = true;
   };
   
   this.showFlashObjects = function()
   {
      var flashObjects = document.getElementsByTagName("object");
      for (i = 0; i < flashObjects.length; i++) {
         flashObjects[i].style.visibility = "visible";
      }
      var flashEmbeds = document.getElementsByTagName("embed");
      for (i = 0; i < flashEmbeds.length; i++) {
         flashEmbeds[i].style.visibility = "visible";
      }
   };
   
   this.close = function()
   {
      this.showFlashObjects();
      document.body.removeChild(fo);
      document.body.removeChild(fl);
   };
   
   this.hideFlashObjects = function()
   {
      var flashObjects = document.getElementsByTagName("object");
      for (i = 0; i < flashObjects.length; i++) {
         flashObjects[i].style.visibility = "hidden";
      }
      var flashEmbeds = document.getElementsByTagName("embed");
      for (i = 0; i < flashEmbeds.length; i++) {
         flashEmbeds[i].style.visibility = "hidden";
      }
   };
   
   this.load = function(xmlFile, xmlPath, policyFile, swfPath)
   {
      if (!isInit) this.init();
      if (isLoad) this.close();
      this.hideFlashObjects();
      if (!swfPath) swfPath = 'swf/';
      //if (!xmlPath) xmlPath = xmlFile.replace(/epaper.xml/, '');
      self.scrollTo(0,0);
      document.body.appendChild(fl);
      document.body.appendChild(fo);
      swfobject.embedSWF(
         swfPath + "ePaper.swf", idFlashLayerInner, "960", "780", "9.0.115", swfPath + "expressInstall.swf",
         {  policyFile: policyFile,
            xmlFile: xmlFile,
            baseHref: xmlPath,
            uiPath: "ePaper.controller.swf"
         }, {
            allowScriptAccess: "always",
            bgcolor: "#eeeeee",
            allowFullscreen: "true"
         },
         {
            id : idFlashLayerInner
         }
      );
   };
};

var tgdEPaper = new tgdEPaperObject();

function closeEPaper() {
   tgdEPaper.close();
}