var imageSets;
var captions;
var categories;
var categorySets;

function openImageViewer(set, index, embedded) {
  var url = "/images/viewer.html?" + set + "," + index;
  window.open(url, "viewer", "width=800,height=400,top=30,left=30,resizable=yes,scrollbars=yes,location=no,menubar=no,status=no,toolbar=no");
}

function drawImagePair(pair, large, embedded) {
  if (pair == undefined) {
    document.write("undefined");
    return;
  }

  var currentImages = imageSets[pair];
  var numImages = currentImages.length;

  if (embedded) {
    document.write("<table width=256 style=\"float: right\"><tr>");
  } else {
    document.write("<table><tr>");
  }
  if (embedded) {
    document.write("<tr><td style=\"font-size: 10pt; text-align: center\" valign=middle colspan=" + numImages + ">");
    document.write("Click on an image to view an enlarged version of these and additional before and after photos.");
    document.write("</td></tr>");
  }
  for (var i = 0; i < numImages; i++) {
    document.write("<td align=");
    if (numImages == 1) {
      document.write("center");
    } else if (i == 0) {
      document.write("right");
    } else if (i == numImages - 1) {
      document.write("left");
    } else {
      document.write("center");
    }
    document.write(" valign=middle>");
    var fileName;
    var imageWidth;
    if (large) {
      fileName = "\"/images/large/" + currentImages[i] + ".jpg\"";
      //imageWidth = " width=256";
    } else {
      fileName = "\"/images/small/" + currentImages[i] + ".jpg\"";
      imageWidth = " width=128";
    }
    if (!large) {
      var set;
      var index;
      if (embedded) {
        set = categoryForPair(pair);
        index = 0;
      } else {
        set = -1;
        index = pair;
      }
      document.write("<a title=\"Click for larger image\" onmouseover=\"window.status='Click for larger image'; return true\" onmouseout=\"window.status=' '; return true\" href=\"javascript:openImageViewer(" + set + "," + index + "," + embedded + ")\">");
    }
    document.write("<img border=0" + imageWidth + " src=" + fileName + ">");
    if (!large) {
      document.write("</a>");
    }
    document.write("</td>");
  }
  document.write("</tr>");

  if (large && numImages == 2) {
    document.write("<tr><td align=center>Before</td><td align=center>After</td></tr>");
  }

  if (!embedded) {
    document.write("<tr><td style=\"font-size: 10pt; text-align: center\" valign=middle colspan=" + numImages + ">");
    if (captions[currentImages[0]] != undefined) {
      document.write(captions[currentImages[0]]);
    }
    document.write("</td></tr>");
  }

  document.write("</table>");
}

function drawAllImages() {
  document.write("<table>");
  for (var i = 0; i < imageSets.length - 1; i = i + 2) {
    document.write("<tr><td align=center valign=top width=\"50%\">");
    drawImagePair(i, false, false);
    document.write("</td><td align=center valign=top width=\"50%\">");
    if (i + 1 < imageSets.length) {
      drawImagePair(i + 1, false, false);
    }
    document.write("</td></tr>");
  }
  document.write("</table>");
}

function initialize() {
  initializeImageSets();
  initializeCaptions();
  initializeCategories();
}

function initializeImageSets() {
  imageSets = new Array();
  for (var i = 1; i < 98; i = i + 2) {
    imageSets.push(new Array(i, i + 1));
  }
  imageSets.push(new Array(99, 100, 101));
  imageSets.push(new Array(102, 103));
  imageSets.push(new Array(104, 105, 106));
  for (var i = 107; i < 118; i = i + 2) {
    imageSets.push(new Array(i, i + 1));
  }
  var temp = new Array();
  temp[0] = 119;
  imageSets.push(temp);
}

function initializeCaptions() {
  captions = new Array();
  captions[1]="Upper blepharoplasty established a platform for upper eyelid makeup ";
  captions[3]="Upper blepharoplasty. Surgery made it unnecessary to arch the brows to assist eyelid lifting.";
  captions[5]="Upper blepharoplasty also gave better definition to the upper eyelid crease.";
  captions[7]="Prior to this blepharoplasty, excess upper lid skin diminished the patient's upper field of vision.";
  captions[9]="Lower and upper eyelid blepharoplasty.";
  captions[11]="Lower and upper eyelid blepharoplasty.";
  captions[13]="Close-up view of upper and lower eyelid blepharoplasty, along with full-face laser treatment.";
  captions[15]="Extreme example of lower eyelid blepharoplasty.";
  captions[17]="This woman wanted to achieve a more feminine brow - high and arching.  This also enhanced her eyelid opening.";
  captions[19]="Brow lift for hereditary facial nerve palsy.  Lower eyelid ectropion (sagging) was also corrected.";
  captions[21]="Brow lift for left acquired facial nerve palsy (Bell's Palsy).  Left lower eyelid ectropion (sagging) was also corrected.";
  captions[23]="Left brow droop was corrected by unilateral brow lift. ";
  captions[25]="Mid-face lift can impart a remarkable cheek elevation that can be varied based upon each patient's wishes.";
  captions[27]="A more subtle lift was this patient's desired result.  This achieved a more youthful and vital appearance.";
  captions[29]="Botox significantly reduced horizontal forehead furrows, along with the vertical lines at the glabella.";
  captions[31]="Full face laser treatment significantly reduced facial wrinkles.";
  captions[33]="Perioral laser treatment reduced the vertical lines around the lips and eliminated the problem of lipstick <i>bleeding</i> beyond the vermilion border of the lips.";
  captions[35]="Full face laser treatment significantly reduced wrinkles throughout the face.";
  captions[37]="Right upper lid ptosis repair with bilateral upper lid blepharoplasty.";
  captions[39]="Bilateral ptosis repair with more correction required for the right upper lid.";
  captions[41]="Bilateral ptosis repair with bilateral upper lid blepharoplasty.";
  captions[43]="Bilateral ptosis repair with bilateral upper lid blepharoplasty.";
  captions[45]="Bilateral congenital ptosis repair.";
  captions[47]="Right upper lid congenital ptosis repair.";
  captions[49]="Right upper lid congenital ptosis repair.";
  captions[51]="Bilateral ptosis repair with upper and lower lid blepharoplasty.";
  captions[53]="Bilateral ptosis repair with upper and lower lid blepharoplasty.";
  captions[55]="Right upper lid ptosis repair.";
  captions[57]="Bilateral ptosis repair with upper lid blepharoplasty.";
  captions[59]="Bilateral ptosis repair with upper and lower lid blepharoplasty.";
  captions[61]="Bilateral ptosis repair with upper and lower lid blepharoplasty.";
  captions[63]="Cicatricial ectropion of the right lower lid repaired using a full-thickness skin graft.";
  captions[65]="Cicatricial ectropion of the right lower lid repaired using a full-thickness skin graft.";
  captions[67]="Mechanical ectropion of the right lower lid repaired without an incision using the tarsal rotation suture technique.";
  captions[69]="Involutional ectropion of both lower lids - caused by age-related horizontal lower lid elongation.";
  captions[71]="Involutional entropion (inward turning) of the right lower lid.";
  captions[73]="Basal cell carcinoma at the central portion of the left lower lid.";
  captions[75]="Cystic basal cell carcinoma at the central portion of the left lower lid.";
  captions[77]="Basal cell carcinoma involving the entire right lower lid.";
  captions[79]="Basal cell carcinoma overlying the tear drainage system.";
  captions[81]="Basal cell carcinoma of the right lower lid, involving a portion of the tear drainage system - repaired using a full thickness skin graft with repair of the tear drainage system.";
  captions[83]="Malignant melanoma involving the entire left lower lid and the lower surface of the eye.";
  captions[85]="Malignant melanoma at the lateral aspect of the left lower lid.";
  captions[87]="Bilateral upper eyelid retraction secondary to Graves' disease.";
  captions[89]="Right upper eyelid retraction secondary to Graves' disease.";
  captions[91]="Right upper eyelid retraction in a child.";
  captions[93]="Retraction of all four eyelids secondary to Graves' disease.";
  captions[95]="Retraction of the right lower eyelid secondary to Graves' disease.";
  captions[97]="Retraction of both lower eyelids secondary to Graves' disease.";
  captions[99]="Vascular tumor at the medial aspect of the right orbit.";
  captions[102]="Representation and CT scan of an orbital floor (blowout) fracture.";
  captions[104]="This patient has diminished right eye movement in upgaze owing to eye muscle entrapment in the blowout fracture site.";
  captions[107]="Representation of the 3 potential sites of bony disruption in a trimalar (tripod) fracture. Ct scan showing left trimalar fracture with 2 fracture sites.";
  captions[109]="Right temple and upper lid laceration.";
  captions[111]="Right upper lid full-thickness laceration.";
  captions[113]="Old trauma left a left lower eyelid margin notch.";
  captions[115]="Congenital orbital tumor - dermoid cyst.";
  captions[117]="Kohn-Romano (blepharophimosis) syndrome consisting of ptosis (drooping upper lids), blepharophimosis (horizontally shortened eyelids), epicanthus inversus (extra skin fold originating at the inner portion of the lower lids extending to the inner canthus), telecanthus (apparent excess separation of both eyes).";
  captions[119]="Anatomy of the left tear drainage system.";
}

function initializeCategories() {
  categories = new Array();
  categories[0] = "Upper Lid Blepharoplasty";
  categories[1] = "Lower Lid Blepharoplasty";
  categories[2] = "Brow Lift";
  categories[3] = "Cheek (mid-face) Lift";
  categories[4] = "Botox for Wrinkles";
  categories[5] = "Laser Facial Resurfacing";
  categories[6] = "Ptosis Repair";
  categories[7] = "Ectropion Repair";
  categories[8] = "Entropion Repair";
  categories[9] = "Skin Cancer Surgery";
  categories[10] = "Tear Drainage System";
  categories[11] = "Thyroid (Graves') Disease";
  categories[12] = "Orbital Tumors";
  categories[13] = "Trauma - Fractures";
  categories[14] = "Trauma - Lacerations";
  categories[15] = "Scar Excision & Revision";
  categories[16] = "Congenital Abnormalities";

  categorySets = new Array();
  categorySets[0] = new Array(0,1,2,3);
  categorySets[1] = new Array(4,5,6,7);
  categorySets[2] = new Array(8,9,10,11);
  categorySets[3] = new Array(12,13);
  categorySets[4] = new Array(); categorySets[4][0] = 14;
  categorySets[5] = new Array(15,16,17);
  categorySets[6] = new Array(19,27,22,23,24,20,21,28,25,26,29,30,18);
  categorySets[7] = new Array(31,32,33,34);
  categorySets[8] = new Array(); categorySets[8][0] = 35;
  categorySets[9] = new Array(36,37,38,39,40,41,42);
  categorySets[10] = new Array(); categorySets[10][0] = 58;
  categorySets[11] = new Array(43,44,45,46,47,48);
  categorySets[12] = new Array(); categorySets[12][0] = 49;
  categorySets[13] = new Array(50,51,52,53,54);
  categorySets[14] = new Array(53,54);
  categorySets[15] = new Array(); categorySets[15][0] = 55;
  categorySets[16] = new Array(56,57);
}

function categoryForPair(pair) {
  for (var i = 0; i < categorySets.length; i++) {
    var currentSet = categorySets[i];
    for (var j = 0; j < currentSet.length; j++) {
      if (currentSet[j] == pair) {
        return i;
      }
    }
  }
  return -1;
}


function copyrightStatement() {
  document.write("<span style=\"font-size: 8pt\">Photographs Copyright &copy;2008, Roger Kohn, M.D.  All Rights Reserved.</span>");
}

initialize();
