// elements to create and clone
var oDiv = document.createElement('div');
var oA = document.createElement('a');
var oP = document.createElement('p');
var oImg = document.createElement('img');
var oSpan = document.createElement('span');
var oUl = document.createElement('ul');
var oLi = document.createElement('li');
var oH5 = document.createElement('h5');

/*****************************************************/
/** Gallery ******************************************/
/*****************************************************/
if(GalleryImgs == undefined) var GalleryImgs = {};  // Make sure base namespace exists
GalleryImgs.Thumbnails = function() {};
GalleryImgs.Gallery = function() {};

GalleryImgs.Thumbnails.prototype = {
	sXMLFile: '',
	oCurrentClickedLink: false,
	oLastClickedLink: false,
	oGalleryObj: new Object(),
	iCurrentNum: 1,
	iLastNum: 1,
	
	init: function() {
		var oThumbsContainer = $('thumbscontainer');
		var aThumbs = oThumbsContainer.getElementsByTagName('a');
		var self = this;
		for(var i=0, oThumb; oThumb = aThumbs[i]; i++) {
			addEventToObject(oThumb,'onclick',function(ev) {self.processClick(self,ev)});
		}
		this.oCurrentClickedLink = new HTMLObject($('thumb1'));
		
		var self = this;
		AppleJAX.getXMLwithResults(this.sXMLFile,function(results) {
			self.results = results;
			self.oGalleryObj.results = self.results;
			self.oGalleryObj.init();
			self.oGalleryObj.setGalleryFromXML();
			self.oGalleryObj.fFunc = function() {
				self.oGalleryObj.removeExtraThumbnails();
				self.highlightClickedThumb();
			}
			self.oGalleryObj.moveFunc = function() {
				self.highlightScrolledThumb();
			}
			self.oGalleryObj.displayHTML();
			if(self.fFunc) self.fFunc();
		});			
	},
	processClick: function(obj,ev) {
		stopDefaultAction(ev);
		var oClickedLink = getClickedLink(ev);
		
		if(obj.oGalleryObj.bGalleryInMotion == false) {
			var iNewCurrentNum = parseInt(oClickedLink.id.split('thumb')[1]);
			if(obj.iCurrentNum != iNewCurrentNum) {
				obj.iCurrentNum = parseInt(oClickedLink.id.split('thumb')[1]);
				obj.oLastClickedLink = obj.oCurrentClickedLink;
				obj.oCurrentClickedLink = new HTMLObject(oClickedLink);
				obj.highlightClickedThumb();
			}
		}
	},
	highlightClickedThumb: function() {
		if(this.oLastClickedLink != false) {
			var nextBeginningThumbnail = this.iCurrentNum-1;
			var direction = 'left';
			if(this.iLastNum < this.iCurrentNum) direction = 'left';
			else direction = 'right';
				
			this.oGalleryObj.move(direction,nextBeginningThumbnail);
			this.iLastNum = this.iCurrentNum;
			if(this.oLastClickedLink.hasClass('hi')) this.oLastClickedLink.removeClass('hi');
		}
		if(!this.oCurrentClickedLink.hasClass('hi')) this.oCurrentClickedLink.addClass('hi');
	},
	highlightScrolledThumb: function() {
		this.oLastClickedLink = this.oCurrentClickedLink;
		this.oCurrentClickedLink = new HTMLObject($('thumb'+this.oGalleryObj.iThumbNum));
		if(this.oLastClickedLink.hasClass('hi')) this.oLastClickedLink.removeClass('hi');
		if(!this.oCurrentClickedLink.hasClass('hi')) this.oCurrentClickedLink.addClass('hi');
		
	}
}


// Gallery
GalleryImgs.Gallery.prototype = {
	sXMLFile: false,
	results: false,
	sGalleryContainer: false,
	sTitleClass: '',
	oSelf: false,
	moveFunc: false,
	initFunc: false,
	fFunc: false,
	oClickObj: false,
	oGalleryXML: false,
	oGalleryImagesXMLObj: false,
	aGalleryHash: new Array(),
	oGalleryContainerHTML: new Object(),
	oGalleryRuleHTML: oDiv.cloneNode(true),
	oGalleryImgGalleryNavHTML: oDiv.cloneNode(true),
	oGalleryMovingGalleryHTML: oDiv.cloneNode(true),
	iGalleryMoveSpeed: 4,
	iThumbsAcross: 6,
	iThumbWidth: 72,
	iThumbHeight: 55,
	iThumbPadding: 10,
	iThumbAlt: 'View Movie',
	iGalleryWidth: 0,
	sTextColor: '#666',
	iThumbFontSize: 10,
	iThumbNavWidth: false,
	oGalleryHTML: new HTMLObject(oDiv.cloneNode(true)),
	iMoveSpeed: false,
	oGalleryNavPrevHTML: oA.cloneNode(true),
	oGalleryNavPrevImgHTML: oImg.cloneNode(true),
	oGalleryNavNextHTML: oA.cloneNode(true),
	oGalleryNavNextImgHTML: oImg.cloneNode(true),
	oGalleryNavHTML: oDiv.cloneNode(true),
	oGalleryPageNavHTML: oDiv.cloneNode(true),
	oGalleryMotionContainerHTML: oDiv.cloneNode(true),
	oGalleryListContainerHTML: oDiv.cloneNode(true),
	oGalleryListHTML: oUl.cloneNode(true),
	sRuleColor: '#666',
	iThumbNavHeight: false,
	bThumbNamesToggle: false,
	bFullSizeImgToggle: false,
	aRequiredAttributes: new Array(),
	iThumbNum: 0,
	iCurrentGalleryImg: 0,
	iCurrentBeginningThumb: 0,
	iNextBeginningThumbLeft: false,
	aMovingThumbLeft: new Array(),
	aMovingThumbs: new Array(),
	aThumbImgs: new Array(),
	aFullSizeImgs: new Array(),
	sErrorMsg: '',
	sOnImg: '',
	sOffImg: '',
	iOnOffImgWidth: 0,
	iOnOffImgHeight: 0,
	oFullSizeImgHTML: oImg.cloneNode(true),
	oDateHTML: oH5.cloneNode(true),
	oDescriptionHTML: oP.cloneNode(true),
	sRequiredAttributeErrors: '',
	iRemainder: 0,
	bGalleryInMotion: false,
	sError100: function() { return 'What are you thinking? A gallery with no images? That won\'t work! '; },
	sError101: function() { return 'You need to add attributes to the gallery tag.  Please add: '
				+ this.sRequiredAttributeErrors + '. '; },
	sError102: function() { return 'You have an incorrect number of gallery images.  ' +
				'Please check your XML file. ' + this.aGalleryHash.length +
				' gallery images and ' + this.iThumbsAcross + ' thumbnails across. You need ' +
				(this.iThumbsAcross-parseInt(this.iRemainder)) + ' more or ' + this.iRemainder + ' less. '; },
	sError103: function() { return 'Watch your speed! Your speed will not work ' +
				'in this scenario. Your current speed is ' + this.iGalleryMoveSpeed +
				' and your image width with padding is ' +
				(this.iThumbWidth+(this.iThumbPadding*2)) +
				'. This results in an actual speed of ' + this.iMoveSpeed +
				', which may be a repeating decimal. '; },
	
	init: function() {
		this.oGalleryXML = this.results.getElementsByTagName('gallery')[0];
		this.oGalleryImgsXMLObj = this.oGalleryXML.getElementsByTagName('galleryimage');
		this.oGalleryContainerHTML = $(this.sGalleryContainer);
		this.iThumbNavWidth = ((this.iThumbWidth+(this.iThumbPadding*2))*this.iThumbsAcross);
		Object.extend(this.oGalleryHTML,WhizBang.prototype);
		this.iMoveSpeed = parseFloat((this.iThumbWidth+(this.iThumbPadding*2))/this.iGalleryMoveSpeed);
	},
	getXML: function() {
		var self = this;
		AppleJAX.getXMLwithResults(this.sXMLFile,function(results) {
			self.results = results;
			if(self.initFunc) self.initFunc();

		});
	},
	moveRight: function(scroll,nextBeginningThumbnail) {
		for(i=0;i<(this.iThumbsAcross*this.iPages);i++) {
			if(this.aGalleryHash[i].isdisplayed == true) {
				this.aGalleryHash[i].movingthumbnailleft += this.iMoveSpeed;
				if(isFinite(this.aGalleryHash[i].movingthumbnailleft)) {
					this.aGalleryHash[i].movingthumbnail.style.left =
						this.aGalleryHash[i].movingthumbnailleft + 'px';
				}
			}
		}

		if(this.aGalleryHash[nextBeginningThumbnail].movingthumbnailleft == 0) scroll = false;

		var moveTimeout;
		var obj = this;
		if(scroll == true) {moveTimeout = window.setTimeout(function(){obj.moveRight(scroll,nextBeginningThumbnail);},10);}
		else {clearTimeout(moveTimeout); obj.bGalleryInMotion = false; return true;}
		this.iCurrentBeginningThumb = nextBeginningThumbnail;		
	},
	moveLeft: function(scroll,nextBeginningThumbnail) {
		for(i=(this.iThumbsAcross*this.iPages)-1;i>=0;i--) {
			if(this.aGalleryHash[i].isdisplayed == true) {
				this.aGalleryHash[i].movingthumbnailleft -= this.iMoveSpeed;
				//obj.aMovingThumbLeft[i] -= obj.iMoveSpeed;
				if(isFinite(this.aGalleryHash[i].movingthumbnailleft)) {
					this.aGalleryHash[i].movingthumbnail.style.left =
						this.aGalleryHash[i].movingthumbnailleft + 'px';
				}
			}
		}

		if(this.aGalleryHash[nextBeginningThumbnail].movingthumbnailleft == 0) scroll = false;

		var moveTimeout;
		var obj = this;
		if(scroll == true) {moveTimeout = window.setTimeout(function(){obj.moveLeft(scroll,nextBeginningThumbnail);},10);}
		else {clearTimeout(moveTimeout); obj.bGalleryInMotion = false; return true;}
		this.iCurrentBeginningThumb = nextBeginningThumbnail;	
	},
	move: function(direction,nextBeginningThumbnail) {
		this.bGalleryInMotion = true;
		this.iThumbNum = nextBeginningThumbnail;
		this.displayMovingThumbnailsHTML(direction);
		var scroll = true;
		// scroll left or right
		if(direction == 'right') this.moveRight(scroll,nextBeginningThumbnail);
		else if(direction == 'left') this.moveLeft(scroll,nextBeginningThumbnail);
		this.displayPageNavHTML();
		
	},
	processMovingGalleryNavItem: function(obj,ev) {
		stopDefaultAction(ev);
		var clickedLink = getClickedLink(ev);
		
		if(obj.bGalleryInMotion == false) {
			if(clickedLink === obj.oGalleryNavPrevHTML) {
				var nextBeginningThumbnail = (obj.iCurrentBeginningThumb > 0) ?
					obj.iCurrentBeginningThumb - obj.iThumbsAcross :
					obj.aGalleryHash.length - obj.iThumbsAcross;
				obj.move('right',nextBeginningThumbnail);
			}
			else if(clickedLink === obj.oGalleryNavNextHTML) {
				var nextBeginningThumbnail =
					((obj.iCurrentBeginningThumb + obj.iThumbsAcross) <
					obj.aGalleryHash.length) ?
					obj.iCurrentBeginningThumb + obj.iThumbsAcross : 0 ;
				obj.move('left',nextBeginningThumbnail);
			}
			else {
				var clickedNum = parseInt(clickedLink.id.split('_')[1]);
				if(clickedNum < obj.iCurrentBeginningThumb)	obj.move('right',clickedNum);
				else if(clickedNum > obj.iCurrentBeginningThumb) obj.move('left',clickedNum);
			}
			if(this.moveFunc) this.moveFunc();
		}
		return false;		
	},
	processGalleryImageItem: function(ev) {
		stopDefaultAction(ev);
		var clickedLink = getClickedLink(ev);
		myGalleryObj.iCurrentGalleryImg = clickedLink.parentNode.id.split('_')[1];
		return false;		
	},
	findClickedGalleryDiv: function(obj) {
		if(obj.bGalleryInMotion == false) {
			var nextBeginningThumbnail =
				((obj.iCurrentBeginningThumb + obj.iThumbsAcross) <
				obj.aGalleryHash.length) ?
				obj.iCurrentBeginningThumb + obj.iThumbsAcross : 0 ;
			obj.move('left',nextBeginningThumbnail);
		}
	},
	setGalleryFromXML: function() {
		for(var i=0, oItem; oItem = this.oGalleryImgsXMLObj[i]; i++) {
			this.aGalleryHash[i] = {
				obj:oItem,
				href:oItem.getAttribute('href'),
				thumbnail:oItem.getElementsByTagName('thumbnail')[0].firstChild.data,
				alt:oItem.getAttribute('alt'),
				name:(this.bThumbNamesToggle) ? oItem.getElementsByTagName('name')[0].firstChild.data : '',
				id:oItem.getAttribute('id'),
				classstr:oItem.getAttribute('class'),
				onclick:oItem.getAttribute('onclick'),
				onmouseover:oItem.getAttribute('onmouseover'),
				movingthumbnail:new Object(),
				movingthumbnailleft:0,
				isdisplayed:true
			};
		}
		for(var i=0; i<this.aGalleryHash; i++) {
			this.aGalleryHash[this.aGalleryHash[i].id] = this.aGalleryHash[i];
		}
		//this.displayHTML();
		
	},
	errorCheck: function() {
		this.iPages = parseInt(this.aGalleryHash.length/this.iThumbsAcross);
	
		if(this.aGalleryHash.length <= 0) this.sErrorMsg += this.sError100();
		
		for(i=0;i<this.aRequiredAttributes.length;i++) {
			if(!(this.oGalleryXML.getAttribute(this.aRequiredAttributes[i]))) {
				if(i == (this.aRequiredAttributes.length-1)) {
					this.sRequiredAttributeErrors += 'and ' + this.aRequiredAttributes[i];
				} else {
					this.sRequiredAttributeErrors += this.aRequiredAttributes[i] + ', ';
				}
			}
		}
		if(this.sRequiredAttributeErrors.length > 0) this.sErrorMsg += this.sError101();
	
		if(this.oGalleryXML.getAttribute('rulecolor')) { //should be hasAttribute but doesn't work in IE
			this.sRuleColor = this.oGalleryXML.getAttribute('rulecolor');
		}
		/*
		if(this.oGalleryXML.getAttribute('thumbnailnavheight')) { //should be hasAttribute
			this.iThumbNavHeight = parseInt(this.oGalleryXML.getAttribute('thumbnailnavheight'));
		} else {
			this.iThumbNavHeight = this.iThumbHeight+60+this.iOnOffImgHeight;
		}	
		*/
		
		this.iRemainder = (this.aGalleryHash.length%this.iThumbsAcross);
		if(this.iRemainder > 0) {
			this.sErrorMsg += this.sError102();
		}
		var moveSpeedString = this.iMoveSpeed.toString();
		var moveSpeedDecimal = this.iMoveSpeed.toString().split('.')[1];

		if(moveSpeedDecimal && moveSpeedDecimal.length >= 10) this.sErrorMsg += this.sError103();
	},
	displayHTML: function() {
		this.errorCheck();
		
		this.oGalleryHTML.setAttribute('id',this.sGalleryContainer+'gallery');
		this.oGalleryRuleHTML.setAttribute('id',this.sGalleryContainer+'galleryrule');
		this.oGalleryImgGalleryNavHTML.setAttribute('id',this.sGalleryContainer+'imagegallerynav');
		this.oGalleryPageNavHTML.setAttribute('id',this.sGalleryContainer+'pagenav');
		this.oGalleryMotionContainerHTML.setAttribute('id',this.sGalleryContainer+'motioncontainer');
		this.oGalleryMovingGalleryHTML.setAttribute('id',this.sGalleryContainer+'movinggallery');
		
		var gallerynavtoggle = false;
		if(this.aGalleryHash.length > this.iThumbsAcross) {
			gallerynavtoggle = this.displayPrevNextNavHTML();
			this.displayPageNavHTML();
		}
		
		this.oGalleryMotionContainerHTML.appendChild(this.oGalleryMovingGalleryHTML);
		this.oGalleryImgGalleryNavHTML.appendChild(this.oGalleryPageNavHTML);
		this.oGalleryImgGalleryNavHTML.appendChild(this.oGalleryMotionContainerHTML);
	
		if(this.sErrorMsg.length > 0) {
			var errorText = document.createTextNode(this.sErrorMsg);
			this.oGalleryContainerHTML.appendChild(errorText);
		} else {	
			this.preloadImages();
			this.displayThumbnailsHTML();
			this.styleHTML();

			if(gallerynavtoggle) this.oGalleryContainerHTML.appendChild(this.oGalleryNavHTML);
			this.oGalleryContainerHTML.appendChild(this.oGalleryImgGalleryNavHTML);
		}

		//this.iThumbNavHeight = this.aGalleryHash[0].movingthumbnail.offsetHeight;
		this.oGalleryMotionContainerHTML.style.height = this.iThumbNavHeight + 'px';
		this.oGalleryMovingGalleryHTML.style.height = this.iThumbNavHeight + 'px';
		if(this.fFunc) {this.fFunc();}
	},
	preloadImages: function() {
		for(i=0;i<this.aGalleryHash.length;i++) {
			if(this.aGalleryHash[i].length > 0 && this.aGalleryHash[i].thumbnail) {
				this.oThumbImgs[i] = new Image();
				this.oThumbImgs[i].src = this.aGalleryHash[i].thumbnail;
			}
		}
	},
	styleHTML: function() {
		this.oGalleryContainerHTML.style.width = this.iGalleryWidth + 'px';

		this.oGalleryRuleHTML.style.width = this.iGalleryWidth + 'px';
		if(this.sRuleColor) {
			this.oGalleryRuleHTML.style.borderTop = '1px solid ' + this.sRuleColor;
		}
	
		this.oGalleryPageNavHTML.style.width = this.iGalleryWidth + 'px';
		this.oGalleryPageNavHTML.style.textAlign = 'center';
		this.oGalleryPageNavHTML.style.margin = '0 0 10px 0';
	
		this.oGalleryMotionContainerHTML.style.width = this.iThumbNavWidth + 'px';
		this.oGalleryMotionContainerHTML.style.height = this.iThumbNavHeight + 'px';
		this.oGalleryMotionContainerHTML.style.margin = '0 ' +  (this.iGalleryWidth-this.iThumbNavWidth)/2 + 'px'; 
		this.oGalleryMotionContainerHTML.style.padding = '0';
		this.oGalleryMotionContainerHTML.style.overflow = 'hidden';
		this.oGalleryMotionContainerHTML.style.position = 'relative';
	
		this.oGalleryMovingGalleryHTML.style.width = this.iThumbNavWidth + 'px';
		this.oGalleryMovingGalleryHTML.style.height = this.iThumbNavHeight + 'px';
		this.oGalleryMovingGalleryHTML.style.position = 'relative';	
	},
	displayPageNavHTML: function() {
		var pagenavonimg = oImg.cloneNode(true);
		pagenavonimg.setAttribute('width',this.iOnOffImgWidth);
		pagenavonimg.setAttribute('height',this.iOnOffImgHeight);
		pagenavonimg.setAttribute('border','0');
		pagenavonimg.style.margin = '2px 4px 0pt'; // '0 2px'; // nat
	
		while(this.oGalleryPageNavHTML.hasChildNodes()) { this.oGalleryPageNavHTML.removeChild(this.oGalleryPageNavHTML.firstChild); }
	
		for(i=0;i<this.iPages;i++) {
			if(this.iCurrentBeginningThumb == (i*this.iThumbsAcross)) {
					pagenavonimg.setAttribute('src',this.sOnImg);

				this.oGalleryPageNavHTML.appendChild(pagenavonimg);
			}
			else {
				var pagenavoffa = oA.cloneNode(true);
				var pagenavoffimg = pagenavonimg.cloneNode(true);
		
				pagenavoffa.setAttribute('id',this.sGalleryContainer+'pagenav_'+(this.iThumbsAcross*i));				
				pagenavoffa.setAttribute('href','#');
				pagenavoffimg.setAttribute('src',this.sOffImg);
	
				pagenavoffa.appendChild(pagenavoffimg);
				this.oGalleryPageNavHTML.appendChild(pagenavoffa);

				var myObj = this;
				addEventToObject(pagenavoffa,'onclick',function(ev){myObj.processMovingGalleryNavItem(myObj,ev);});

			}
		}
	
	return true;	
	},
	displayPrevNextNavHTML: function() {
		this.oGalleryNavHTML.setAttribute('id',this.sGalleryContainer+'gallerynav');

		this.oGalleryNavPrevHTML.setAttribute('href','#');
		this.oGalleryNavNextHTML.setAttribute('href','#');
		this.oGalleryNavPrevHTML.setAttribute('id',this.sGalleryContainer+'prevgallerynav');
		this.oGalleryNavNextHTML.setAttribute('id',this.sGalleryContainer+'nextgallerynav');
	
		this.oGalleryNavPrevImgHTML.setAttribute('width',this.iPrevArrowWidth);
		this.oGalleryNavNextImgHTML.setAttribute('width',this.iNextArrowWidth);
		this.oGalleryNavPrevImgHTML.setAttribute('height',this.iPrevArrowHeight);
		this.oGalleryNavNextImgHTML.setAttribute('height',this.iNextArrowHeight);
		this.oGalleryNavPrevImgHTML.setAttribute('border','0');
		this.oGalleryNavNextImgHTML.setAttribute('border','0');

		this.oGalleryNavPrevImgHTML.setAttribute('alt','Previous');
		this.oGalleryNavNextImgHTML.setAttribute('alt','Next');
		
		this.oGalleryNavPrevHTML.appendChild(this.oGalleryNavPrevImgHTML);
		this.oGalleryNavNextHTML.appendChild(this.oGalleryNavNextImgHTML);
		
		this.oGalleryNavHTML.appendChild(this.oGalleryNavPrevHTML);
		this.oGalleryNavHTML.appendChild(this.oGalleryNavNextHTML);
	
		this.oGalleryNavHTML.style.width = this.iGalleryWidth + 'px';
		this.oGalleryNavHTML.style.position = 'relative';

		this.oGalleryNavPrevHTML.style.position = 'absolute';
		this.oGalleryNavNextHTML.style.position = 'absolute';

		if(this.oGalleryXML.getElementsByTagName('gallerypagenav')[0]) {
			//this.oGalleryNavPrevHTML.style.top = (((this.iThumbNavHeight-parseInt(this.iPrevArrowHeight))/2)+parseInt(this.iOnOffImgHeight)+((this.bThumbNamesToggle) ? 0 : 0)) + 'px';
			//this.oGalleryNavNextHTML.style.top = (((this.iThumbNavHeight-parseInt(this.iNextArrowHeight))/2)+parseInt(this.iOnOffImgHeight)+((this.bThumbNamesToggle) ? 0 : 0)) + 'px';
		} else {

			//this.oGalleryNavPrevHTML.style.top = (((this.iThumbNavHeight-parseInt(this.iPrevArrowHeight))/2)-parseInt(this.iPrevArrowHeight)) + 'px';
			//this.oGalleryNavNextHTML.style.top = (((this.iThumbNavHeight-parseInt(this.iNextArrowHeight))/2)-parseInt(this.iNextArrowHeight)) + 'px';
		}

		
		this.oGalleryNavPrevHTML.style.zIndex = 100;
		this.oGalleryNavNextHTML.style.zIndex = 100;

		var myObj = this;
		
addEventToObject(this.oGalleryNavPrevHTML,'onclick',function(ev){myObj.processMovingGalleryNavItem(myObj,ev);});
		addEventToObject(this.oGalleryNavNextHTML,'onclick',function(ev){myObj.processMovingGalleryNavItem(myObj,ev);});

		return true;
	},
	removeExtraThumbnails: function() {
		var childrenLength = this.oGalleryMovingGalleryHTML.childNodes.length;
		for(var i=0;i<(childrenLength);i++) {
			if((i < this.iCurrentBeginningThumb) || (i >= (this.iCurrentBeginningThumb+this.iThumbsAcross))) {
				var childToRemove = $(this.sGalleryContainer+'imagenav_'+i) || $(this.aGalleryHash[i].id);
				if(childToRemove) {
					this.oGalleryMovingGalleryHTML.removeChild(childToRemove);
					this.aGalleryHash[i].isdisplayed = false;
				}
			}
		}
		
	},
	displayMovingThumbnailsHTML: function(direction) {
		this.removeExtraThumbnails();
		var endingThumbnail = (this.iThumbNum+this.iThumbsAcross);
		var i = this.iThumbsAcross;
		var j = this.iThumbsAcross;
		for(this.iThumbNum;this.iThumbNum<endingThumbnail;this.iThumbNum++) {
			
			var thumbnailLeft;

			if(direction === 'right') {
				thumbnailLeft = (-(this.iThumbWidth+(this.iThumbPadding*2))*i);
				i--;
			}
			else if(direction === 'left') {
				thumbnailLeft = ((this.iThumbWidth+(this.iThumbPadding*2))*j);
				j++;
			}
			else {
				thumbnailLeft = (this.iThumbNum*(this.iThumbWidth+(this.iThumbPadding*2)));
			}

			var thumbnail = this.aGalleryHash[this.iThumbNum].movingthumbnail;
			thumbnail.style.left = thumbnailLeft + 'px';
			this.aGalleryHash[this.iThumbNum].movingthumbnailleft = thumbnailLeft;

			this.oGalleryMovingGalleryHTML.appendChild(this.aGalleryHash[this.iThumbNum].movingthumbnail);
			this.aGalleryHash[this.iThumbNum].isdisplayed = true;
		
		}

		return true;
	
	},
	displayThumbnailsHTML: function() {
		for(this.iThumbNum;this.iThumbNum<this.aGalleryHash.length;this.iThumbNum++) {
			var galleryimagedivHTML = oDiv.cloneNode(true);
			var galleryimageaHTML = oA.cloneNode(true);
			var galleryimagetitleaHTML = new HTMLObject(oA.cloneNode(true));
			var galleryimageimgHTML = oImg.cloneNode(true);
			var galleryimagespanHTML = oSpan.cloneNode(true);
			var galleryimagelearnmoreimgHTML = oImg.cloneNode(true);
			var galleryimagebuynowimgHTML = oImg.cloneNode(true);
			var galleryimagelearnmoreaHTML = oA.cloneNode(true);
			var galleryimagebuynowaHTML = oA.cloneNode(true);
			var galleryimagelearnmorespanHTML = oSpan.cloneNode(true);
			var galleryimagebuynowspanHTML = oSpan.cloneNode(true);
		
			var myMovieObj = this.oMovieSelf;
			if(this.aGalleryHash[this.iThumbNum].onclick != '') {
				var self = this;
				addEventToObject(galleryimageaHTML,'onclick',function(ev) {WWDCBios.processSwap(self.oClickObj,ev)});
				addEventToObject(galleryimagetitleaHTML,'onclick',function(ev) {WWDCBios.processSwap(self.oClickObj,ev)});
			}

			if(this.aGalleryHash[this.iThumbNum].onmouseover) {
				var self = this;
				addEventToObject(galleryimageaHTML,'onmouseover',function(ev) {self.aGalleryHash[self.iThumbNum].onmouseover(ev);});
				addEventToObject(galleryimagetitleaHTML,'onmouseover',function(ev) {self.aGalleryHash[self.iThumbNum].onmouseover(ev);});
			}
			if(this.aGalleryHash[this.iThumbNum].id != '') {
				galleryimagedivHTML.setAttribute('id',this.aGalleryHash[this.iThumbNum].id);
			} else {
				galleryimagedivHTML.setAttribute('id',this.sGalleryContainer+'imagenav_'+this.iThumbNum);
			}
			if(this.aGalleryHash[this.iThumbNum].classstr != '') {
				galleryimagedivHTML.className = this.aGalleryHash[this.iThumbNum].classstr;
			}
			galleryimagedivHTML.style.position = 'absolute';
			galleryimagedivHTML.style.width = (this.iThumbWidth+(this.iThumbPadding*2)) + 'px';
			galleryimagedivHTML.style.height = 'auto';

			galleryimagedivHTML.style.top = '0px';

			var thumbnailLeft;

			thumbnailLeft = (this.iThumbNum*(this.iThumbWidth+(this.iThumbPadding*2)));

			galleryimagedivHTML.style.left = thumbnailLeft + 'px';
			this.aGalleryHash[this.iThumbNum].movingthumbnailleft = thumbnailLeft;
			//this.aMovingThumbLeft.push(thumbnailLeft);

			galleryimagedivHTML.style.padding = '0 ' + this.iThumbPadding + 'px';

			// add link to a thumbnail
			if(this.aGalleryHash[this.iThumbNum].href){
				galleryimageaHTML.setAttribute('href',this.aGalleryHash[this.iThumbNum].href);
			}


			if(this.aGalleryHash[this.iThumbNum].thumbnail) {
				galleryimageimgHTML.setAttribute('src',this.aGalleryHash[this.iThumbNum].thumbnail);
			}

			galleryimageimgHTML.setAttribute('width',this.iThumbWidth);
			galleryimageimgHTML.setAttribute('height',this.iThumbHeight);

			if(this.aGalleryHash[this.iThumbNum].alt) {
				galleryimageimgHTML.setAttribute('alt',this.aGalleryHash[this.iThumbNum].alt);
			}

			galleryimageimgHTML.setAttribute('border','0');

			// display title with a link underneath of each thumbnail
			if(this.bThumbNamesToggle && this.aGalleryHash[this.iThumbNum].name) {
				var childTitle = document.createTextNode(this.aGalleryHash[this.iThumbNum].name);
				if(this.aGalleryHash[this.iThumbNum].href)
				{
					galleryimagetitleaHTML.setAttribute('href',this.aGalleryHash[this.iThumbNum].href);
					galleryimagetitleaHTML.style.color = '#666';
				
				}
				if(galleryimagetitleaHTML.hasClass(this.sTitleClass) == false) galleryimagetitleaHTML.addClass(this.sTitleClass);
				galleryimagetitleaHTML.appendChild(childTitle);
				galleryimagespanHTML.appendChild(galleryimagetitleaHTML);
			
			}
		
			// SPAN that wraps thumb image and title
			galleryimagespanHTML.style.display = 'block';
			galleryimagespanHTML.style.width = this.iThumbWidth + 'px';
			galleryimagespanHTML.style.textAlign = 'center';
			//galleryimagespanHTML.style.margin = '0 ' + thumbnailpadding + 'px';
			galleryimagespanHTML.style.fontSize = this.iThumbFontSize + 'px';
			galleryimagetitleaHTML.style.fontSize = this.iThumbFontSize + 'px';
		
			//if(this.glryimgsX[this.thumbnum].hasChildNodes()) {
			galleryimageaHTML.appendChild(galleryimageimgHTML);
			galleryimagedivHTML.appendChild(galleryimageaHTML);
			galleryimagedivHTML.appendChild(galleryimagespanHTML);
		
			this.oGalleryMovingGalleryHTML.appendChild(galleryimagedivHTML);
			
			this.aGalleryHash[this.iThumbNum].movingthumbnail = galleryimagedivHTML;
			//this.aMovingThumbs.push(galleryimagedivHTML);
		}

		this.iThumbNum = this.iThumbsAcross;
		return true;
	}
};



function preloader(aImgs) {
	var aPreloadImgs = new Array();
	for(i=0;i<aImgs.length;i++) {
		aPreloadImgs[i] = new Image();
		aPreloadImgs[i].src = aImgs[i];
	}
}
