//rev3.40

//******************************************************************
// JW DMN 08/06/2007
//******************************************************************
//Hide page ads on display

function getElementsByStyleClass (className) {
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++){
    if (all[e].className == className){
      elements[elements.length] = all[e];
    }
  }
  return elements;
}

function hideAds(){
	ads = getElementsByStyleClass('ad');
	for (i = 0; i < ads.length; i++){
		ads[i].style.display = 'none';
	}
}

function showAds(){
	ads = getElementsByStyleClass('ad');
	for (i = 0; i < ads.length; i++){
		ads[i].style.display = 'block';
	}
}

//******************************************************************
// JW DMN 12/06/07
//******************************************************************
//Hide flash on page, flash objects go through the overlay otherwise.
function hideFlash(){
	ads = getElementsByStyleClass('flash');
	for (i = 0; i < ads.length; i++){
		ads[i].style.display = 'none';
	}
}

function showFlash(){
	ads = getElementsByStyleClass('flash');
	for (i = 0; i < ads.length; i++){
		ads[i].style.display = 'block';
	}
}
//END***************************************************************
// -----------------------------------------------------------------------------------
//
//	Litebox v1.0
//	A combined effort between detrate and gannon
//	07/03/06
//
//	Source edited from Lightbox v2.02
//	by Lokesh Dhakar - http://www.huddletogether.com
//
//	For more information on this script, visit:
//	http://doknowevil.net/litebox
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
//
// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage = '/img/lb/loading.gif';		
var fileBottomNavCloseImage = '/img/lb/closelabel.gif';
var resizeSpeed = 6;	// controls the speed of the image resizing (1=slowest and 10=fastest)
var borderSize = 10;	//if you adjust the padding in the CSS, you will need to update this variable
var _strlo = String(window.location).toLowerCase();

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;
var tMaxWidth = 100;
var tMaxHeight = 75;

//******************************************************************
// JW DMN 09/20/2007
//******************************************************************
//we need to know it we are dealing with a single image
var singleImage = false;

//******************************************************************

if(resizeSpeed > 10){ resizeSpeed = 10;}
if(resizeSpeed < 1){ resizeSpeed = 1;}
resizeDuration = (11 - resizeSpeed) * 100;

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	hide: function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = $(arguments[i]);
			element.style.display = 'none';
		}
	},
	show: function() {
		for (var i = 0; i < arguments.length; i++) {
			var element = $(arguments[i]);
			element.style.display = '';
		}
	},
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
		element.style.width = w +'px';
	},
	getHeight: function(element) {
		element = $(element);
		return element.offsetHeight;
	},
	setHeight: function(element,h) {
   		element = $(element);
		element.style.height = h +'px';
	},
	setTop: function(element,t) {
	   	element = $(element);
		element.style.top = t +'px';
	},
	setSrc: function(element,src) {
		element = $(element);
		element.src = src; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//
Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var Lightbox = Class.create();

Lightbox.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Loops through anchor tags looking for 
	// 'lightbox' references and applies onclick events to appropriate links. The 2nd section of
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}
		}
		
		
var objBody = document.getElementsByTagName('body').item(0);
		
		var objOverlay = document.createElement('div');
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); return false; }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement('div');
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);

//******************************************************************
// JW DMN 06/04/2007
//******************************************************************
//Create a new container to put the image and data in.
		var objlbcontainer = document.createElement('div');
		objlbcontainer.setAttribute('id','lbcontainer');
		objlbcontainer.style.display = 'block';
		objlbcontainer.style.marginLeft = '30px';
		objLightbox.appendChild(objlbcontainer);
//END***************************************************************	

		var objOuterImageContainer = document.createElement('div');
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		
//******************************************************************
// JW DMN 06/04/2007
//******************************************************************
//Changed the line below to put the OuterImageContainer into a new div.
//had to do this to make the image and data centered on screen. 
		//objLightbox.appendChild(objOuterImageContainer);
		objlbcontainer.appendChild(objOuterImageContainer);
//END***************************************************************

		var objImageContainer = document.createElement('div');
		objImageContainer.setAttribute('id','imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);
	
		
//******************************************************************
// JW DMN 09/13/2007
//******************************************************************
//This code adds the nav div. 
		var nav = document.createElement('div');
		nav.setAttribute('id','nav');
		objImageContainer.appendChild(nav);					
				
			var objPrevLink = document.createElement('a');
			objPrevLink.setAttribute('id','prevLink');
			objPrevLink.setAttribute('href','#');
			nav.appendChild(objPrevLink);
	
				var objPrevImage = document.createElement('img');
				objPrevImage.setAttribute('src', '/img/lb/rev3/prev-button.gif');
				objPrevLink.appendChild(objPrevImage);	
		
			var navNumberDisplay = document.createElement('span');
			navNumberDisplay.setAttribute('id','numberDisplay');
			nav.appendChild(navNumberDisplay);
			
			var objNextLink = document.createElement('a');
			objNextLink.setAttribute('id','nextLink');
			objNextLink.setAttribute('href','#');
			nav.appendChild(objNextLink);
				
				var objNextImage = document.createElement('img');
				objNextImage.setAttribute('src', '/img/lb/rev3/next-button.gif');
				objNextLink.appendChild(objNextImage);
						

			var objImageButtonsCloseLink = document.createElement('a');
			objImageButtonsCloseLink.setAttribute('id','bottomNavClose');
			objImageButtonsCloseLink.setAttribute('href','#');
			objImageButtonsCloseLink.onclick = function() { myLightbox.end(); return false; }
			nav.appendChild(objImageButtonsCloseLink);
			
				var objCloseImage = document.createElement('img');
				objCloseImage.setAttribute('src', '/img/lb/rev3/close-button.gif');
				objImageButtonsCloseLink.appendChild(objCloseImage);

			

					
//END***************************************************************			
		
		var objLightboxImage = document.createElement('img');
		objLightboxImage.setAttribute('id','lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
	
		var objHoverNav = document.createElement('div');
		objHoverNav.setAttribute('id','hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objLoading = document.createElement('div');
		objLoading.setAttribute('id','loading');
		objImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement('a');
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myLightbox.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement('img');
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement('div');
		objImageDataContainer.setAttribute('id','imageDataContainer');
		objImageDataContainer.className = 'clearfix';
		
//******************************************************************
// JW DMN 06/04/2007
//******************************************************************
//Changed the line below to put the objImageDataContainer into a new div.
//had to do this to make the image and data centered on screen. 
		//objLightbox.appendChild(objImageDataContainer);
		objlbcontainer.appendChild(objImageDataContainer);
//END***************************************************************

		var objImageData = document.createElement('div');
		objImageData.setAttribute('id','imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement('div');
		objImageDetails.setAttribute('id','imageDetails');
		objImageData.appendChild(objImageDetails);
	
		var objCaption = document.createElement('span');
		objCaption.setAttribute('id','caption');
		objImageDetails.appendChild(objCaption);	
		
		overlayEffect = new fx.Opacity(objOverlay, { duration: 300 });	
		overlayEffect.hide();
		
		imageEffect = new fx.Opacity(objLightboxImage, { duration: 350, onComplete: function() { imageDetailsEffect.custom(0,1); }});
		imageEffect.hide();
		
		imageDetailsEffect = new fx.Opacity('imageDataContainer', { duration: 400, onComplete: function() { navEffect.custom(0,1); }}); 
		imageDetailsEffect.hide();
		
		navEffect = new fx.Opacity('hoverNav', { duration: 100 });
		navEffect.hide();
	},
	
	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink) {	

		hideSelectBoxes();
		hideAds();
		hideFlash();
		document.getElementById('overlay').style.display = "block";
		
		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);
		overlayEffect.custom(0,0.8);
		
		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
			singleImage = true;
			tRev = false;
			tRev = imageLink.getAttribute('rev');
			tCart = false;
			tImg = "";
					
//******************************************************************
// JW DMN 09/20/2007
//******************************************************************					
//parse the rev tag for information (table-id:thumb path)
					if(tRev){
						args = "";
						args = tRev.split(':');
						if(args.length > 1){
							tCart  = args[0];
							tImg = args[1];
						} else {
							tCart = false;
							tImg = args[0];
						}	
					}
//******************************************************************											
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title'), tImg, tCart));
						
		} else {
		// if image is part of a set..
			singleImage = false;
			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					tRev = false;
					tRev = anchor.getAttribute('rev');
					tCart = false;
					tImg = "";
					
//******************************************************************
// JW DMN 09/20/2007
//******************************************************************					
//parse the rev tag for information (table-id:thumb path)
					if(tRev){
						args = "";
						args = tRev.split(':');
						if(args.length > 1){
							tCart  = args[0];
							tImg = args[1];
						} else {
							tCart = false;
							tImg = args[0];
						}	
					}
//******************************************************************											
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title'), tImg, tCart));
				}
			}
			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		Element.setTop('lightbox', lightboxTop);
		Element.show('lightbox');
		this.changeImage(imageNum);
		
	},	

//******************************************************************
// JW DMN 06/11/2007
//******************************************************************
//This member function writes the tnail images to the page. 
	gallery: function(){
	
		var objLightbox = document.getElementById('lightbox');
		
		if (document.getElementById('thumbnails')){
			//Remove existing tnail div
			  var olddiv = document.getElementById('thumbnails');
			  objLightbox.removeChild(olddiv);
		} 
		
		var objThumbnailDiv = document.createElement('div');
		objThumbnailDiv.setAttribute('id', 'thumbnails');
		objLightbox.appendChild(objThumbnailDiv);
		
		
		//Create image divs within main thumbail div for each image. We limit this to 6 thumbnails so it fits on the page.
		cur = (1+ activeImage); 
		tot = imageArray.length;
		last = ((6+ activeImage) <= tot) ? (5+ activeImage) : imageArray.length;
				
		TN_ID = [];
		
		//Make sure we show the minimum number of images. 
		if ((tot - activeImage) < 5){
			first = (tot-5);
		}else{
			first = activeImage;
		}
		
		for (TN_Counter = first, i = 0; (TN_Counter < imageArray.length) && (TN_Counter < (5 + activeImage)); TN_Counter++, i++) {
		TN_ID[i] = TN_Counter;
		}	
			

			var tnailUpDiv = document.createElement('div');
				tnailUpDiv.setAttribute('id','tnailUpDiv');
				objThumbnailDiv.appendChild(tnailUpDiv);
						var objNextUp = document.createElement('a');
						objNextUp.setAttribute('id','prevLinkTnail');
						objNextUp.setAttribute('href','#');
						tnailUpDiv.appendChild(objNextUp);
						
						//dont show the up arrow if we do not have more thumbnails
						if (cur > 1  && (tot > 5)){					
							var objNextUpImage = document.createElement('img');
							objNextUpImage.setAttribute('src', '/img/lb/rev3/up-button.gif');
							objNextUp.appendChild(objNextUpImage);
							
				//******************************************************************
				// JW DMN 08/06/2007
				//******************************************************************
				//Added additional prev event handler
							document.getElementById('prevLinkTnail').onclick = function() {
								myLightbox.changeImage(activeImage - 1); return false;
							}
				//END***************************************************************
		}
		for (TN_Counter = 0; (TN_Counter < TN_ID.length) && (TN_Counter < 5); TN_Counter++) {
				
			div_id = 'thumbnail' + (1+TN_Counter);
			a_id = 'thumbnailLink' + (1+TN_Counter);
			img_id = 'thumbnailImg' + (1+TN_Counter);
				
			var objThumbnail = document.createElement('div');

			objThumbnailDiv.appendChild(objThumbnail);
					
			var objThumbnailLink = document.createElement('a');
			objThumbnailLink.setAttribute('href', '#');
			
			objThumbnailLink.setAttribute('id', a_id);
			objThumbnail.appendChild(objThumbnailLink);
					
			var objThumbnailImg = document.createElement('img');
			objThumbnailImg.setAttribute('id', img_id);

			objThumbnailLink.appendChild(objThumbnailImg);
		
			
			}

//******************************************************************
// JW DMN 08/04/2007
//******************************************************************
//We add a count div to the tnail display

			var tnailDownDiv = document.createElement('div');
				tnailDownDiv.setAttribute('id','tnailDownDiv');
				objThumbnailDiv.appendChild(tnailDownDiv);
						var objNextDown = document.createElement('a');
						objNextDown.setAttribute('id','nextLinkTnail');
						objNextDown.setAttribute('href','#');
						tnailDownDiv.appendChild(objNextDown);
			if (last < tot){					
							var objNextDownImage = document.createElement('img');
							objNextDownImage.setAttribute('src', '/img/lb/rev3/down-button.gif');
							objNextDown.appendChild(objNextDownImage);
							
				//******************************************************************
				// JW DMN 08/06/2007
				//******************************************************************
				//Added additional next event handler
							document.getElementById('nextLinkTnail').onclick = function() {
								myLightbox.changeImage(activeImage + 1); return false;
							}
				//END***************************************************************
			}
			
		var thumbs = Array();
		var thumbIndices = Array();
		var links = Array();
		var thumbIndex = activeImage;
		var galleryLength = imageArray.length;
		
		thumbs[0] = 0;
		thumbIndices[0] = '';
		for (var i=1; i<=5; i++) {
			thumbs[i] = document.getElementById('thumbnailImg'+i);
			thumbIndices[i] = 0;
		}
		
//******************************************************************
// JW DMN 09/13/2007
//******************************************************************
//Check for thumbnail image

//******************************************************************
// JW DMN 09/13/2007
//******************************************************************	
//if there are less than 3 thumbnails hide the border on the center image.		
		if(galleryLength < 3){
			document.getElementById('thumbnailImg3').style.border = '0px solid white';
		}else{
			document.getElementById('thumbnailImg3').style.border = '4px solid white';
		}
//******************************************************************	
		if(galleryLength > 2){
			// first set middle thumbnail to current image
			if (imageArray[thumbIndex][2]) {
				//we have a thumbnail woohoo!
				thumbs[3].src = imageArray[thumbIndex][2];
			} else {
				//we do not have a thumbnail, figure out which dimension to scale the image.
				//set image to 0 width and height, this prevents the "flashing" effect seen on ff which is due to the delay in the following preload code.
				document.getElementById('thumbnailImg3').style.height = '0px';
				document.getElementById('thumbnailImg3').style.width = '0px';
				tn3 = new Image;		
				tn3.onload=function(){
					//check if the thumbnail is too big for the div
					if(tn3.width >= tMaxWidth || tn3.height >= tMaxHeight){
						//set either the width or the height, not both!
						//(tMaxWidth - tMaxHeight) added for sqaure images, doh!
						if((Math.abs(tn3.height - tMaxHeight) + (tMaxWidth - tMaxHeight)) > Math.abs(tn3.width - tMaxWidth)){
							document.getElementById('thumbnailImg3').style.height = '75px';
							document.getElementById('thumbnailImg3').style.width = '';
						}else{
							document.getElementById('thumbnailImg3').style.width = '100px';
							document.getElementById('thumbnailImg3').style.height = '';
						}					
					}
				}
				tn3.src = imageArray[thumbIndex][0];
				thumbs[3].src = imageArray[thumbIndex][0];			 
			}
			document.getElementById('thumbnailLink3').onclick =  function() {
				return false;
			}
		}else{
				//if we do not have a image for this position put xclear as a placeholder.
				thumbs[3].src = '/i/xclear.gif'
		}

		if(galleryLength > 1){
			// now set first 2 thumbnails to previous 2 images
			thumbIndex = (thumbIndex == 0 ? galleryLength-1 : thumbIndex-1);
			thumbIndices[2] = thumbIndex;
			if (imageArray[thumbIndex][2]) {
				thumbs[2].src = imageArray[thumbIndex][2];
			} else {
				document.getElementById('thumbnailImg2').style.height = '0px';
				document.getElementById('thumbnailImg2').style.width = '0px';
				tn2 = new Image;			
				tn2.onload=function(){
					//check if the thumbnail is too big for the div
					if(tn2.width >= tMaxWidth || tn2.height >= tMaxHeight){
						//set either the width or the height, not both!
						if((Math.abs(tn2.height - tMaxHeight) + (tMaxWidth - tMaxHeight)) > Math.abs(tn2.width - tMaxWidth)){
							document.getElementById('thumbnailImg2').style.height = '75px';
							document.getElementById('thumbnailImg2').style.width = '';
						}else{
							document.getElementById('thumbnailImg2').style.width = '100px';
							document.getElementById('thumbnailImg2').style.height = '';
						}						
					}
				}
				tn2.src = imageArray[thumbIndex][0];
				thumbs[2].src = imageArray[thumbIndex][0];				
			}
			document.getElementById('thumbnailLink2').onclick =  function() {
				myLightbox.changeImage(thumbIndices[2]); return false;
			}
		}else{
				thumbs[2].src = '/i/xclear.gif'
		}

		
		if(galleryLength > 0){
			thumbIndex = (thumbIndex == 0 ? galleryLength-1 : thumbIndex-1);
			thumbIndices[1] = thumbIndex;
			
			if (imageArray[thumbIndex][2]) {
				thumbs[1].src = imageArray[thumbIndex][2];
			} else {
				document.getElementById('thumbnailImg1').style.height = '0px';
				document.getElementById('thumbnailImg1').style.width = '0px';
				tn1 = new Image;
				tn1.onload=function(){
					//check if the thumbnail is too big for the div
					if(tn1.width >= tMaxWidth || tn1.height >= tMaxHeight){
						//set either the width or the height, not both!
						if((Math.abs(tn1.height - tMaxHeight) + (tMaxWidth - tMaxHeight)) > Math.abs(tn1.width - tMaxWidth)){
							document.getElementById('thumbnailImg1').style.height = '75px';
							document.getElementById('thumbnailImg1').style.width = '';
						}else{
							document.getElementById('thumbnailImg1').style.width = '100px';
							document.getElementById('thumbnailImg1').style.height = '';
						}						
					}
				}
				tn1.src = imageArray[thumbIndex][0];
				thumbs[1].src = imageArray[thumbIndex][0];
			}
			
			document.getElementById('thumbnailLink1').onclick =  function() {
				myLightbox.changeImage(thumbIndices[1]); return false;
			}
		}else{
				thumbs[1].src = '/i/xclear.gif'
		}			
		
		// reset thumbIndex
		thumbIndex = activeImage;
		
		// now set last 2 thumbnails to next 2 images
		thumbIndex = (thumbIndex == galleryLength-1 ? 0 : thumbIndex+1);
		if(galleryLength > 3){
			thumbIndices[4] = thumbIndex;
			if (imageArray[thumbIndex][2]) {
				thumbs[4].src = imageArray[thumbIndex][2];
			} else {
				document.getElementById('thumbnailImg4').style.height = '0px';
				document.getElementById('thumbnailImg4').style.width = '0px';
				tn4 = new Image;
				tn4.onload=function(){
					//check if the thumbnail is too big for the div
					if(tn4.width >= tMaxWidth || tn4.height >= tMaxHeight){
						//set either the width or the height, not both!
						if((Math.abs(tn4.height - tMaxHeight) + (tMaxWidth - tMaxHeight)) > Math.abs(tn4.width - tMaxWidth)){
							document.getElementById('thumbnailImg4').style.height = '75px';
							document.getElementById('thumbnailImg4').style.width = '';
						}else{
							document.getElementById('thumbnailImg4').style.width = '100px';
							document.getElementById('thumbnailImg4').style.height = '';
						}						
					}
				}
				tn4.src = imageArray[thumbIndex][0];
				thumbs[4].src = imageArray[thumbIndex][0];	
			}
	
			document.getElementById('thumbnailLink4').onclick =  function() {
				myLightbox.changeImage(thumbIndices[4]); return false;
			}
		}else{
				thumbs[4].src = '/i/xclear.gif'
		}

		if(galleryLength > 4){
			thumbIndex = (thumbIndex == galleryLength-1 ? 0 : thumbIndex+1);
			thumbIndices[5] = thumbIndex;
			
			if (imageArray[thumbIndex][2]) {
				thumbs[5].src = imageArray[thumbIndex][2];
			} else {
				document.getElementById('thumbnailImg5').style.height = '0px';
				document.getElementById('thumbnailImg5').style.width = '0px';
				tn5 = new Image;					
				tn5.onload=function(){				
					//check if the thumbnail is too big for the div
					if(tn5.width >= tMaxWidth || tn5.height >= tMaxHeight){
						//set either the width or the height, not both!
						if((Math.abs(tn5.height - tMaxHeight) + (tMaxWidth - tMaxHeight)) > Math.abs(tn5.width - tMaxWidth)){
							document.getElementById('thumbnailImg5').style.height = '75px';
							document.getElementById('thumbnailImg5').style.width = '';
						}else{
							document.getElementById('thumbnailImg5').style.width = '100px';
							document.getElementById('thumbnailImg5').style.height = '';
						}						
					}
				}
				tn5.src = imageArray[thumbIndex][0];
				thumbs[5].src = imageArray[thumbIndex][0];
			}
			
			document.getElementById('thumbnailLink5').onclick =  function() {
				myLightbox.changeImage(thumbIndices[5]); return false;
			}
		}else{
				thumbs[5].src = '/i/xclear.gif'
		}


//END***************************************************************	
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {
		
		activeImage = imageNum;	// update global var
		// hide elements during transition
		Element.show('loading');
		imageDetailsEffect.hide();
		imageEffect.hide();
		navEffect.hide();
		Element.hide('prevLink');
		Element.hide('nextLink');
		Element.hide('numberDisplay');
		
		imgPreloader = new Image();
		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
			Element.setSrc('lightboxImage', imageArray[activeImage][0]);
//******************************************************************
// JW DMN 09/20/2007
//******************************************************************				
//If the image is too small set the width to the minimum for the nav (200px)
			if(imgPreloader.width < 250){
				filteredWidth = 250;
			} else {
				filteredWidth = imgPreloader.width;
			}
//******************************************************************				
			myLightbox.resizeImageContainer(filteredWidth, imgPreloader.height);
//******************************************************************
// JW DMN 10/22/2007
//******************************************************************
//Safari hack, interm. failure to resize new image, so I dyn. add width and height to inline style
			document.getElementById('lightboxImage').style.height = imgPreloader.height + 'px';
			document.getElementById('lightboxImage').style.width = imgPreloader.width + 'px';
//******************************************************************		
		}
		imgPreloader.src = imageArray[activeImage][0];
		

//******************************************************************
// JW DMN 06/11/2007
//******************************************************************		
//This updates the banner ad when the image is changed.
		// Find the current gallery name.
		var anchors = document.getElementsByTagName('a');
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if (imageArray[activeImage][0] == anchors[i].getAttribute('href')){
				var gallery = anchors[i].getAttribute('rel');
				gallery = gallery.replace(/lightbox./gi, '');
				gallery = gallery.replace(/]/g, '');
			}
		}
		var rndm = Math.round(100000*Math.random())

//******************************************************************
// JW DMN 09/20/2007
//******************************************************************	
//Decide what information we want to send omniture.
//if a docid exists then write it as storyid
		try{
			galleryMacro('CN/photos/gallery','unknown');
		}
		catch(e){
			document.writeln("<!-- " + e.message + " -->");
		}
//******************************************************************	 
//END***************************************************************
	
	},
	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get current height and width
		this.wCur = Element.getWidth('outerImageContainer');
		this.hCur = Element.getHeight('outerImageContainer');

		// calculate size difference between new and old image, and resize if necessary
		wDiff = (this.wCur - borderSize * 2) - imgWidth;
		hDiff = (this.hCur - borderSize * 2) - imgHeight;
		
		// Resize the outerImageContainer very sexy like
		reHeight = new fx.Height('outerImageContainer', { duration: resizeDuration });
		reHeight.custom(Element.getHeight('outerImageContainer'),imgHeight+(borderSize*2)); 
		reWidth = new fx.Width('outerImageContainer', { duration: resizeDuration, onComplete: function() { imageEffect.custom(0,1); }});
		reWidth.custom(Element.getWidth('outerImageContainer'),imgWidth+(borderSize*2));

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf('MSIE')!=-1){ pause(250); } else { pause(100);} 
		}

//******************************************************************
// JW DMN 06/11/2007
//******************************************************************
//I //'ed this to prevent the prev and next link divs from jumping.
		//Element.setHeight('prevLink', imgHeight);
		//Element.setHeight('nextLink', imgHeight);
//******************************************************************
		
		Element.setWidth( 'imageDataContainer', imgWidth + (borderSize * 2));
		Element.setWidth( 'hoverNav', imgWidth + (borderSize * 2));
		
		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		Element.hide('loading');
		myLightbox.updateDetails(); 
		
//******************************************************************
// JW DMN 09/20/2007
//******************************************************************
//if there is a single image then dont show the tnails or the banner.
		if(!singleImage){
			this.gallery();
			this.preloadNeighborImages();
			try{
				Element.show('thumbnails');;
				document.getElementById('lbcontainer').style.marginLeft = '-30px';
			}
			catch(e){
				//
			}
		}else{
			try{
				
				Element.hide('thumbnails');
				document.getElementById('lbcontainer').style.marginLeft = '30px';
			}
			catch(e){
				//
			}			
		}
//******************************************************************

	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {

		Element.show('caption');
		Element.setInnerHTML( 'caption', imageArray[activeImage][1]);
		
		// if image is part of set display 'Image x of x' 
		if(imageArray.length > 1){
			Element.show('numberDisplay');
			Element.setInnerHTML( 'numberDisplay', eval(activeImage + 1) + '/ ' + imageArray.length);
		}

		myLightbox.updateNav();
	},
	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {
		
		// grab existing cookie data
		var cookieName = 'dnews_images', cookieVal = '', cookieExp = '', cookieString = '';
		var start = document.cookie.indexOf(cookieName), end = 0;
		if (start != -1) {
			cookieString = document.cookie.substring(start, document.cookie.length);
			start = cookieString.indexOf('=') + 1;
			end = cookieString.indexOf(';') == -1 ? cookieString.length : cookieString.indexOf(';');
			cookieVal = cookieString.substring(start, end);
			try {
				numCartItems = cookieVal.split(/,/).length;
			}
			catch (e) {
				numCartItems = 0;
			}
		} else {
			numCartItems = 0;
		}

		
		// Check if the item is in the cart.
		if (cookieVal.indexOf(imageArray[activeImage][3]) != -1) {
			itemInCart = true;
		} else {
			itemInCart = false;
		}
		
		if (!(imageArray[activeImage][3] == false)) {
			forSale = true;
		} else {
			forSale = false;
		}
		
		// JW 01-31-2008 show div on calling page if there are items in the cart.	
		if(numCartItems > 0) {			
			if((cartItemsDiv = document.getElementById("cartItems")) && (cartItemsDivNum = document.getElementById("cartItemsNum"))) {
				cartItemsDivNum.innerHTML = numCartItems;
				cartItemsDiv.style.display = "block";
			}			
		} else {
			if((cartItemsDiv = document.getElementById("cartItems")) && (cartItemsDivNum = document.getElementById("cartItemsNum"))) {
				cartItemsDivNum.innerHTML = 0;
				cartItemsDiv.style.display = "none";
			}
		}
			
		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('prevLink');
			document.getElementById('prevLink').onclick = function() {
				myLightbox.changeImage(activeImage - 1); return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('nextLink');
			document.getElementById('nextLink').onclick = function() {
				myLightbox.changeImage(activeImage + 1); return false;
			}
		}
		
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'q') ||(key == 'x') || (key == 'o') || (key == 'c') || (keycode == '27')){	// close lightbox
			myLightbox.end();
			//previous on p, or left arrow
		} else if(key == 'p' || keycode == '37'){	// display previous image
			if(activeImage != 0){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage - 1);
			}
			//nex on n, or right arrow
		} else if(key == 'n' || keycode == '39'){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myLightbox.disableKeyboardNav();
				myLightbox.changeImage(activeImage + 1);
			}
		}
	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

	//
	//	end()
	//	
	end: function() {
		this.disableKeyboardNav();
		Element.hide('lightbox');
		Element.hide('overlay');
		imageEffect.toggle();
		overlayEffect.custom(0.8,0);
		showSelectBoxes();
		showAds();
		showFlash();
//******************************************************************
// JW DMN 06/11/2007
//******************************************************************
//If we dont remove these elements ie will choke!
		//var objData = document.getElementsByTagName('body')[0];
		//remove lightbox
		//var olddiv = document.getElementById('lightbox');
		//objData.removeChild(olddiv); 
		//remove overlay
		//var olddiv = document.getElementById('overlay');
		//objData.removeChild(olddiv);
//END***************************************************************
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }

// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName('select');
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = 'visible';
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName('select');
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = 'hidden';
	}
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}}
// ---------------------------------------------------

function initLightbox() { 

//******************************************************************
// JW DMN 09/20/2007
//******************************************************************
		myLightbox = new Lightbox();
//****************************************************************** 
}