var TheIntFolderName;
var TheB='BODY';
var Show_CurrentPhoto=0;
var IsShow=true;
var Show_Running;
var TimeOutID;
var IsPanorama=new Array();

function myvoid()
{
}

function RedirectToPhotos() // args: FolderName, optional PrevPath
{
  var i;
  FolderName = arguments[0];
  if (arguments.length>1) PrevPath=arguments[1];
  else PrevPath='';
  if (PrevPath='undefined') PrevPath='';
  TheIntFolderName=FolderName;
  for (i=0;i<1000;i++) // just in case 'IsPanorama' is not defined
  {
    IsPanorama[i]=0;	
  }
  document.write('<script language="javascript" src="'+PrevPath+FolderName+'/Photos.js"></script>');
  if (IsShow) window.location.href= PrevPath+'Photos/Show_Photos.htm?'+FolderName;
  else window.location.href= PrevPath+'Photos/Photos.htm?'+FolderName;
}

function ShowStart()
{
  NewPic=TheSubFolder+PictureFile[0]+'.jpg';
//  alert(NewPic);
  ShowPic(NewPic,0);
  top.MainFrame.document.all.InfoSpot.innerHTML = '<FONT face="Comic Sans MS" size="-1"><P></P><hr>Move your mouse over the photos in the lower window and click them to show them enlarged.'+
    ' You may also scroll the lower bar to see more photos, if enough photos exist. Make sure that your explorer window is maximised. Click on the large photos to have them shown in a new window (in even larger size).<P></P>'+
    'This might take a while if you have a slow internet connection. The size of a large photo is about 100KB.<hr>Enjoy! Lars<hr></font>';
}

function ShowPic(NewPic,PhotoNum)
{
  var TheFrameName=top.MainFrame.location.href;
  TheFrameName=TheFrameName.toUpperCase();
  if (TheFrameName.indexOf('MAINFRAME.HTM')>0)
  {
    if (IsPanorama[PhotoNum]==1)
    {
      top.MainFrame.document.all.PhotoSpot.innerHTML = '<APPLET archive=ptviewer.jar code=ptviewer.class width=500 height=300>' +
	'<param name=roi0      value="i""' + NewPic + '"" x550 y0" >' +
	'<param name=panmin    value=-1 >' +
	'<param name=panmax    value=1 >' +
//        '<PARAM name=file   value="' + NewPic + '">' +
//        '<PARAM name=auto   value="1">' +
        '</applet>';
    }
    else
    {
      top.MainFrame.document.all.PhotoSpot.innerHTML = '<a href="' + NewPic +
        '"><img name="PicShowing" src="' + NewPic + '" ALT="'+GetDesc(NewPic,PhotoNum)+'" width="' +
        eval(GetPhotoSizeMultiplier(IsPortrait[PhotoNum]) * 1.045)+
        '" border=0 onMouseOver="window.status=\'Display this photo enlarged in new window with a mouse click\'; return true" onMouseOut="window.status=\'Click on a photo with your mouse to enlarge it\';return true"></a>';
    }
    top.MainFrame.document.all.InfoSpot.innerHTML = '<FONT face="Comic Sans MS"><P></P><hr>'+GetSubHeader(PhotoNum)+'<P></P><hr><size="3">'+GetHeader(PhotoNum, false)+'</font>';
  }
  else
  {
    alert('Didn\'t I tell you to wait for the pictures to load before pressing a button? - Please refresh the Page using the refresh button.');
  }
}

function GetPhotoSizeMultiplier(ThePortrait)
{
  Width = top.MainFrame.document.body.clientWidth;
  Height = top.MainFrame.document.body.clientHeight-30;
  if (Height<=30) Height=30;
  if (ThePortrait=='1')
  {
    PhotoHeight=4/3;
  }
  else
  {
    PhotoHeight=0.75;
  }
  if ((Width)<=(Height/PhotoHeight))
  {
    return Width;
  }
  else
  {
    return Height/PhotoHeight;
  }
}

function GetPhotoName(PhotoNum)
{
  return PictureFile[PhotoNum]+'.jpg';
}

function GetDate(PhotoNum)
{
  var PhotoName=PictureFile[PhotoNum];
  var Months = new Array('January','February','March',
    'April','May','June','July','August','September',
    'October','November','December');
  return PhotoName.substring(6,8)+' '+Months[eval(PhotoName.substring(4,6))-1]+' '+PhotoName.substring(0,4)
}

function ProduceHeaderTable()
{
  for (i=0;i<Headers.length;i++)
  {
    document.write('<td ALIGN="CENTER" VALIGN="BOTTOM" colspan="'+eval(HeadersStart[i+1]-HeadersStart[i])+'" height="18" nowrap>');
    document.write('<p align="left"><font face="WebDings" color="#000066">6</font><font face="Comic Sans MS" color="#000066">   '+Headers[i]+'</font></td>');
  }
}

function DisplayThumbnails()
{
  for (i=0;i<PictureFile.length;i++)
  {
    document.write('<TD ALIGN=CENTER VALIGN=BOTTOM height="98" nowrap><FONT face="Verdana, Arial, Helvetica, Sans-Serif" size="-2"><A HREF="javascript:ShowPic(\''+
      TheSubFolder+GetPhotoName(i)+'\','+i+')" onMouseClick="ShowPic(\''+TheSubFolder+
      GetPhotoName(i)+'\','+i+')" onMouseOver="window.status=\'Open photo '+PictureFile[i]+' with a mouse click\'; return true;" onMouseOut="window.status=\'Click on a photo with your mouse to enlarge a photo\';return true">')
    document.write('<IMG SRC="'+TheSubFolder+'TN_'+PictureFile[i]+'.jpg" ALT="'+GetDesc(PictureFile[i],i)+'"></A></FONT></TD>')
  }
}

function GetDesc(DefaultName, PhotoNum)
{
  if (!HasDesc)return('Photo '+DefaultName+'.\n Open with a mouse click.')
  else return(Desc[PhotoNum]);
}

function GetMenu(StartPath)
{
  var MaxMenuTextLength;
  MaxMenuTextLength=5;
  if (MaxMenuTextLength > MenuText.length)
  {
    MaxMenuTextLength=MenuText.length;
  }
//  for (i=0;i<MaxMenuTextLength;i++)
  for (i=0;i<MenuText.length;i++)
  {
    document.write('<TR>');
    document.write('<TD width="10%">');
    for (j=0;j<IsNewFld.length;j++)
    {
    	if (IsNewFld[j]==i)
    	{
    	    document.write('<P align=center><FONT color=#ff0000 face="Comic Sans MS"><EM>New!</EM></FONT></P>');
    	}
    }
    document.write('</TD>');
    document.write('<TD width="60%">');
    document.write('<A href="javascript:RedirectToPhotos(\''+MenuFolder[i]+'\',\''+StartPath+'\')"> <FONT face="Comic Sans MS">'+MenuText[i]+'</Font></a></td>');
    document.write('<TD rowSpan=7 width="30%">');
    if (i==0)
    {
      document.write('<P align=center><IMG height=160 src="'+ThePhoto+'" width=160><P>');
      document.write('<P align=center><IMG src="http://cgicounter.onlinehome.de/cgi-bin/cnt?clsid=e47947db0417ab952832e9ac27fda6eb1"></P></TD>');
    }
    document.write('</TR>');
  }
/*
  if (MaxMenuTextLength<MenuText.length)
  {

    document.write('<TR>');
    document.write('<TD width="10%">');
    document.write('</TD>');
    document.write('<TD width="60%">');
    document.write('<FORM name=NewPhotos><SELECT name=NewPhotoLinks');
    document.write('onchange=NewPhotoLinkUp(this.form) size=1');
    i=MaxMenuTextLength;
    document.write('style="FONT-FAMILY: Comic Sans MS; FONT-SIZE: 12pt">');
    document.write('<OPTION selected value='+i+'>check out some older photos&nbsp;');
    for (i=MaxMenuTextLength-1;i<MenuText.length;i++)
    {
      document.write('<option value='+i+'>'+MenuText[i]+'&nbsp;');
    }
    document.write('<option value='+i+'>_______________________________________________________________________</OPTION></SELECT>');
    document.write('</FORM>');
    document.write('<P>&nbsp;</P></TD></TR>');
  }
*/
}

function NewPhotoLinkUp()
{
  var number = document.NewPhotos.NewPhotoLinks.selectedIndex;
  var i=document.NewPhotos.NewPhotoLinks.options[number].value;
  location.href ='javascript:RedirectToPhotos(\''+MenuFolder[i]+'\'','\''+StartPath+'\'';
}

function GetHeader(PhotoNum, PlusSubHeader)
{
  var RetStr;
  if (!HasDesc)
  {
    if (PlusSubHeader) RetStr = GetSubHeader(PhotoNum)+'<P></P><hr>'
    else RetStr = '';
    RetStr = RetStr +  '<font size="2">Photo Name: '+GetPhotoName(PhotoNum)+'<P></P>Taken on: '+GetDate(PhotoNum);
  }
  else RetStr = ''+Desc[PhotoNum]+'<P></P><hr><font size="2">Photo Name: '+GetPhotoName(PhotoNum);
  return RetStr;
}

function GetSubHeader(PhotoNum)
{
  for (i=1;i<=Headers.length;i++)
  {
    if (HeadersStart[i]-1>PhotoNum)
    {
      return Headers[i-1];
    }
  }
}

function GetParam()
{
  var locate = window.location;
  document.GetPassString.PassTheString.value = locate;
  var Text = document.GetPassString.PassTheString.value;
  TheIntFolderName=Text.substring(Text.indexOf("?") + 1, 1000);
  return(TheIntFolderName);
}

function LoadMainFrame(CmdLine)
{
  window.MainFrame.location.href = 'MainFrame.htm?'+CmdLine;
}

//Get Browser info
function GetBrowser()
{
  return ('App Name = ['+navigator.appName+'], Version=['+navigator.appVersion+']');	
}

//Get Command Line Parameters, in one string
function GetCmdLine()
{
  var TheRetStr=unescape(location.search.substring(1));
  if (TheRetStr)
  {
    return TheRetStr;
  }
  else return 'No Cmd Line';
}

// COOKIE STUFF
function GetCookie(name)
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    if (begin != 0)
    {
      alert('GetCookie: '+name+' returned null.');
      return null;
    } 	
  }
  else 
  {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;
//  alert(dc.substring(begin + prefix.length, end));
  return unescape(dc.substring(begin + prefix.length, end));
}

function SetCookie (name, value)
{
//  alert('SetCookie: '+name+','+value);
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name)
{
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//Animation Config: can be modified from here
var from = 5;                    //the animation start value
var to = 11;			 //the animation end value
var delay = 55;			 //the animation speed
var glowColor = "white";          //the color of the text
//no more editing
var i = to;
var j = 0;
function textPulseUp()
{
  if (!document.all) return
  if (i < to)
  {
    theText.style.filter = "Glow(Color=" + glowColor + ", Strength=" + i + ")";
    i++;
    theTimeout = setTimeout('textPulseUp()',delay);
    return 0;
  }
  if (i = to)
  {
    theTimeout = setTimeout('textPulseDown()',delay);
    return 0;
  }
}
function textPulseDown()
{
  if (!document.all)
  return
  if (i > from)
  {
    theText.style.filter = "Glow(Color=" + glowColor + ", Strength=" + i + ")";
    i--;
    theTimeout = setTimeout('textPulseDown()',delay);
    return 0;
  }
  if (i = from)
  {
    theTimeout = setTimeout('textPulseUp()',delay);
    return 0;
  }
}

// Functionality for the Slide Show
function Show_ShowStart()
{
  Show_NextPhoto(true);
  top.MainFrame.document.all.InfoSpot.innerHTML = '<FONT face="Comic Sans MS" size="-1"><P></P><hr>Use the buttons at the lower end of the window to Start or Stop the presentation.'+
    ' In slide mode, a new photo is loaded every 5 seconds (if your internet speed allows for it). You can pause the show at any point.<P></P>Also you may use the Fast Forward or Rewind button to go back/move forward one photo. Make sure that your explorer window is maximised. Click on the large photos to have them shown in a new window (in even larger size).<P></P>'+
    'This might take a longer than 5 secs if you have a slow internet connection. The size of a large photo is about 100KB.<hr>Enjoy! Lars<hr></font>';
}

function Show_NextPhoto() //args: optional ChangeNow=false
{
  clearTimeout(TimeOutID);
  PhotoDelay = 5000;
  if (arguments.length>0) ChangeNow=arguments[0];
  else ChangeNow=false;
  if (Show_Running||ChangeNow)
  {
    if ((Show_CurrentPhoto==PictureFile.length)&&(!ChangeNow))
    {
      Show_ResetCurrentPhoto();
      Show_Stop();
    }
    else
    {
      NewPic=TheSubFolder+GetPhotoName(Show_CurrentPhoto);
      TimeOutID = setTimeout('Show_NextPhoto()',PhotoDelay);
      if (IsPanorama[Show_CurrentPhoto]==1)
      {
        top.MainFrame.document.all.PhotoSpot.innerHTML = '<APPLET archive=ptviewer.jar code=ptviewer.class' +
          ' width='+eval(GetPhotoSizeMultiplier(IsPortrait[Show_CurrentPhoto]) * 1.035)+
          ' height='+eval(GetPhotoSizeMultiplier(IsPortrait[Show_CurrentPhoto]) * 1.035 * 0.75)+'>' +
          '<PARAM name=file   value="' + NewPic + '">' +
          '<PARAM name=auto   value="1">' +
          '</applet>';
      }
      else
      {
        top.MainFrame.document.all.PhotoSpot.innerHTML = '<a href="'+NewPic+'">'+
          '<img name="' + PictureFile[Show_CurrentPhoto] + '" src="'+NewPic+'" ALT="Photo Desc" width="' +
          eval(GetPhotoSizeMultiplier(IsPortrait[Show_CurrentPhoto]) * 1.035)+
          '" border=0 onMouseOver="window.status=\'Display this photo enlarged in new window with a mouse click\'; return true" onMouseOut="window.status=\'Click on a photo with your mouse to enlarge it\';return true"></a>';
      }
      top.MainFrame.document.all.InfoSpot.innerHTML = '<FONT face="Comic Sans MS"><P></P><hr>'+GetHeader(Show_CurrentPhoto, true);
//      top.MainFrame.document.all.InfoSpot.innerHTML = '<FONT face="Comic Sans MS"><P></P><hr>      Test';
      top.MainFrame.document.all.CountSpot.innerHTML = '<FONT face="Comic Sans MS" size="2"><P></P>Photo # '+eval(Show_CurrentPhoto+1)+' of '+PictureFile.length+'<P></P><hr></font>';
      if (IsPanorama[Show_CurrentPhoto]=='1')
      {
      	top.MainFrame.document.all.CountSpot.innerHTML = top.MainFrame.document.all.CountSpot.innerHTML +
      	  'This is a Panorama photo. Use all arrow keys or your mouse to move within the photo, and the [+] and [-] buttons to zoom in and out.';
      }
      Show_CurrentPhoto++;
    }
  }
}

function Show_Previous()
{
  Show_CurrentPhoto--;
  Show_CurrentPhoto--;
  if (Show_CurrentPhoto<0) Show_CurrentPhoto=PictureFile.length-1;
  Show_NextPhoto(true);

}

function Show_Next()
{
  Show_NextPhoto(true);
  if (Show_CurrentPhoto==PictureFile.length) Show_ResetCurrentPhoto();
}

function Show_Start()
{
  Show_LoadButtons(false,false,true);
  Show_Running=true;
  Show_NextPhoto(false);
}

function Show_Stop()
{
  Show_LoadButtons(true,false,false);
  Show_Running=false;
  Show_ResetCurrentPhoto();
  Show_NextPhoto(true);
}

function Show_Pause()
{
  Show_LoadButtons(false,true,false);
  Show_Running=false;
}

function Show_ResetCurrentPhoto()
{
  Show_CurrentPhoto=0;	
}

function Show_LoadButtons(IsStopOn, IsPauseOn, IsPlayOn)
{
  if (IsStopOn) StopGif='StopButtonActive.Gif'; else StopGif='StopButtonBlue.gif';
  if (IsPauseOn) PauseGif='PauseButtonActive.Gif'; else PauseGif='PauseButtonBlue.gif';
  if (IsPlayOn) PlayGif='PlayButtonActive.Gif'; else PlayGif='PlayButtonBlue.gif';
  top.Buttons.document.all.StopSpot.innerHTML = '<a href="javascript:Show_Stop()">' +
    ' <img border="0" onMouseOver="javascript:window.status=\'Stop the slide show (go to 1st Picture).\'; return true"'+
    ' onMouseOut="window.status=\'Click on a photo with your mouse to enlarge it.\';return true"'+ 
    ' src="Extra/'+StopGif+'" width="34" height="34" alt="Stop the slide show (go to 1st Picture)."></a>';
  top.Buttons.document.all.PauseSpot.innerHTML = '<a href="javascript:Show_Pause()">' +
    ' <img border="0" onMouseOver="javascript:window.status=\'Pause the slide show.\'; return true"'+ 
    ' onMouseOut="window.status=\'Click on a photo with your mouse to enlarge it.\';return true"'+ 
    ' src="Extra/'+PauseGif+'" width="34" height="34" alt="Pause the slide show."></a>';
  top.Buttons.document.all.PlaySpot.innerHTML = '<a href="javascript:Show_Start()">' +
    ' <img border="0" onMouseOver="javascript:window.status=\'Play the slide show.\'; return true"'+ 
    ' onMouseOut="window.status=\'Click on a photo with your mouse to enlarge it.\';return true"'+ 
    ' src="Extra/'+PlayGif+'" width="34" height="34" alt="Play the slide show."></a>';	
}


