/***************************************************************************
* Create a photo object                                                    *
***************************************************************************/
function photo(id, galleries_id, photo_ref, section_code, src, width, height, caption, thumbnail, thumbnail_width, thumbnail_height, home, gallery, description, takendate, photographer, location, item_price, purchase_instruction) {
	this.id = id;
	this.galleries_id = galleries_id;
	this.photo_ref = photo_ref;
	this.section_code = section_code;
	this.src = src;
	this.width = width;
	this.height = height;
	this.caption = caption;
	this.thumbnail = thumbnail;
	this.thumbnail_width = thumbnail_width;
	this.thumbnail_height = thumbnail_height;
	this.home = home;
	this.gallery = gallery;
	this.description = description;
	this.takendate = takendate;
	this.photographer = photographer;
	this.location = location;
	this.item_price = item_price;
	this.purchase_instruction = purchase_instruction;
}
/***************************************************************************
* Create a gallery object                                                  *
***************************************************************************/

function gallery(id,featured_images,title,section_code) {
	this.id = id;
	this.featured_images = featured_images;
	this.title = title;
	this.section_code = section_code;}

/***************************************************************************
* Select a random value from a comma separated list                        *
***************************************************************************/
function randomListVal(list) {
	arrayVals = list.split(',');
	pos = Math.round(Math.random() * (arrayVals.length - 1));
	debug('Returning ' + arrayVals[pos] + ' as random image');
	return arrayVals[pos];
}

/***************************************************************************
* img = reference to image object in which to show image                   *
***************************************************************************/
function showHomeImage(img) {

	imageID = randomListVal('1601049,1601016');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if (!basic) {
			img.src = photos[j].src;
			img.width = photos[j].width;
			img.height = photos[j].height;
			}
			else {
				newImage = new Image(photos[j].width,photos[j].height);
				newImage.src = photos[j].src;
				document.images[img.name] = newImage;
				debug(newImage.src);
			}
			break;
		}
	}
}

/***************************************************************************
* Show a random image on home page from featured images                    *
***************************************************************************/
function showHomeImageInline() {
	
	imageID = randomListVal('1601049,1601016');
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			if ('gallery' != '') {
						if (photos[j].galleries_id != '') {
						document.write('<a href="' + photos[j].section_code + '_' + photos[j].galleries_id + '.html">');
						}
						else {
						document.write('<a href="gallery.html">');
						}
			}
			document.write('<img src="' + photos[j].src + '" width="' + photos[j].width + '" height="' + photos[j].height + '" class="mainhomepageimage" id="mainSample" name="mainSample" alt="' + photos[j].caption  + '" border="0">');
			if ('gallery' != '') {
				document.write('</a>');
			}
			break;
		}
	}
	
}

/***************************************************************************
* Show the next image in a gallery.  field = hidden field containing       *
* image_id                                                                 *
*  img = reference to image object in which to show image                  *
***************************************************************************/
function next(field,img) {

	debug('IN next');
	imageID = field.value;
	
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			break;
		}
	}
	debug('image is ' + j);
	nextImg = -1;
	k= j + 1;
	while (nextImg < 0) {
		for (; k < photos.length; k++) {
			debug('testing image ' + k + ': gallery = ' + photos[k].galleries_id + '(existing: ' + photos[j].galleries_id + ')');
			if (photos[k].galleries_id == photos[j].galleries_id) {
				nextImg = k;
				debug('setting  nextImg = ' + k);
				break;
			}
		}
		if (nextImg == -1) {
			k = 0;
		}
	}
	if (nextImg != -1) {
		updateImage(nextImg, field,img);
	}


}


/***************************************************************************
* Set a new image on the gallery detail page given its array position      *
***************************************************************************/
function updateImage (nextImg, field,img) {
	debug('Updating image');
	if (!basic && !((0) || (0))) {
		debug('In updateImage');
		debug('setting  img src = ' + photos[nextImg].src);
		
					
			document.getElementById('imagePhoto').innerHTML = '<img class="mainphoto" src="' + photos[nextImg].src + ' " id="mainPic" name="mainPic" width="' + photos[nextImg].width + '" height="' + photos[nextImg].height + '" alt="' + photos[nextImg].caption + '">';
						field.value = photos[nextImg].id;
			document.getElementById('imageTitle').innerHTML = photos[nextImg].caption;
									document.title = 'Doug Norman Photography: ' + photos[nextImg].caption;
										/* apply 'blank' classname to element where */			if ( photos[nextImg].caption == '') {
				document.getElementById('imageTitle').style.className = 'blank';
			}
			else {
				document.getElementById('imageTitle').style.className = 'normal';
			}
						temp = '';
			if (photos[nextImg].description != '') {
				temp = temp +  '<p id="imageDescription">' + photos[nextImg].description + '</p>';
			}
						if (photos[nextImg].photo_ref != '') {
				temp = temp + '<p class="imageinfo" id="imageRef"><strong>Ref: </strong>' + photos[nextImg].photo_ref + '</p>';
			}
						if (photos[nextImg].takendate != '') {
				debug('Resetting taken date');
				temp = temp + '<p class="imageinfo" id="imageDate"><strong>Date: </strong>' + photos[nextImg].takendate + '</p>';
			}
			
			if (photos[nextImg].location != '') {
				debug('Resetting location');
				temp = temp + '<p class="imageinfo" id="imageLocation"><strong>Location: </strong>' +  photos[nextImg].location + '</p>';
			}
			
			if (photos[nextImg].photographer != '') {
				debug('Resetting photographer');
				temp = temp + '<p class="imageinfo" id="imagePhotographer"><strong>Photographer: </strong>' + photos[nextImg].photographer + '</p>';
			}
			if (temp != '') {				temp = temp + '<div class="spacer"></div>';			}					if (temp == '') {
			document.getElementById('imageDetails').style.display = 'none';
		}
		else {
			document.getElementById('imageDetails').style.display = 'block';
		}
		document.getElementById('imageDetails').innerHTML =temp;	
		
	}
	else {
		debug('Redirecting to id ' + photos[nextImg].id);
		window.location = 'photo_' + photos[nextImg].id + '.html';
	}
}

/***************************************************************************
* Show the previous image for a gallery. field = hidden field containing   *
* image_id                                                                 *
*  img = reference to image object in which to show image                  *
***************************************************************************/
function previous(field,img) {


	imageID = field.value;
	for (j = 0; j < photos.length; j++) {
		if (photos[j].id == imageID) {
			break;
		}
	}
	debug('image is ' + j);
	nextImg = -1;
	k = j -1;
	while (nextImg < 0) {
		for (; k >= 0; k--) {
			if (photos[k].galleries_id == photos[j].galleries_id) {
				nextImg = k;
				break;
			}
		}
		if (nextImg == -1) {
			k = photos.length -1;
		}
	}
	if (nextImg != -1) {
		updateImage(nextImg, field,img);	
	}
}

/***************************************************************************
* Pick a photo at random from the featured images of a gallery.
        *
* Gallery_id = id of gallery to choose                                     *
* 
 img = reference to html image                                       *
* in which to show image                                                   *
***************************************************************************/
function showGalleryImage(gallery_id, img) {
	debug('Gallery = ' + gallery_id);
	for (i = 0; i < galleries.length; i++) {
		if (galleries[i].id == gallery_id) {
			imageID = randomListVal(galleries[i].featured_images);
				for (j = 0; j < photos.length; j++) {
					if (photos[j].id == imageID) {
						
						img.src = photos[j].thumbnail;
						img.width = photos[j].thumbnail_width;
						img.height = photos[j].thumbnail_height;
						
						break;
					}
				}
			break;
		}
	} 
	}

/***************************************************************************
* If we have dynamic HTML                                                  *
*  replace the galleries link with a list that                             *
* doesn't include the current gallery                                      *
***************************************************************************/
function showGalleries(gallery_id) {
	debug('Showing links for gallery ' + gallery_id);
	
	if (!basic) {
		temp = '';
		for (i = 0; i < galleries.length; i++) {
			debug('Testing gallery ' + galleries[i].id);
			
			if (galleries[i].id != gallery_id) {
				debug('Adding link');
				if (temp != '') {
					temp = temp + ' | ';
				}
				temp = temp + '<a href="gallery_' + galleries[i].id + '.html">' + galleries[i].title + '</a>';
			}
		}
		document.all.galleryLinks.innerHTML = 'Other galleries: ' + temp;
	}
}
/***************************************************************************
* Create the array of Photo objects                                        *
***************************************************************************/
photos = new Array();
photos[0] = new photo(1600824,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON0011.jpg',600,244,'','http://www1.clikpic.com/dougboy/images/DNP_CON0011_thumb.jpg',130, 53,0, 0,'','','Doug Norman','','','');
photos[1] = new photo(1600832,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON003.jpg',600,750,'','http://www1.clikpic.com/dougboy/images/DNP_CON003_thumb.jpg',130, 163,0, 1,'','','Doug Norman','','','');
photos[2] = new photo(1600826,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON002.jpg',600,257,'','http://www1.clikpic.com/dougboy/images/DNP_CON002_thumb.jpg',130, 56,0, 0,'','','Doug Norman','','','');
photos[3] = new photo(1600835,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON006.jpg',600,750,'','http://www1.clikpic.com/dougboy/images/DNP_CON006_thumb.jpg',130, 163,0, 0,'','','Doug Norman','','','');
photos[4] = new photo(1600836,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON007.jpg',600,273,'','http://www1.clikpic.com/dougboy/images/DNP_CON007_thumb.jpg',130, 59,0, 0,'','','Doug Norman','','','');
photos[5] = new photo(1600834,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON004.jpg',221,600,'','http://www1.clikpic.com/dougboy/images/DNP_CON004_thumb.jpg',130, 353,0, 0,'','','Doug Norman','','','');
photos[6] = new photo(1600838,'109194','','gallery','http://www1.clikpic.com/dougboy/images/DNP_CON008.jpg',600,273,'','http://www1.clikpic.com/dougboy/images/DNP_CON008_thumb.jpg',130, 59,0, 0,'','','Doug Norman','','','');
photos[7] = new photo(1601016,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M005.jpg',400,400,'','http://www1.clikpic.com/dougboy/images/DNP_M005_thumb.jpg',130, 130,1, 0,'','','Doug Norman','','','');
photos[8] = new photo(1601017,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M006.jpg',400,400,'','http://www1.clikpic.com/dougboy/images/DNP_M006_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[9] = new photo(1601021,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M011.jpg',400,400,'','http://www1.clikpic.com/dougboy/images/DNP_M011_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[10] = new photo(1601022,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M013.jpg',400,400,'','http://www1.clikpic.com/dougboy/images/DNP_M013_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[11] = new photo(1601026,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M015.jpg',600,437,'','http://www1.clikpic.com/dougboy/images/DNP_M015_thumb.jpg',130, 95,0, 0,'','','Doug Norman','','','');
photos[12] = new photo(1601028,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M016.jpg',600,295,'','http://www1.clikpic.com/dougboy/images/DNP_M016_thumb.jpg',130, 64,0, 0,'','','Doug Norman','','','');
photos[13] = new photo(1601031,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M017.jpg',400,256,'','http://www1.clikpic.com/dougboy/images/DNP_M017_thumb.jpg',130, 83,0, 0,'','','Doug Norman','','','');
photos[14] = new photo(1601038,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M020.jpg',600,350,'','http://www1.clikpic.com/dougboy/images/DNP_M020_thumb.jpg',130, 76,0, 0,'','','Doug Norman','','','');
photos[15] = new photo(1601033,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M018.jpg',214,400,'','http://www1.clikpic.com/dougboy/images/DNP_M018_thumb.jpg',130, 243,0, 0,'','','Doug Norman','','','');
photos[16] = new photo(1601034,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M019.jpg',341,400,'','http://www1.clikpic.com/dougboy/images/DNP_M019_thumb.jpg',130, 152,0, 0,'','','Doug Norman','','','');
photos[17] = new photo(1601037,'109204','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M021.jpg',294,400,'','http://www1.clikpic.com/dougboy/images/DNP_M021_thumb.jpg',130, 177,0, 0,'','','Doug Norman','','','');
photos[18] = new photo(1601049,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M001.jpg',400,400,'HAIR','http://www1.clikpic.com/dougboy/images/DNP_M001_thumb.jpg',130, 130,1, 0,'','','Doug Norman','','','');
photos[19] = new photo(1601051,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M002.jpg',400,400,'HAIR','http://www1.clikpic.com/dougboy/images/DNP_M002_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[20] = new photo(1601052,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M003.jpg',400,400,'HAIR','http://www1.clikpic.com/dougboy/images/DNP_M003_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[21] = new photo(1601055,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M004.jpg',400,400,'HAIR','http://www1.clikpic.com/dougboy/images/DNP_M004_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[22] = new photo(1601059,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M007.jpg',400,400,'HAIR & FACE','http://www1.clikpic.com/dougboy/images/DNP_M007_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[23] = new photo(1601062,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M009.jpg',400,400,'','http://www1.clikpic.com/dougboy/images/DNP_M009_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[24] = new photo(1601063,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M010.jpg',400,400,'HANDS','http://www1.clikpic.com/dougboy/images/DNP_M010_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[25] = new photo(1601066,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M012.jpg',400,400,'HAIR & FACE','http://www1.clikpic.com/dougboy/images/DNP_M012_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[26] = new photo(1601067,'109207','','section143770','http://www1.clikpic.com/dougboy/images/DNP_M014.jpg',400,400,'HAIR','http://www1.clikpic.com/dougboy/images/DNP_M014_thumb.jpg',130, 130,0, 0,'','','Doug Norman','','','');
photos[27] = new photo(1600893,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD001.jpg',600,454,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD001_thumb.jpg',130, 98,0, 1,'','','Doug Norman','','','');
photos[28] = new photo(1600895,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD002.jpg',599,449,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD002_thumb.jpg',130, 97,0, 0,'','','Doug Norman','','','');
photos[29] = new photo(1600896,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD003.jpg',600,488,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD003_thumb.jpg',130, 106,0, 0,'','','Doug Norman','','','');
photos[30] = new photo(1600901,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD005.jpg',600,450,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD005_thumb.jpg',130, 98,0, 0,'','','Doug Norman','','','');
photos[31] = new photo(1600903,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD006.jpg',600,500,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD006_thumb.jpg',130, 108,0, 0,'','','Doug Norman','','','');
photos[32] = new photo(1600905,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD007.jpg',429,600,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD007_thumb.jpg',130, 182,0, 0,'','','Doug Norman','','','');
photos[33] = new photo(1600908,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD008.jpg',600,474,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD008_thumb.jpg',130, 103,0, 0,'','','Doug Norman','','','');
photos[34] = new photo(1600909,'109195','','gallery','http://www1.clikpic.com/dougboy/images/DNP_TRAD009.jpg',600,496,'','http://www1.clikpic.com/dougboy/images/DNP_TRAD009_thumb.jpg',130, 107,0, 0,'','','Doug Norman','','','');

/***************************************************************************
* Create the array of Gallery objects                                      *
***************************************************************************/
galleries = new Array();
galleries[0] = new gallery(109194,'1600832','CONTEMPORARY PORTRAITS','gallery');
galleries[1] = new gallery(109204,'1601038,1601037,1601034,1601033,1601031,1601028,1601026,1601022,1601021,1601017','MODEL FASHION','section143770');
galleries[2] = new gallery(109207,'1601067,1601066,1601063,1601062,1601059,1601055,1601052,1601051,1601049','MODEL SPECIFICS','section143770');
galleries[3] = new gallery(109195,'1600893','TRADITIONAL PORTRAITS','gallery');

