﻿//===========================================================================
// Provides image groupings given image file names. Allows lookup of 
// associated thumbnails and their full size image.
//===========================================================================


//List the images here that will be grouped for display
var imageGroupings = new Dictionary();

/*
//Dressers group of images
var dressers = new ImageGroup();

// Example config:
dressers.GroupName = "Dressers";
dressers.GroupTitle = "Some dressers";
dressers.RelatedImages.push(new GroupedImage("gallery_2.jpg", "Dresser and Wardrobe"));
dressers.RelatedImages.push(new GroupedImage("gallery_9.jpg", "Bed"));
dressers.RelatedImages.push(new GroupedImage("gallery_12.jpg", "Bed and Wardbrobe"));
dressers.RelatedImages.push(new GroupedImage("gallery_17.jpg", "Drawers"));

imageGroupings.Add("gallery_2.jpg", dressers);
imageGroupings.Add("gallery_9.jpg", dressers);
imageGroupings.Add("gallery_12.jpg", dressers);
imageGroupings.Add("gallery_17.jpg", dressers);

//Wardrobes
var wardrobes = new ImageGroup();
wardrobes.GroupName = "Wardrobes";
wardrobes.GroupTitle = "Some wardrobes";
wardrobes.RelatedImages.push(new GroupedImage("gallery_7.jpg", "Caption A"));
wardrobes.RelatedImages.push(new GroupedImage("gallery_8.jpg", "Caption B"));
wardrobes.RelatedImages.push(new GroupedImage("gallery_10.jpg", "Caption C"));

imageGroupings.Add("gallery_7.jpg", wardrobes);
imageGroupings.Add("gallery_8.jpg", wardrobes);
imageGroupings.Add("gallery_10.jpg", wardrobes);
*/

//Gallery page 1:
var image37 = new ImageGroup();
image37.GroupName = "Cupboards";
image37.GroupTitle = "Cupboards";
image37.RelatedImages.push(new GroupedImage("gallery_37a.jpg", ""));
image37.RelatedImages.push(new GroupedImage("gallery_37b.jpg", ""));
image37.RelatedImages.push(new GroupedImage("gallery_37c.jpg", ""));
imageGroupings.Add("gallery_37a.jpg", image37);
imageGroupings.Add("gallery_37b.jpg", image37);
imageGroupings.Add("gallery_37c.jpg", image37);

var image38 = new ImageGroup();
image38.GroupName = "Bedroom";
image38.GroupTitle = "Bedroom";
image38.RelatedImages.push(new GroupedImage("gallery_38a.jpg", ""));
image38.RelatedImages.push(new GroupedImage("gallery_38b.jpg", ""));
image38.RelatedImages.push(new GroupedImage("gallery_38c.jpg", ""));
image38.RelatedImages.push(new GroupedImage("gallery_38d.jpg", ""));
imageGroupings.Add("gallery_38a.jpg", image38);
imageGroupings.Add("gallery_38b.jpg", image38);
imageGroupings.Add("gallery_38c.jpg", image38);
imageGroupings.Add("gallery_38d.jpg", image38);

var image39 = new ImageGroup();
image39.GroupName = "Cabinet";
image39.GroupTitle = "Cabinet";
image39.RelatedImages.push(new GroupedImage("gallery_39a.jpg", ""));
image39.RelatedImages.push(new GroupedImage("gallery_39b.jpg", ""));
image39.RelatedImages.push(new GroupedImage("gallery_39c.jpg", ""));
image39.RelatedImages.push(new GroupedImage("gallery_39d.jpg", ""));
imageGroupings.Add("gallery_39a.jpg", image39);
imageGroupings.Add("gallery_39b.jpg", image39);
imageGroupings.Add("gallery_39c.jpg", image39);
imageGroupings.Add("gallery_39d.jpg", image39);

var image40 = new ImageGroup();
image40.GroupName = "Desk";
image40.GroupTitle = "Desk";
image40.RelatedImages.push(new GroupedImage("gallery_40a.jpg", ""));
image40.RelatedImages.push(new GroupedImage("gallery_40b.jpg", ""));
image40.RelatedImages.push(new GroupedImage("gallery_40c.jpg", ""));
imageGroupings.Add("gallery_40a.jpg", image40);
imageGroupings.Add("gallery_40b.jpg", image40);
imageGroupings.Add("gallery_40c.jpg", image40);

var image41 = new ImageGroup();
image41.GroupName = "Storage";
image41.GroupTitle = "Storage";
image41.RelatedImages.push(new GroupedImage("gallery_41a.jpg", ""));
image41.RelatedImages.push(new GroupedImage("gallery_41b.jpg", ""));
image41.RelatedImages.push(new GroupedImage("gallery_41c.jpg", ""));
imageGroupings.Add("gallery_41a.jpg", image41);
imageGroupings.Add("gallery_41b.jpg", image41);
imageGroupings.Add("gallery_41c.jpg", image41);

var image42 = new ImageGroup();
image42.GroupName = "Storage";
image42.GroupTitle = "Storage";
image42.RelatedImages.push(new GroupedImage("gallery_42a.jpg", ""));
image42.RelatedImages.push(new GroupedImage("gallery_42b.jpg", ""));
image42.RelatedImages.push(new GroupedImage("gallery_42c.jpg", ""));
imageGroupings.Add("gallery_42a.jpg", image42);
imageGroupings.Add("gallery_42b.jpg", image42);
imageGroupings.Add("gallery_42c.jpg", image42);

var image44 = new ImageGroup();
image44.GroupName = "Cabinet";
image44.GroupTitle = "Cabinet";
image44.RelatedImages.push(new GroupedImage("gallery_44a.jpg", ""));
image44.RelatedImages.push(new GroupedImage("gallery_44b.jpg", ""));
imageGroupings.Add("gallery_44a.jpg", image44);
imageGroupings.Add("gallery_44b.jpg", image44);

var image47 = new ImageGroup();
image47.GroupName = "Cabinet";
image47.GroupTitle = "Cabinet";
image47.RelatedImages.push(new GroupedImage("gallery_47a.jpg", ""));
image47.RelatedImages.push(new GroupedImage("gallery_47b.jpg", ""));
image47.RelatedImages.push(new GroupedImage("gallery_47c.jpg", ""));
imageGroupings.Add("gallery_47a.jpg", image47);
imageGroupings.Add("gallery_47b.jpg", image47);
imageGroupings.Add("gallery_47c.jpg", image47);

var image48 = new ImageGroup();
image48.GroupName = "Cabinet";
image48.GroupTitle = "Cabinet";
image48.RelatedImages.push(new GroupedImage("gallery_48a.jpg", ""));
image48.RelatedImages.push(new GroupedImage("gallery_48b.jpg", ""));
image48.RelatedImages.push(new GroupedImage("gallery_48c.jpg", ""));
imageGroupings.Add("gallery_48a.jpg", image48);
imageGroupings.Add("gallery_48b.jpg", image48);
imageGroupings.Add("gallery_48c.jpg", image48);

var image3 = new ImageGroup();
image3.GroupName = "Cabinet";
image3.GroupTitle = "Cabinet";
image3.RelatedImages.push(new GroupedImage("gallery_3a.jpg", ""));
image3.RelatedImages.push(new GroupedImage("gallery_3b.jpg", ""));
image3.RelatedImages.push(new GroupedImage("gallery_3c.jpg", ""));
imageGroupings.Add("gallery_3a.jpg", image3);
imageGroupings.Add("gallery_3b.jpg", image3);
imageGroupings.Add("gallery_3c.jpg", image3);

var image4 = new ImageGroup();
image4.GroupName = "Cabinet";
image4.GroupTitle = "Cabinet";
image4.RelatedImages.push(new GroupedImage("gallery_4a.jpg", ""));
image4.RelatedImages.push(new GroupedImage("gallery_4b.jpg", ""));
image4.RelatedImages.push(new GroupedImage("gallery_4c.jpg", ""));
image4.RelatedImages.push(new GroupedImage("gallery_4d.jpg", ""));
imageGroupings.Add("gallery_4a.jpg", image4);
imageGroupings.Add("gallery_4b.jpg", image4);
imageGroupings.Add("gallery_4c.jpg", image4);
imageGroupings.Add("gallery_4d.jpg", image4);

var image9 = new ImageGroup();
image9.GroupName = "Cabinet";
image9.GroupTitle = "Cabinet";
image9.RelatedImages.push(new GroupedImage("gallery_9a.jpg", ""));
image9.RelatedImages.push(new GroupedImage("gallery_9b.jpg", ""));
imageGroupings.Add("gallery_9a.jpg", image9);
imageGroupings.Add("gallery_9b.jpg", image9);

var image12 = new ImageGroup();
image12.GroupName = "Cabinet";
image12.GroupTitle = "Cabinet";
image12.RelatedImages.push(new GroupedImage("gallery_12a.jpg", ""));
image12.RelatedImages.push(new GroupedImage("gallery_12b.jpg", ""));
image12.RelatedImages.push(new GroupedImage("gallery_12c.jpg", ""));
image12.RelatedImages.push(new GroupedImage("gallery_12d.jpg", ""));
imageGroupings.Add("gallery_12a.jpg", image12);
imageGroupings.Add("gallery_12b.jpg", image12);
imageGroupings.Add("gallery_12c.jpg", image12);
imageGroupings.Add("gallery_12d.jpg", image12);

var image13 = new ImageGroup();
image13.GroupName = "Cabinet";
image13.GroupTitle = "Cabinet";
image13.RelatedImages.push(new GroupedImage("gallery_13a.jpg", ""));
image13.RelatedImages.push(new GroupedImage("gallery_13b.jpg", ""));
image13.RelatedImages.push(new GroupedImage("gallery_13c.jpg", ""));
image13.RelatedImages.push(new GroupedImage("gallery_13d.jpg", ""));
imageGroupings.Add("gallery_13a.jpg", image13);
imageGroupings.Add("gallery_13b.jpg", image13);
imageGroupings.Add("gallery_13c.jpg", image13);
imageGroupings.Add("gallery_13d.jpg", image13);

var image20 = new ImageGroup();
image20.GroupName = "Cabinet";
image20.GroupTitle = "Cabinet";
image20.RelatedImages.push(new GroupedImage("gallery_20a.jpg", ""));
image20.RelatedImages.push(new GroupedImage("gallery_20b.jpg", ""));
image20.RelatedImages.push(new GroupedImage("gallery_20c.jpg", ""));
imageGroupings.Add("gallery_20a.jpg", image20);
imageGroupings.Add("gallery_20b.jpg", image20);
imageGroupings.Add("gallery_20c.jpg", image20);

var image34 = new ImageGroup();
image34.GroupName = "Cabinet";
image34.GroupTitle = "Cabinet";
image34.RelatedImages.push(new GroupedImage("gallery_34a.jpg", ""));
image34.RelatedImages.push(new GroupedImage("gallery_34b.jpg", ""));
image34.RelatedImages.push(new GroupedImage("gallery_34c.jpg", ""));
image34.RelatedImages.push(new GroupedImage("gallery_34d.jpg", ""));
imageGroupings.Add("gallery_34a.jpg", image34);
imageGroupings.Add("gallery_34b.jpg", image34);
imageGroupings.Add("gallery_34c.jpg", image34);
imageGroupings.Add("gallery_34d.jpg", image34);


//===========================================================================
// Provides a Dictionary object for client-side java scripts
//===========================================================================

function ImageGroup() 
{
    this.GroupName = "";
    this.GroupTitle = "";
    this.ImageCaption = "";
    this.RelatedImages = new Array();
}

function GroupedImage(filename, caption) {
    this.Filename = filename;
    this.Caption = caption;
    return this;
}

function Lookup(key) 
{
  return(this[key]);
}

function Delete() 
{
  for (c=0; c < Delete.arguments.length; c++) 
  {
    this[Delete.arguments[c]] = null;
  }
  // Adjust the keys (not terribly efficient)
  var keys = new Array()
  for (var i=0; i<this.Keys.length; i++)
  {
    if(this[this.Keys[i]] != null)
      keys[keys.length] = this.Keys[i];
  }
  this.Keys = keys;
}

function Add() 
{
  for (c=0; c < Add.arguments.length; c+=2) 
  {
    // Add the property
    this[Add.arguments[c]] = Add.arguments[c+1];
    // And add it to the keys array
    this.Keys[this.Keys.length] = Add.arguments[c];
  }
}

function Dictionary() 
{
  this.Add = Add;
  this.Lookup = Lookup;
  this.Delete = Delete;
  this.Keys = new Array();
}

//===================================================================
//If the selected image appears in the list of related images display
//up to 4 related image thumbnails underneath.
//===================================================================
function ShowRelatedImages(target)
{
    ClearThumbnails();
    var filename = target.match(/[-_\w]+[.][\w]+$/i)[0];
    var imageGroup = imageGroupings.Lookup(filename);

    if (imageGroup != null) {
        var imageid = "", linkid = "";
        for (var i = 0; i < imageGroup.RelatedImages.length && i < 4;  i++) {
            imageid = "subImage" + i;
            linkid = "subImageLink" + i;
            $(imageid).src = "images/groupedImageThumbs/" + imageGroup.RelatedImages[i].Filename;
            $(linkid).href = "javascript:function(){return false};";
            $(linkid).setAttribute('onClick', "document.getElementById('lightboxImage').setAttribute('src', 'images/" + imageGroup.RelatedImages[i].Filename + "'); document.getElementById('caption').innerHTML='" + imageGroup.RelatedImages[i].Caption + "';");
            $(imageid).show();
            
        } 
        $('bottomThumbs').show();
    }
}

function ClearThumbnails() {
    $('subImage0').hide();
    $('subImage1').hide();
    $('subImage2').hide();
    $('subImage3').hide();
    $('bottomThumbs').hide();
}


