var photos = ['Atlantis-1.jpg','Atlantis-2.jpg','Atlantis-3.jpg','Atlantis-4.jpg',
              'Atlantis-5.jpg','Atlantis-6.jpg','Atlantis-7.jpg','Atlantis-8.jpg',
              'Atlantis-9.jpg','Atlantis-10.jpg','Activities-1.jpg','Activities-2.jpg',
              'Activities-3.jpg','Activities-4.jpg','Activities-5.jpg','Activities-6.jpg',
              'Activities-7.jpg','Activities-8.jpg','Activities-9.jpg','Activities-10.jpg',
              'Activities-11.jpg','Activities-1.jpg','Villa-1.jpg','Villa-2.jpg',
              'Villa-3.jpg','Villa-4.jpg'];
var videos = ['Atlantis_Activities','Deluxe_and_Premium_units',
              'Airport_to_HarborSide','Around_Harborside','Villa_1BR_Deluxe','Villa_1BR_Premium','Villa_2BR_Deluxe','Villa_Lock-offs'];

var current_photo = 0;
var begin_displayed = false;

function write_first_photo()
{
    document.writeln('<img id="gallery_photo" style="margin-top: 10px;" src="images/gallery/' +
                     photos[0] + '">');
}

function write_photo_links()
{
    var num_photos = photos.length;
    for (var loop = 0;  loop < num_photos;  loop++) {
       document.write('<div id="photo_div_' + loop + '"');
       if (loop > 4) document.write(' style="display:none;');
       else document.write(' style="display:inline;');
       if (loop < 9) document.write(' padding-left:3px; padding-right:4px;');
       document.write('">');
       document.write('<a href="javascript:select_photo(' + loop + ');" class="');
       if (loop == 0) document.write('selected_photo_link');
       else document.write('photo_link');
       document.writeln('" id="photo_link_' + loop + '">' + (loop + 1) + '</a></div>');
       if (loop < (photos.length - 1)) {
          document.write('<div id="sep_div_'+ loop + '"');
          if (loop > 3) document.write(' style="display:none;"');
          else document.write(' style="display:inline;"');
          document.write('>');
          document.write('&nbsp;&nbsp;|&nbsp;&nbsp;');
          document.writeln('</div>');
       }
    }
    document.write('&nbsp;&nbsp;of &nbsp;'+num_photos);
}

function select_photo(photo_num)
{
    var gallery_photo = document.getElementById('gallery_photo');
    gallery_photo.src = 'images/gallery/' + photos[photo_num];
    var photo_link = document.getElementById('photo_link_' + current_photo);
    photo_link.className = 'photo_link';
    photo_link = document.getElementById('photo_link_' + photo_num);
    photo_link.className = 'selected_photo_link';
    current_photo = photo_num;
    if ((current_photo == 0) && begin_displayed) {
       var begin_image = document.getElementById('begin_image');
       begin_image.style.display = 'none';   begin_displayed = false;
    }
    else if ((current_photo != 0) && (! begin_displayed)) {
       var begin_image = document.getElementById('begin_image');
       begin_image.style.display = '';   begin_displayed = true;
    }
}

function adjust_photo_divs(hide_id,show_id)
{
    var photo_div = document.getElementById('photo_div_'+hide_id);
    photo_div.style.display = 'none';
    photo_div = document.getElementById('photo_div_'+show_id);
    photo_div.style.display = 'inline';
}

function adjust_sep_divs(hide_id,show_id)
{
    var sep_div = document.getElementById('sep_div_'+hide_id);
    if (sep_div) sep_div.style.display = 'none';
    sep_div = document.getElementById('sep_div_'+show_id);
    if (sep_div) sep_div.style.display = 'inline';
}

function begin_photos()
{
    if (current_photo == 0) return;
    if (current_photo > 4) {
       var sep_div = document.getElementById('sep_div_4');
       if (sep_div) sep_div.style.display = 'none';
       for (var loop = 5;  loop <= current_photo;  loop++) {
          var photo_div = document.getElementById('photo_div_'+loop);
          photo_div.style.display = 'none';
          sep_div = document.getElementById('sep_div_'+loop);
          if (sep_div) sep_div.style.display = 'none';
       }
       for (loop = 0;  loop < 4;  loop++) {
          photo_div = document.getElementById('photo_div_'+loop);
          photo_div.style.display = 'inline';
          sep_div = document.getElementById('sep_div_'+loop);
          if (sep_div) sep_div.style.display = 'inline';
       }
       var photo_div = document.getElementById('photo_div_4');
       photo_div.style.display = 'inline';
    }
    select_photo(0);
}

function previous_photo()
{
    if (current_photo == 0) return;
    if (current_photo > 4) adjust_photo_divs(current_photo,current_photo - 5);
    if (current_photo > 4) adjust_sep_divs(current_photo - 1,current_photo - 5);
    select_photo(current_photo - 1);
}

function next_photo()
{
    if (current_photo == (photos.length - 1)) return;
    if (current_photo > 3) adjust_photo_divs(current_photo - 4,current_photo + 1);
    if (current_photo > 3) adjust_sep_divs(current_photo - 4,current_photo);
    select_photo(current_photo + 1);
}

function close_video()
{
   var video_div = document.getElementById('video_div');
   video_div.style.display = 'none';
   video_div.innerHTML = '';
   var ghost_div = document.getElementById('ghost_div');
   ghost_div.style.display = 'none';
}

function play_video(video_num)
{
   if (document.documentElement && document.documentElement.scrollWidth)
      var body_width = document.documentElement.scrollWidth;
   else if (document.body) var body_width = document.body.scrollWidth;
   else var body_width = -1;
   if (document.documentElement && document.documentElement.scrollHeight)
      var scroll_height = document.documentElement.scrollHeight;
   else if (document.body) var scroll_height = document.body.scrollHeight;
   else var scroll_height = -1;
   if (document.documentElement && document.documentElement.clientHeight)
      var client_height = document.documentElement.clientHeight;
   else if (document.body) var client_height = document.body.clientHeight;
   else var client_height = -1;
   if (scroll_height > client_height) var body_height = scroll_height;
   else var body_height = client_height;
   var ghost_div = document.getElementById('ghost_div');
   if (body_width != -1) ghost_div.style.width = '' + body_width + 'px';
   if (body_height != -1) ghost_div.style.height = '' + body_height + 'px';
   ghost_div.style.display = '';
   var friend_email_div = document.getElementById('friend_email_div');
   var see_video = document.getElementById('see_video');
   
   if (friend_email_div) {
      var divX = friend_email_div.offsetLeft;
      var divY = friend_email_div.offsetTop;
      var parent = friend_email_div.offsetParent;
      while (parent) {
         if (parent.offsetLeft) divX += parent.offsetLeft;
         if (parent.offsetTop) divY += parent.offsetTop;
         parent = parent.offsetParent;
      }
      divX -= 390;   divY -= 150;
   }
   else if (see_video) {
      var divX = see_video.offsetLeft;
      var divY = see_video.offsetTop;
      var parent = see_video.offsetParent;
      while (parent) {
         if (parent.offsetLeft) divX += parent.offsetLeft;
         if (parent.offsetTop) divY += parent.offsetTop;
         parent = parent.offsetParent;
      }
      divX -= 140;   divY -= 340;
   }
   else {
	   var divX = (body_width - 409)/2;
	   var divY = 325;
	   
	   
   }
   var video_file = 'images/flash/' + videos[video_num];
   var html = "<div><div class='video_header'></div>";
   html += AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
                            'width','388','height','285','movie',video_file,'quality',
                            'high','wmode','transparent');
   html += "</div><div class='video_footer'><a href=\"\" onclick=\"close_video();";
   html += " return false;\" ><img src=\"images/pop-up-close.jpg\" alt=\"Close Window\" border='0' /></a></div>";
   var video_div = document.getElementById('video_div');
   video_div.innerHTML = html;
   video_div.style.left = divX+"px";
   video_div.style.top = divY+"px";
   video_div.style.display = '';
}

