var CurrentPhotoIndex;

function openPhoto( PhotoIndex, ServerPath )
{
   CurrentPhotoIndex = PhotoIndex;
   window.open( "/photo.html", "photowindow", "status=no,toolbar=no,location=no,menu=no,scrollbars=yes,resizable=yes" );
}

function ndeSetStyleSheet(newtitle) 
{
   // this function exists solely to 
   // distinguish when the user chooses a new
   // theme. IE does not properly reflow the page
   // when a new theme is chosen and we must force
   // a reload when IE users choose a new theme.
   
   ndeSetStyleSheetInternal(newtitle);
   /*
   if (navigator.userAgent.indexOf('MSIE') != -1 && 
      !window.opera && 
      navigator.product != 'Gecko')
   
   {
      history.go(0);
   }
   */
}

function ndeSetStyleSheetInternal(newtitle) 
{
   if (!document.getElementsByTagName)
   {
      return;
   }

   if( !document.getElementById("ChangeStyle") )
   {
      return;
   }
   
   var i;
   var savedtitle = '';
   var links = document.getElementsByTagName("link");

   if (!newtitle)
   {
      newtitle = savedtitle = ndeReadCookie("album-style", false);
   }

   if (!newtitle)
   {
      newtitle = "Echo";
   }
   
   var activesheet = null;
   for (i = 0; i < links.length; i++) 
   {
      var a = links[i];
      var rel = a.getAttribute('rel');
      var title = a.getAttribute('title');
      
      if (rel.indexOf("style") != -1 && title) 
      {
         a.disabled = true;
         if (title == newtitle) 
         {
           activesheet = a;
         }
      }
   }
   if (activesheet)
   {
      activesheet.disabled = false;
   }
   if (newtitle != savedtitle)
   {
      ndeCreateCookie("album-style", newtitle, 365, false);
   }
   document.getElementById("ChangeStyle").value = newtitle;
}

function ndeCreateCookie(name,value,days,useLang) 
{

  var langString = useLang ? ndeGetLang() : "";

  var cookie = name + langString + "=" + value + ";";

  if (days) 
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    cookie += " expires=" + date.toGMTString() + ";";
  }
  cookie += " path=/";

  document.cookie = cookie;
}

function ndeReadCookie(name, useLang) 
{

  var langString = useLang ? ndeGetLang() : "";

  var nameEQ = name + langString + "=";
  var ca = document.cookie.split(';');

  for(var i = 0; i < ca.length; i++) 
  {
    var c = ca[i];
    while (c.charAt(0) == ' ') 
    {
      c = c.substring(1, c.length);
    }

    if (c.indexOf(nameEQ) == 0) 
    {
      return c.substring(nameEQ.length,c.length);
    }
  }
  return null;
}

window.onload=function() {ndeSetStyleSheetInternal()};
