var windowHeight=0;
var windowWidth=0;
var marginRight=40;
var marginBottom=40;


  function FullScreenPreview(wURL)
  {var wnd = window.open(wURL, '', 'WIDTH=300,HEIGHT=150,scrollbars,resizable');
   with (wnd.document)
   {open();
    write("\n   <body style='background-color: black;'>");
    write("\n    <script type='text/javascript'>");
    write("\n     var offset = (navigator.userAgent.indexOf('Mac') != -1 || ");
    write("\n                   navigator.userAgent.indexOf('Gecko') != -1 || ");
    write("\n		   navigator.appName.indexOf('Netscape') != -1) ? 0 : 4;");
    write("\n     window.moveTo(-offset, -offset);");
    write("\n     window.resizeTo(screen.availWidth + (2 * offset), screen.availHeight + (2 * offset));");
    write("\n     window.location.href='" + wURL + "&screen=" + screen.availWidth + "x" + screen.availHeight + "'");
    write("\n    <\/script>");
    write("\n    <\/body>");
    close();
   }
  }


function ResizeToContents()
 {GetPageWidth(document.body);
  GetPageHeight(document.body);

  windowHeight+=marginBottom;
  windowWidth+=marginRight;

  var visibleDocumentSize=GetVisibleDocumentSize();
  var windowDeltaX=windowDeltaY=0;
  windowDeltaY=windowHeight-visibleDocumentSize['height'];
  windowDeltaX=windowWidth-visibleDocumentSize['width'];


  if (screen.availHeight<windowHeight) windowHeight=screen.availHeight;
  if (screen.availWidth<windowWidth) windowWidth=screen.availWidth;

  if (((visibleDocumentSize['height'] + windowDeltaY) > screen.availHeight) ||
      ((visibleDocumentSize['width'] + windowDeltaX) > screen.availWidth))
  {var offset = (navigator.userAgent.indexOf("Mac") != -1 || 
                 navigator.userAgent.indexOf("Gecko") != -1 || 
		 navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
   window.moveTo(-offset, -offset);
   window.resizeTo(screen.availWidth + (2 * offset), screen.availHeight + (2 * offset));
   return;
  }

 
  window.moveTo((screen.availWidth-windowWidth)/2, (screen.availHeight-windowHeight)/2);
  window.resizeBy(windowDeltaX, windowDeltaY);
  return;
 }



function GetVisibleDocumentSize() 
{var visibleDocumentSize=new Array();
 if (typeof( window.innerWidth ) == 'number') 
 {//Non-IE
  visibleDocumentSize['width']=window.innerWidth;
  visibleDocumentSize['height']=window.innerHeight;
 } 
 else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight) ) 
       {//IE 6+ in 'standards compliant mode'
	visibleDocumentSize['width']=document.documentElement.clientWidth;
	visibleDocumentSize['height']=document.documentElement.clientHeight;
       } 
       else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
             {//IE 4 compatible
	      visibleDocumentSize['width']=document.body.clientWidth;
	      visibleDocumentSize['height']=document.body.clientHeight;
	     }

 return visibleDocumentSize;
}




function GetPageHeight(element)
{for (var i=0; i < element.childNodes.length; i++)
  if (element.childNodes[i].nodeType==1) GetPageHeight(element.childNodes[i]);

 var height=GetElementHeight(element)+GetElementTop(element);
 if (height>windowHeight) windowHeight=height;
}



function GetPageWidth(element)
{for (var i=0; i < element.childNodes.length; i++)
  if (element.childNodes[i].nodeType==1) GetPageWidth(element.childNodes[i]);

 var width=GetElementWidth(element)+GetElementLeft(element);
 if (width>windowWidth) windowWidth=width;
}



function GetElementHeight(element)
{return element.offsetHeight;}


function GetElementWidth(element)
{return element.offsetWidth;}



function GetElementLeft(eElement)
 {if (!eElement && this)
   eElement = this;

  var DL_bIE = document.all ? true : false;
  var nLeftPos = eElement.offsetLeft;
  var eParElement = eElement.offsetParent;

  while (eParElement != null)                 
   {if(DL_bIE)
     if(eParElement.tagName == "TD")
       nLeftPos += eParElement.clientLeft;

     nLeftPos += eParElement.offsetLeft;
     eParElement = eParElement.offsetParent;
   }
  return nLeftPos;
 }
    


function GetElementTop(eElement)
 {if (!eElement && this)
  eElement = this;

  var DL_bIE = document.all ? true : false;
  var nTopPos = eElement.offsetTop;
  var eParElement = eElement.offsetParent;

  while (eParElement != null)                 
   {if(DL_bIE)
     if(eParElement.tagName == "TD")
      nTopPos += eParElement.clientTop;
 
    nTopPos += eParElement.offsetTop;
    eParElement = eParElement.offsetParent;
   }
  return nTopPos;
 }


function OpenEditor(URL)
{window.open(URL, '', 'WIDTH=300,HEIGHT=150,scrollbars,resizable');
 return false;
}


function setBackground(bg)					  
{document.getElementById('photo-td').style.backgroundColor=bg;}
