function CPhotoBox()
{
    this.m_htmlThumbnails = null;
    this.m_htmlPhotoBox = null;
    this.m_htmlPhotoContainer = null;
    this.m_htmlControls = null;
    
    this.m_htmlPhotoContainerPrevious = null;
    this.m_htmlPhotoContainerCurrent = null;
    this.m_htmlPhotoContainerNext = null;

    this.m_listPhoto = null;
    this.m_nPhotoCursor = 0;

    if(HTML.GetBrowserType() == HTML.BROWSER_TYPE_IPHONEPAD)
    {
        this.FADE_DURATION = 50;  // ms
    }
    else
    {
        this.FADE_DURATION = 500;  // ms
    }

    this.m_bInTransaction = false;

    this.m_bListenToKeyboardEvents = true;
    this.m_bUpdateAddressBar = true;
    this.m_bViewControls = true;

    this.m_bDisplayGrayScale = false;

    this.m_bCacheImages = true;
    this.m_oCachedImages = new Array();

    this.m_nClicks = 0;
}

CPhotoBox.IMAGE_LOCATION = 'http://www.chrisfrance.co.uk/codebase/framework/Photo.php';
CPhotoBox.NEXT = 1;
CPhotoBox.PREVIOUS = 2;

CPhotoBox.EVENT_KEY_DOWN = 1;
CPhotoBox.EVENT_KEY_UP = 2;

CPhotoBox.THUMBNAIL_COUNT = 5;
CPhotoBox.THUMBNAIL_OFFSET = 2;

CPhotoBox.prototype.Initialise = function(htmlContainer, oAlbumManager, sInitalPhotoID)
{
    this.m_htmlContainer = htmlContainer;

    this.m_listPhoto = oAlbumManager.GetAllPhotos();

    this._SetInitalPhotoCursor(sInitalPhotoID);

    if(this.m_htmlContainer != null)
    {
        if(this.m_listPhoto.GetCount() > 0)
        {
            this._DrawPhotoContainer();
        }
        else
        {
            this._DrawWarning();
        }
    }
    return SW_OK;
}

CPhotoBox.prototype._SetInitalPhotoCursor = function(sInitalPhotoID)
{
    this.m_nPhotoCursor = 0;
    if(sInitalPhotoID != null)
    {
        this.m_nPhotoCursor = this.m_listPhoto.FindIndex('GetID', sInitalPhotoID);
    }
    if(this.m_nPhotoCursor < 0)
    {
        this.m_nPhotoCursor = 0;
    }
    return SW_OK;
}

CPhotoBox.prototype._GetHasMultiplePhotos = function()
{
  return (this.m_listPhoto.GetCount() > 1);
}

CPhotoBox.prototype._DrawPhotoContainer = function ()
{
    var pMe = this;

    this.m_bDisplayGrayScale = false;
    HTML.RemoveChildren(this.m_htmlContainer);

    this.m_htmlPhotoBox = document.createElement('DIV');
    HTML.AddClassName(this.m_htmlPhotoBox, 'PhotoBox');
    this.m_htmlContainer.appendChild(this.m_htmlPhotoBox);

    this.m_htmlPhotoContainer = document.createElement('DIV');
    HTML.AddClassName(this.m_htmlPhotoContainer, 'PhotoContainer');
    this.m_htmlPhotoBox.appendChild(this.m_htmlPhotoContainer);

    if(this._GetHasMultiplePhotos() == true)
    {
        this.m_htmlPhotoContainerPrevious = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlPhotoContainerPrevious, 'Photo_Previous');
        this.m_htmlPhotoContainer.appendChild(this.m_htmlPhotoContainerPrevious);
    }

    this.m_htmlPhotoContainerCurrent = document.createElement('DIV');
    HTML.AddClassName(this.m_htmlPhotoContainerCurrent, 'Photo_Current');
    this.m_htmlPhotoContainer.appendChild(this.m_htmlPhotoContainerCurrent);

    if(this._GetHasMultiplePhotos() == true)
    {
        this.m_htmlPhotoContainerNext = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlPhotoContainerNext, 'Photo_Next');
        this.m_htmlPhotoContainer.appendChild(this.m_htmlPhotoContainerNext);
    }

    this._SetInitalPhotos();

    if(this.m_bViewControls == true)
    {
        this.m_htmlIcons = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlIcons, 'IconContainer');
        this.m_htmlPhotoBox.appendChild(this.m_htmlIcons);

        this._DrawIcons();

        this.m_htmlThumbnails = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlThumbnails, 'ThumbnailContainer');
        this.m_htmlPhotoBox.appendChild(this.m_htmlThumbnails);

        this._DrawThumbnails();

        this.m_htmlControls = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlControls, 'Controls');
        this.m_htmlContainer.appendChild(this.m_htmlControls);

        if(HTML.GetBrowserType() != HTML.BROWSER_TYPE_IPHONEPAD)
        {
            HTML.AddClassName(this.m_htmlIcons, 'Hidden');
            HTML.AddClassName(this.m_htmlThumbnails, 'Hidden');
            HTML.AddClassName(this.m_htmlControls, 'Hidden');
            this.m_htmlContainer.onmouseover = function () { pMe._OnMouseIn(); };
            this.m_htmlContainer.onmouseout = function () { pMe._OnMouseOut(); };
        }

        var htmlBackControl = document.createElement('DIV');
        HTML.AddClassName(htmlBackControl, 'BackControl');
        this.m_htmlControls.appendChild(htmlBackControl);

        var imgBack = document.createElement('IMG');
        imgBack.setAttribute('src', 'SiteImages/Back.png');
        imgBack.setAttribute('alt', 'Back');
        imgBack.onclick = function () { pMe.Previous(); pMe._CountClicks(); };
        htmlBackControl.appendChild(imgBack);

        var htmlForwardControl = document.createElement('DIV');
        HTML.AddClassName(htmlForwardControl, 'ForwardControl');
        this.m_htmlControls.appendChild(htmlForwardControl);

        var imgForward = document.createElement('IMG');
        imgForward.setAttribute('src', 'SiteImages/Forward.png');
        imgForward.setAttribute('alt', 'Forward');
        imgForward.onclick = function () { pMe.Next(); pMe._CountClicks(); };
        htmlForwardControl.appendChild(imgForward);

        this.m_htmlTip = document.createElement('DIV');
        this.m_htmlTip.onclick = function () { HTML.AddClassName(pMe.m_htmlTip, 'Hidden'); return false; };
        HTML.AddClassName(this.m_htmlTip, 'Tip');
        HTML.AddClassName(this.m_htmlTip, 'Hidden');

        var htmlHeading = document.createElement('H1');
        htmlHeading.appendChild(document.createTextNode('Did you know?...'));
        this.m_htmlTip.appendChild(htmlHeading);

        var htmlP = document.createElement('P');
        htmlP.appendChild(document.createTextNode('You can use the keyboard arrows to navigate though the photos.'));
        this.m_htmlTip.appendChild(htmlP);

        var htmlP = document.createElement('P');
        htmlP.appendChild(document.createTextNode('(Click this message to remove it)'));
        this.m_htmlTip.appendChild(htmlP);

        this.m_htmlContainer.appendChild(this.m_htmlTip);
    }

    this._UpdateAddressBar();

    if(this.m_bListenToKeyboardEvents == true)
    {
        if(window.ActiveXObject)
        {
            // Works for IE but not FF
            window.document.onkeydown = function (e) { return pMe._OnKeyboardEvent(CPhotoBox.EVENT_KEY_DOWN, e); };
            window.document.onkeyup = function (e) { return pMe._OnKeyboardEvent(CPhotoBox.EVENT_KEY_UP, e); };
        }
        else
        {
            // Works in FF but not IE
            window.document.addEventListener('keydown', function (e) { return pMe._OnKeyboardEvent(CPhotoBox.EVENT_KEY_DOWN, e); }, true);
            window.document.addEventListener('keyup', function (e) { return pMe._OnKeyboardEvent(CPhotoBox.EVENT_KEY_UP, e); }, true);
        }
    }
    return SW_OK;
}

CPhotoBox.prototype._OnMouseIn = function()
{
    HTML.RemoveClassName(this.m_htmlIcons, 'Hidden');
    HTML.RemoveClassName(this.m_htmlThumbnails, 'Hidden');
    HTML.RemoveClassName(this.m_htmlControls, 'Hidden');
    return SW_OK;
}

CPhotoBox.prototype._OnMouseOut = function()
{
    HTML.AddClassName(this.m_htmlIcons, 'Hidden');
    HTML.AddClassName(this.m_htmlThumbnails, 'Hidden');
    HTML.AddClassName(this.m_htmlControls, 'Hidden');
    return SW_OK;
}

CPhotoBox.prototype._DrawWarning = function()
{
    HTML.RemoveClassName(this.m_htmlContainer, 'Loading');
    this.m_htmlContainer.appendChild(document.createTextNode('No Photos')); // TODO tidy up
    return SW_OK;
}

CPhotoBox.prototype._DrawThumbnails = function()
{
  HTML.RemoveChildren(this.m_htmlThumbnails);
  
  var htmlList = document.createElement('UL');
  this.m_htmlThumbnails.appendChild(htmlList);  
  
  var nCount = this.m_nPhotoCursor + CPhotoBox.THUMBNAIL_COUNT - CPhotoBox.THUMBNAIL_OFFSET;
  var nCursor = this.m_nPhotoCursor - CPhotoBox.THUMBNAIL_OFFSET;
  for(; nCursor < nCount; nCursor++)
  {
    htmlList.appendChild(this._DrawThumbnail(this._GetThumbnailCursorOffSet(nCursor)));
  }
  return SW_OK;
}

CPhotoBox.prototype._ToggleBWorColour = function()
{
    var pMe = this;

    if(this.m_bDisplayGrayScale == false)
    {
        this.m_bDisplayGrayScale = true;
    }
    else
    {
        this.m_bDisplayGrayScale = false;
    }
    return this._SetFilter();
}

CPhotoBox.prototype._ReturnToAlbum = function()
{
    var pMe = this;

    window.location = 'photogallery.php';
    return SW_Ok;
}

CPhotoBox.prototype._SetFilter = function()
{
    var pMe = this;
    if(this.m_bDisplayGrayScale == true)
    {
        this.m_htmlPhotoContainerCurrent.style.filter = 'gray';
    }
    else
    {
        this.m_htmlPhotoContainerCurrent.style.filter = 'none';
    }
    return SW_OK;
}

CPhotoBox.prototype._DrawIcons = function ()
{
    var pMe = this;
    this.m_htmlIcons.appendChild(this._CreateButton('Return to Gallery', 'SiteImages/Icons/Back.png', function () { pMe._ReturnToAlbum(); }, 150));

    if(HTML.GetBrowserType() == HTML.BROWSER_TYPE_IE)
    {
        this.m_htmlIcons.appendChild(this._CreateButton('B&W / Colour', 'SiteImages/Icons/BandWhite.png', function () { pMe._ToggleBWorColour(); }, 130));
    }
}

CPhotoBox.prototype._CreateButton = function(sName, sIconSrc, fn, nWidth)
{
    if(nWidth == null)
    {
        nWidth = 100;
    }

    var htmlLink = document.createElement('A');
    htmlLink.setAttribute('href', '#');
    HTML.AddClassName(htmlLink, 'Button');
    htmlLink.onclick = function() { fn(); return false; };

    var htmlTable = document.createElement('TABLE');
    htmlTable.setAttribute('cellpadding', '0');
    htmlTable.setAttribute('cellspacing', '0');
    htmlTable.style.width = nWidth + 'px';
    htmlLink.appendChild(htmlTable);

    var htmlTHead = document.createElement('THEAD');
    htmlTable.appendChild(htmlTHead);

    var htmlTR = document.createElement('TR');
    htmlTHead.appendChild(htmlTR);

    var htmlTD = document.createElement('TD');
    htmlTR.appendChild(htmlTD);

    var img = document.createElement('IMG');
    img.alt = sName;
    img.src = sIconSrc;
    htmlTD.appendChild(img);

    var htmlTD = document.createElement('TD');
    htmlTR.appendChild(htmlTD);
    htmlTD.appendChild(document.createTextNode(sName));

    return htmlLink;
}

CPhotoBox.prototype._DrawThumbnail = function (nCurrentPhotoIndex)
{
    var pMe = this;
    var htmlListItem = document.createElement('LI');

    var htmlLink = document.createElement('A');
    htmlLink.setAttribute('href', '#');
    if(HTML.GetBrowserType() != HTML.BROWSER_TYPE_IPHONEPAD)
    {
        htmlLink.onclick = function () { pMe.GotoPhoto(nCurrentPhotoIndex); return false; };
    }
    else
    {
        htmlLink.onmouseover = function () { pMe.GotoPhoto(nCurrentPhotoIndex); return false; };
    }
    
    htmlListItem.appendChild(htmlLink);

    var oPhoto = this._GetPhoto(nCurrentPhotoIndex);
    var imgPhoto = this._CreateIMG(CPhotoBox.IMAGE_LOCATION + '?ID=' + oPhoto.GetID() + '&Type=T', htmlLink);

    return htmlListItem;
}

CPhotoBox.prototype._GetThumbnailCursorOffSet = function(nCursor)
{
    var nThumbnailCursorOffset = nCursor;
    var nPhotoCount = this.m_listPhoto.GetCount();
    if(nCursor < 0)
    {
      nThumbnailCursorOffset = nPhotoCount + nCursor; 
    }
    if(nCursor >= nPhotoCount)
    {
      nThumbnailCursorOffset = (nCursor - nPhotoCount); 
    }
    return nThumbnailCursorOffset;
}

CPhotoBox.prototype.Next = function()
{
    var nRet = SW_OK;
    if(this.m_bInTransaction == false)
    {          
      this.m_nPhotoCursor = this._GetNextID();
      nRet = this._StartTransition(CPhotoBox.NEXT);
    }
    return nRet;
}

CPhotoBox.prototype.Previous = function()
{
    var nRet = SW_OK;
    if(this.m_bInTransaction == false)
    {
      this.m_nPhotoCursor = this._GetPreviousID();
      nRet = this._StartTransition(CPhotoBox.PREVIOUS);
    }
    return nRet;
}

CPhotoBox.prototype._CountClicks = function()
{
    this.m_nClicks++;
    
    if((this.m_nClicks == 5) &&
       (HTML.GetBrowserType() != HTML.BROWSER_TYPE_IPHONEPAD))
    {
      HTML.RemoveClassName(this.m_htmlTip, 'Hidden');
    }
    return SW_OK;
}

CPhotoBox.prototype.GotoPhoto = function(nPhotoIndex)
{
    if(this.m_nPhotoCursor != nPhotoIndex)
    {
        this.m_nPhotoCursor = nPhotoIndex;
        this._DrawPhotoContainer();
    }
    return SW_OK;
}

CPhotoBox.prototype._GetNextID = function()
{
    var nNextPhotoID = this.m_nPhotoCursor + 1;
    if(nNextPhotoID >= this.m_listPhoto.GetCount())
    {
        nNextPhotoID = 0;
    }
    return nNextPhotoID;
}

CPhotoBox.prototype._GetPreviousID = function()
{
    var nPreviousPhotoID = this.m_nPhotoCursor - 1;
    if(nPreviousPhotoID < 0)
    {
        nPreviousPhotoID = (this.m_listPhoto.GetCount() - 1);
    }
    return nPreviousPhotoID;
}

CPhotoBox.prototype._SetInitalPhotos = function()
{
    if(this._GetHasMultiplePhotos() == true)
    {
      // Previous
      var nPreviousPhotoID = this.m_nPhotoCursor - 1;
      if(nPreviousPhotoID <= 0)
      {
          nPreviousPhotoID = (this.m_listPhoto.GetCount() - 1);
      }
      this._SetPhoto(this.m_htmlPhotoContainerPrevious, nPreviousPhotoID);
      HTML.SetOpacity(this.m_htmlPhotoContainerPrevious, 0);
      this.m_htmlPhotoContainerPrevious.style.zIndex = 2;
    }
    
    // Current
    this._SetPhoto(this.m_htmlPhotoContainerCurrent, this.m_nPhotoCursor);
    this.m_htmlPhotoContainerCurrent.style.zIndex = 1;
    
    if(this._GetHasMultiplePhotos() == true)
    {
      // Next
      var nNextPhotoID = this.m_nPhotoCursor + 1;
      if(nNextPhotoID >= this.m_listPhoto.GetCount())
      {
          nNextPhotoID = 0;
      }
      this._SetPhoto(this.m_htmlPhotoContainerNext, nNextPhotoID);
      HTML.SetOpacity(this.m_htmlPhotoContainerNext, 0);
      this.m_htmlPhotoContainerNext.style.zIndex = 2;
    }
    return SW_OK;
}

CPhotoBox.prototype._GetPhoto = function(nCursor)
{
    return this.m_listPhoto.Get(nCursor);
}

CPhotoBox.prototype._SetPhoto = function (htmlPhotoContainer, nCursor) {
    HTML.RemoveChildren(htmlPhotoContainer);

    var oPhoto = this._GetPhoto(nCursor);
    var imgPhoto = this._CreateIMG(CPhotoBox.IMAGE_LOCATION + '?ID=' + oPhoto.GetID(), htmlPhotoContainer);

    var nX = oPhoto.GetOffsetX();
    var nY = oPhoto.GetOffsetY();
    htmlPhotoContainer.style.top = nX + 'px';
    htmlPhotoContainer.style.left = nY + 'px'; 

    return SW_OK;
}

CPhotoBox.prototype._CreateIMG = function (sSrc, htmlContainer)
{
    var pMe = this;

    var imgPhoto = null;
    if((this.m_bCacheImages == true) && 
       (this.m_oCachedImages[sSrc] != null))
    {
        imgPhoto = this.m_oCachedImages[sSrc];
        htmlContainer.appendChild(imgPhoto);
    }
    else
    {
        HTML.AddClassName(htmlContainer, 'Loading');

        imgPhoto = document.createElement('IMG');
        imgPhoto.src = sSrc;
        htmlContainer.appendChild(imgPhoto);

        imgPhoto.onload = function ()
        {
            HTML.RemoveClassName(htmlContainer, 'Loading');
            HTML.RemoveClassName(imgPhoto, 'Hidden');

            pMe.m_oCachedImages[sSrc] = imgPhoto;
        };

        if(imgPhoto.complete == true) // If the Image is cached onload will not be called so directly display the image
        {
            HTML.RemoveClassName(htmlContainer, 'Loading');
            pMe.m_oCachedImages[sSrc] = imgPhoto;
        }
        else
        {
            HTML.AddClassName(imgPhoto, 'Hidden');
        }
    }
    return imgPhoto;
}

CPhotoBox.prototype._StartTransition = function(nDirection)
{
    var pMe = this;
    
    this.m_bInTransaction = true;
    // Do transition between the two containers
    var nRet = this._ProcessBeforePhotoChange();
    if(ReturnIsOK(nRet))
    {
        var htmlFadePrevious = null;
        var htmlFadeFrom = this.m_htmlPhotoContainerCurrent;
        var htmlFadeTo = null;

        if(nDirection == CPhotoBox.NEXT)
        {
            htmlFadeTo = this.m_htmlPhotoContainerNext;
            htmlFadePrevious = this.m_htmlPhotoContainerPrevious;
        }
        else // CPhotoBox.PREVIOUS;
        {
            htmlFadeTo = this.m_htmlPhotoContainerPrevious;
            htmlFadePrevious = this.m_htmlPhotoContainerNext;
        }

        HTML.SetOpacity(htmlFadeTo, 0);
        htmlFadeTo.style.zIndex = 3;
        htmlFadeFrom.style.zIndex = 2;
        htmlFadePrevious.style.zIndex = 1;

        HTML.Fade(htmlFadeTo, 0, 1, pMe.FADE_DURATION, pMe, nDirection);
    }
    return nRet;
}

CPhotoBox.prototype.FadeComplete = function(nDirection)
{
    var pMe = this;

    // Reshuffle the photo
    if(nDirection == CPhotoBox.NEXT)
    {
        var htmlTemp = this.m_htmlPhotoContainerPrevious;
        this.m_htmlPhotoContainerPrevious = this.m_htmlPhotoContainerCurrent;
        HTML.RemoveClassName(this.m_htmlPhotoContainerPrevious, 'Photo_Current');
        HTML.AddClassName(this.m_htmlPhotoContainerPrevious, 'Photo_Previous');
        this.m_htmlPhotoContainerPrevious.style.zIndex = 1;

        this.m_htmlPhotoContainerCurrent = this.m_htmlPhotoContainerNext;
        HTML.RemoveClassName(this.m_htmlPhotoContainerCurrent, 'Photo_Next');
        HTML.AddClassName(this.m_htmlPhotoContainerCurrent, 'Photo_Current');
        this.m_htmlPhotoContainerCurrent.style.zIndex = 2;

        this.m_htmlPhotoContainerNext = htmlTemp;
        HTML.SetOpacity(this.m_htmlPhotoContainerNext, 0);
        HTML.RemoveClassName(this.m_htmlPhotoContainerNext, 'Photo_Previous');
        HTML.AddClassName(this.m_htmlPhotoContainerNext, 'Photo_Next');
        this.m_htmlPhotoContainerNext.style.zIndex = 1;

        this._SetPhoto(this.m_htmlPhotoContainerNext, this._GetNextID());
    }
    else // CPhotoBox.PREVIOUS;
    {
        var htmlTemp = this.m_htmlPhotoContainerNext;
        this.m_htmlPhotoContainerNext = this.m_htmlPhotoContainerCurrent;
        HTML.RemoveClassName(this.m_htmlPhotoContainerNext, 'Photo_Current');
        HTML.AddClassName(this.m_htmlPhotoContainerNext, 'Photo_Next');
        this.m_htmlPhotoContainerNext.style.zIndex = 1;

        this.m_htmlPhotoContainerCurrent = this.m_htmlPhotoContainerPrevious;
        HTML.RemoveClassName(this.m_htmlPhotoContainerCurrent, 'Photo_Previous');
        HTML.AddClassName(this.m_htmlPhotoContainerCurrent, 'Photo_Current');
        this.m_htmlPhotoContainerCurrent.style.zIndex = 2;

        this.m_htmlPhotoContainerPrevious = htmlTemp;
        HTML.SetOpacity(this.m_htmlPhotoContainerPrevious, 0);
        HTML.RemoveClassName(this.m_htmlPhotoContainerPrevious, 'Photo_Next');
        HTML.AddClassName(this.m_htmlPhotoContainerPrevious, 'Photo_Previous');
        this.m_htmlPhotoContainerPrevious.style.zIndex = 1;

        this._SetPhoto(this.m_htmlPhotoContainerPrevious, this._GetPreviousID());
    }

    this.m_bDisplayGrayScale = false;

    if(this.m_bViewControls == true)
    {
        this._DrawThumbnails();
    }

    if(this.m_bUpdateAddressBar == true)
    {
        this._UpdateAddressBar();
    }
    
    this.m_bInTransaction = false;
    return this._ProcessAfterPhotoChange();
}

CPhotoBox.prototype._ProcessBeforePhotoChange = function()
{
    return SW_OK;
}

CPhotoBox.prototype._ProcessAfterPhotoChange = function()
{
    return SW_OK;
}

CPhotoBox.prototype._UpdateAddressBar = function()
{
    if(this.m_bUpdateAddressBar == true)
    {
        var oPhoto = this._GetPhoto(this.m_nPhotoCursor);
        window.location = '#ID=' + oPhoto.GetID();
    }
    return SW_OK;
}

CPhotoBox.prototype._OnKeyboardEvent = function(nEvent, e)
{
    if(!e)
    {
        e = window.event;
    };

    switch(e.keyCode)
    {
        case 37: // Left
            this.Previous();
            break;

        case 39: // Right
            this.Next();
            break;

        default:
            break;
    }
    return SW_OK;
}

/////////////////////////////////////////////////////////

function CAutoPhotoBox()
{
    CAutoPhotoBox.ParentConstructor.call(this);

    this.FADE_DURATION = 2000;  // ms
    this.DISPLAY_DURATION = 5000; // ms

    this.m_bUpdateAddressBar = false;
    this.m_bListenToKeyboardEvents = false;
    this.m_bViewControls = false;
}

DeriveClass(CAutoPhotoBox, CPhotoBox);

CAutoPhotoBox.prototype.Initialise = function(htmlContainer, listPhoto, nFirstPhoto)
{       
    var nRet = CAutoPhotoBox.Parent.Initialise.call(this, htmlContainer, listPhoto, nFirstPhoto);
    if(ReturnIsOK(nRet))
    {
      var pMe = this;
      setTimeout(function() { pMe.Next(); }, pMe.DISPLAY_DURATION);
    }
    return nRet;
}

CAutoPhotoBox.prototype._ProcessAfterPhotoChange = function()
{
    var nRet = CAutoPhotoBox.Parent._ProcessAfterPhotoChange.call(this);
    if(ReturnIsOK(nRet))
    {
      var pMe = this;
      setTimeout(function() { pMe.Next(); }, pMe.DISPLAY_DURATION);
    }
    return nRet;
}

////////////////////////////////////////////////

function CPhotoBoxLike()
{
    CPhotoBoxLike.ParentConstructor.call(this);

    this.m_htmlIFrameController = null;
    this.m_htmlIFrameContainer = null;
}

DeriveClass(CPhotoBoxLike, CPhotoBox);
      
CPhotoBoxLike.prototype._DrawPhotoContainer = function()
{
    var pMe = this;

    var nRet = CPhotoBoxLike.Parent._DrawPhotoContainer.call(this);
    if(ReturnIsOK(nRet))
    {
        this.m_htmlIFrameController = document.createElement('DIV');
        HTML.AddClassName(this.m_htmlIFrameController, 'IFrameController Hidden'); 
        this.m_htmlPhotoBox.appendChild(this.m_htmlIFrameController);

        nRet = this._DrawIFrame();
    }
    return nRet;
}

CPhotoBoxLike.prototype._OnMouseIn = function()
{
    var nRet = CPhotoBoxLike.Parent._OnMouseIn.call(this);
    if(ReturnIsOK(nRet))
    {
      HTML.RemoveClassName(this.m_htmlIFrameController, 'Hidden');
    }
    return nRet;
}

CPhotoBoxLike.prototype._OnMouseOut = function()
{
    var nRet = CPhotoBoxLike.Parent._OnMouseOut.call(this);
    if(ReturnIsOK(nRet))
    {
      HTML.AddClassName(this.m_htmlIFrameController, 'Hidden');
    }
    return nRet;
}

CPhotoBoxLike.prototype._ProcessAfterPhotoChange = function()
{
    var nRet = CPhotoBoxLike.Parent._ProcessAfterPhotoChange.call(this);
    if(ReturnIsOK(nRet))
    {
        nRet = this._DrawIFrame();
    }
    return nRet;
}

CPhotoBoxLike.prototype._DrawIFrame = function()
{
    HTML.RemoveChildren(this.m_htmlIFrameController);

    var oPhoto = this._GetPhoto(this.m_nPhotoCursor);
    var sAddress = 'http://www.facebook.com/plugins/like.php?href=www.chrisfrance.co.uk%2Fphoto' + oPhoto.GetID() + '&amp;layout=standard&amp;show_faces=true&amp;width=300&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=80';

    this.m_htmlIFrameContainer = document.createElement('IFRAME');
    this.m_htmlIFrameContainer.setAttribute('src', sAddress);
    this.m_htmlIFrameContainer.setAttribute('scrolling', 'no');
    this.m_htmlIFrameContainer.setAttribute('frameBorder', '0');
    this.m_htmlIFrameContainer.style.overflow = 'hidden';
    this.m_htmlIFrameController.appendChild(this.m_htmlIFrameContainer);

    return SW_OK;
}
 
////////////////////////////////////////////////

function CPhotoBoxOfTheDay()
{
    CPhotoBoxOfTheDay.ParentConstructor.call(this);
    
    this.m_bListenToKeyboardEvents = false;
    this.m_bUpdateAddressBar = false;
    this.m_bViewControls = false;

    this.m_sDay = new Date();
}

DeriveClass(CPhotoBoxOfTheDay, CPhotoBox);

CPhotoBoxOfTheDay.prototype.Initialise = function (htmlContainer, listPhoto, nFirstPhoto)
{
    var nRet = CPhotoBoxOfTheDay.Parent.Initialise.call(this, htmlContainer, listPhoto, nFirstPhoto);
    if(ReturnIsOK(nRet))
    {
        
    }
    return nRet;
}

CPhotoBoxOfTheDay._ClockTick = function ()
{
    var pMe = this;
    window.setTimeout(function () { pMe._ClockTick(); }, 3600000); // Tick every hour
}

   
////////////////////////////////////////////////
