// 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');



var imageMovieClickSwap = {
	bIsMovieShowing: false,
	oContainer: false,
	oImage: false,
	sMovieParams: false,
	sMoviePath: false,
	
	init: function() {
		// set variables
		imageMovieClickSwap.oContainer = new HTMLObject($('movieswap')) || false;
		imageMovieClickSwap.oImage = new HTMLObject($('movieswap-img')) || false;
		if(imageMovieClickSwap.oContainer && imageMovieClickSwap.oImage) {
			Object.extend(imageMovieClickSwap.oContainer,WhizBang.prototype);
			Object.extend(imageMovieClickSwap.oImage,WhizBang.prototype);
		}
		if (imageMovieClickSwap.oImage) {
			if (isQTInstalled()) {
				// add link to image
				imageMovieClickSwap.oImage.addEvent('onclick',imageMovieClickSwap.processToggle);
			} else {
				// show no QT image and link
				imageMovieClickSwap.oContainer.innerHTML = (imageMovieClickSwap.sNoQTImg) ? '<a href="/go/quicktime"><img src="'+imageMovieClickSwap.sNoQTImg+'" alt="Get Quicktime." border="0"></a>' : '<a href="/go/quicktime/"><img src="assets/videogallery/noQT.jpg" alt="Get Quicktime." border="0"></a>';
			}
		}
	},
	processToggle: function() {
		if(imageMovieClickSwap.bIsMovieShowing === false && imageMovieClickSwap.oContainer && imageMovieClickSwap.oImage) {
			imageMovieClickSwap.bIsMovieShowing = true;
			var qtbHeight = imageMovieClickSwap.oContainer.getInfo('height');
			var elem = new HTMLObject(document.createElement('div'));
			elem.id = 'moviediv';
			if(browser.isIE == false) elem.style.height = '312px';
			imageMovieClickSwap.oContainer.appendChild(elem);
			if(browser.isIE == false) elem.style.top = (parseInt(qtbHeight)-parseInt(elem.getInfo('height')))/2;
			
			var innerHTMLTemp = QT_GenerateOBJECTText_XHTML(imageMovieClickSwap.sMoviePath,'528','312','','id','movieswap-obj','bgcolor','#FFFFFF','autoplay','TRUE','controller','TRUE','type','video/quicktime','enablejavascript','TRUE','qtnext1','javascript:imageMovieClickSwap.processToggle();');
			imageMovieClickSwap.oImage.style.opacity = (0 / 101);
			imageMovieClickSwap.oImage.style.MozOpacity = (0 / 100);
			imageMovieClickSwap.oImage.style.KhtmlOpacity = (0 / 100);
			imageMovieClickSwap.oImage.style.filter = "alpha(opacity=" + 0 + ")";
			elem.innerHTML = innerHTMLTemp;
			if(!imageMovieClickSwap.oContainer.hasClass('hi') && browser.isSafari == false) {
				imageMovieClickSwap.oContainer.addClass('hi');
			}
		} else {
			if(imageMovieClickSwap.oContainer.hasClass('hi') && browser.isSafari == false) {
				imageMovieClickSwap.oContainer.removeClass('hi');
			}
			var elem = $('moviediv');
			elem.innerHTML = '';
			elem.style.display = 'none';
			elem.parentNode.removeChild(elem);
			imageMovieClickSwap.bIsMovieShowing = false;
			imageMovieClickSwap.oImage.style.visibility = 'hidden';
			imageMovieClickSwap.oImage.Fade(500,0,100,10,10,10);
		}	
	}
};

function movieSwap() {
	var qti = document.getElementById('movieswap-img') || false;
	if (qti) {
		if (isQTInstalled()) {
			addEventToObject(qti,'onclick',featureToggle);
		} else {
			//get the latest quicktime scenario
			var oMovieSwap = $('movieswap');
			oMovieSwap.innerHTML = '';
			oMovieSwap.innerHTML = '<a href="/go/quicktime/"><img src="assets/videogallery/noQT.jpg" alt="Get Quicktime." border="0"></a>';
		}
	}
}


/*****************************************************/
/** Gallery Movie ************************************/
/*****************************************************/
if(GalleryMovie == undefined) var GalleryMovie = {};  // Make sure base namespace exists
GalleryMovie.Movie = function() {};
GalleryMovie.Gallery = function() {};
GalleryMovie.SwapAds = function() {};

// Movie
GalleryMovie.Movie.prototype = {
	aMovies: new Array(),
	aMovieSizes: new Array(),
	aMovieSizesNavLinks: new Array(),
	bSwapAds: false,
	bSetGallery: false,
	bEndStateSwap: false,
	bBeginningStateSwap: false,
	bPlayInitMovie: true,
	bPlayRandInitMovie: false,
	bNavSwapFlag: false,
	bMovieContainer: true,
	iSwapContainerPadding: 0,
	iSwapContainerHeight: 0,
	iMoviesLength: false,
	fFunc: false,
	oSwapContainer: false,
	oMovieContainer: false,
	oMovieTitle: false,
	oMovieSizesNav: false,
	oMovieSizesNavGuts: oDiv.cloneNode(true),
	oMovieNav: new Object(),
	oCurrentSizeLink: new Object(),
	oLastSizeLink: false,
	oCurrentMovie: new Object(),
	oLastMovie: false,
	sObjName: 'GalleryMovie.Movie',
	sNavSwapObjName: 'GalleryMovie.SwapAds',
	sXMLFile: 'xmldata/vids.xml',
	sSwapContainer: false,
	sMovieContainer: false,
	sTitleContainer: false,
	sTitleClass: 'movietitle',
	sSizesContainer: false,
	sNavContainer: false,
	sNavClass: false,
	sCurrentSize: false,
	movieGallery: function() {},
	movieGalleryProperties: function() {},
	results: false,
	sNoQTLink: '<a href="/go/quicktime/"><img src="assets/videogallery/noQT.jpg alt="Get Quicktime." border="0"></a>',
	sIsIndexPage: false,
	sOnImg: 'assets/videogallery/dotOn.gif',
	sOffImg: 'assets/videogallery/dotOff.gif',
	sPrevArrow: 'assets/videogallery/arrowLeft.gif',
	sNextArrow: 'assets/videogallery/arrowRight.gif',
	
	
	init: function() {
		// begin
						var oVidSel = new GalleryMovie.SwapAds();
				var oVidThumbs = new GalleryMovie.Gallery();
				this.sObjName = 'oVidGal';
				this.fFunc = function(){$('viewerDiv').style.visibility = 'visible';};
				this.sNavSwapObjName = oVidSel;
				this.sMovieGalleryObjName = oVidThumbs;
				//this.sXMLFile = 'xmldata/vids.xml';
				this.sSwapContainer = 'viewerDiv';
				this.iSwapContainerHeight = 0;
				this.iSwapContainerPadding = 45;
				this.sMovieContainer = 'videoDiv';
				this.sTitleContainer = 'titleDiv';
				this.sSizesContainer = 'sizesDiv';
				//this.aMovieSizes[0] = {name:'small',dimensions:'320x240'};
				//this.aMovieSizes[1] = {name:'medium',dimensions:'480x360'};
				//this.aMovieSizes[2] = {name:'large',dimensions:'640x360'};
				//this.aMovieSizes[3] = {name:'hd',dimensions:'848x480'};
				this.sCurrentSize = 'medium';
				this.sNavContainer = 'thumbDiv';
				this.sNavClass = 'thumbStyle';
				this.bSetGallery = true;
				this.bEndStateSwap = true;
				//this.bPlayInitMovie = true;
				//this.bPlayRandInitMovie = false;
				this.iMoviesLength = 9;
				this.bNavSwapFlag = true;
				oVidThumbs.bThumbNamesToggle = true;
				oVidThumbs.iGalleryWidth = 650;
				oVidThumbs.sOnImg = this.sOnImg; //'assets/videogallery/dotOn.gif',
				oVidThumbs.sOffImg = this.sOffImg; // 'assets/videogallery/dotOff.gif',
				oVidThumbs.sPrevArrow = this.sPrevArrow; //'assets/videogallery/arrowLeft.gif',
				oVidThumbs.sNextArrow = this.sNextArrow; //'assets/videogallery/arrowRight.gif',
				oVidThumbs.iOnOffImgWidth = 7;
				oVidThumbs.iOnOffImgHeight = 7;
				oVidThumbs.iThumbWidth = 83;
				oVidThumbs.iThumbHeight = 63;
				oVidThumbs.iThumbFontSize = 11;
				if(browser.isSafari != true) oVidThumbs.iGalleryMoveSpeed = 2;

				oVidSel.init();				
		// end
		if(this.sSwapContainer && !this.oSwapContainer) {
			this.oSwapContainer = new HTMLObject($(this.sSwapContainer));
			Object.extend(this.oSwapContainer,WhizBang.prototype);
		}
		if(!this.oMovieContainer) this.oMovieContainer = $(this.sMovieContainer);
		if(this.sTitleContainer && !this.oMovieTitle) this.oMovieTitle = $(this.sTitleContainer);
		if(this.sSizesContainer) {
			// set movie sizes
			if(!this.oMovieSizesNav) {
				var nav = document.getElementById(this.sSizesContainer);
				this.oMovieSizesNav = nav;
				this.traverseXML(nav,this.oMovieSizesNavGuts);
			}
			for(var i=0; i<this.aMovieSizes.length; i++) {
				this.aMovieSizes[this.aMovieSizes[i].name] = this.aMovieSizes[i];
			}
		}
		this.oMovieNav = $(this.sNavContainer);

		if(this.bSetGallery) {
			// set scrolling gallery
			var self = this;
			AppleJAX.getXMLwithResults(this.sXMLFile,function(results) {
				self.results = results;
				self.setMovieGallery();
			});			
		} else {
			this.setMovies();
			this.setEndStateObj();
			if(this.sSizesContainer) this.setMovieSizes();
			if(this.bPlayInitMovie) this.playInitMovie();
			if(this.fFunc) this.fFunc();
		}
		var self = this;
		addEventToObject(window,'onunload',function() {self.oCurrentMovie.movieobj = null;});
	},
	setMovieGallery: function() {
		var self = this;
		this.sMovieGalleryObjName.sGalleryContainer = this.sNavContainer;
		this.sMovieGalleryObjName.results = this.results;
		this.sMovieGalleryObjName.oMovieSelf = this;
		this.sMovieGalleryObjName.oSelf = GalleryMovie.Gallery.movieGallery;
		this.sMovieGalleryObjName.sTitleClass = this.sTitleClass;
		this.sMovieGalleryObjName.fFunc = function() {
			self.setMovies();
			var galleryimages = self.results.getElementsByTagName('galleryimage');
			for(var i=0; i<self.aMovies.length; i++) {
				self.aMovies[i].endstate = galleryimages[i].getElementsByTagName('endstate')[0];
			}
			if(self.sSizesContainer) self.setMovieSizes();
			this.removeExtraThumbnails();
			if(self.bPlayInitMovie) self.playInitMovie();
			self.setEndStateObj();					
		};
		
		this.sMovieGalleryObjName.init();
		this.sMovieGalleryObjName.setGalleryFromXML();
		if(this.fFunc) this.fFunc();
	},
	setEndStateObj: function() {
		for(var i=0, oMovie; oMovie = this.aMovies[i]; i++) {
			this.traverseXML(oMovie.endstate,oMovie.endstateobj);
		}
	},
	setMovies: function() {
		// set movies array
		var oNavEls = $c(this.sNavClass,this.oMovieNav);
		var oSelf = this;
		var newSizeFlag = false;
		for(var i=0, oNavEl; oNavEl = oNavEls[i]; i++) {
			if (oNavEl.id != "[empty]") {
				addEventToObject(oNavEl,'onclick',function(ev){oSelf.processMovie(oSelf,ev)});
				addEventToObject(oNavEl,'onmouseover',this.hideStatus);
			
			var sHref = oNavEl.getElementsByTagName('a')[0].getAttribute('href');
			sHref = sHref.substring(0,sHref.lastIndexOf('_'));
			
			var sTitle = $c(this.sTitleClass,oNavEl)[0].firstChild.data;
			if(oNavEl.id.match(/vista/)) newSizeFlag = false;
			if(this.sIsIndexPage && oNavEl.id.match(/genius/)) newSizeFlag = false;
			else if(this.sIsIndexPage) newSizeFlag = true;
			this.aMovies[i] = {
				id: oNavEl.id,
				href: sHref,
				movieobj: false,
				isplaying: false,
				title: sTitle,
				div: new HTMLObject(oNavEl),
				endstate: (this.aMovies[oNavEl.id]) ? this.aMovies[oNavEl.id].endstate : '',
				endstateobj: document.createElement('div'),
				isNewSize: newSizeFlag
			};
			}
		}
		for(var i=0; i<this.aMovies.length; i++) {
			this.aMovies[this.aMovies[i].id] = this.aMovies[i];
		}
		
		if(this.bBeginningStateSwap && this.oSwapContainer) {
			var oSelf = this;
			var aSwapAs = this.oSwapContainer.getElementsByTagName('a');
			for(var i=0, oSwapA; oSwapA = aSwapAs[i]; i++) {
				addEventToObject(oSwapA,'onclick',function(ev){oSelf.processMovie(oSelf,ev)});
				addEventToObject(oSwapA,'onmouseover',this.hideStatus);
			}
		}
	},
	setMovieSizes: function() {
		if(AC.Detector.isiPhone()) {
			this.oMovieSizesNav.style.visibility = 'hidden';
		}
		// set movie sizes nav links
		this.aMovieSizesNavLinks = this.oMovieSizesNav.getElementsByTagName('a');
		var oSelf = this;
		for(var i=0; i<this.aMovieSizesNavLinks.length; i++) {
			addEventToObject(this.aMovieSizesNavLinks[i],'onclick',function(ev){oSelf.processSize(oSelf,ev);});
		}
	},
	playInitMovie: function() {
		// see if there's a movie to play
		var sLocation = document.location.href;
		var bMovieSet = false;
		if(sLocation.indexOf('?') != -1) {
			var sSearch = sLocation.split('?')[1];
			var aSearchArr = new Array(sSearch);
			if(sSearch.indexOf('&') != -1) {
				aSearchArr = sSearch.split('&');
			}
			for(var i=0; i<aSearchArr.length; i++) {
				if(aSearchArr[i].indexOf('movie=') != -1) {
					var sSearchStr = aSearchArr[i].split('=')[1];
					var sMovieName = sSearchStr.split('_')[0];
					var sMovieSize = sSearchStr.split('_')[1];
					this.oCurrentMovie = this.aMovies[sMovieName];
					this.sCurrentSize = sMovieSize;
					bMovieSet = true;
				} else if(aSearchArr[i].indexOf('=') == -1) {
					var sMovieName = aSearchArr[i].split('_')[0];
					var sMovieSize = aSearchArr[i].split('_')[1];
					this.oCurrentMovie = this.aMovies[sMovieName];
					this.sCurrentSize = sMovieSize;
					bMovieSet = true;
				}
			}

		}
		if(this.bPlayRandInitMovie && bMovieSet == false) {
			if(!this.iMoviesLength) this.iMoviesLength = this.aMovies.length;
			var iRandNum = Math.floor(Math.random() * this.iMoviesLength);
			this.oCurrentMovie = this.aMovies[iRandNum];
			bMovieSet = true;
		} else {
			// play the first movie
			this.oCurrentMovie = this.aMovies[0];
			bMovieSet = true;
		}
		if(bMovieSet) (this.bMovieContainer) ? this.playMovie() : this.swapMovie();
	},
	hideStatus: function(ev) {
		stopDefaultAction(ev);
		window.status='';
	},
	processSize: function(oSelf,ev) {
		stopDefaultAction(ev);
		var oClickedLink = getClickedLink(ev);
		var oClickedLinkParent = oClickedLink.parentNode;
		while(!oClickedLinkParent.tagName || oClickedLinkParent.tagName.toLowerCase() != 'li') {
			oClickedLinkParent = oClickedLinkParent.parentNode;
		}
		oSelf.sCurrentSize = oClickedLinkParent.id;
		oSelf.playMovie();
	},
	processMovie: function(oSelf,ev) {
		stopDefaultAction(ev);
		var oClickedLink = getClickedLink(ev);
		var sHref = oClickedLink.getAttribute('href');
		var sMovieName = sHref.substring((sHref.lastIndexOf('/')+1),sHref.lastIndexOf('_'));
		if(sMovieName.indexOf('?') != -1) { sMovieName = sMovieName.split('?')[1]; }
		var oClickedLinkParent = oClickedLink.parentNode;
		while(!oClickedLinkParent.tagName || oClickedLinkParent.tagName.toLowerCase() != 'div') {
			oClickedLinkParent = oClickedLinkParent.parentNode;
		}
		var oClickedParentObj = new HTMLObject(oClickedLinkParent);
		if(oClickedParentObj.hasClass(this.sNavClass)) {
			if(oClickedParentObj.id != sMovieName) sMovieName = oClickedParentObj.id;
		}
		oSelf.oCurrentMovie = oSelf.aMovies[sMovieName];
		if(oSelf.bMovieContainer == false) oSelf.swapMovie();
		else oSelf.playMovie();
	},
	traverseXML: function(tree, elmAppendTo) {
		var nodeCount = (tree.childNodes) ? tree.childNodes.length : 0;
		var children = tree.childNodes;
		for(var i = 0; i < nodeCount; i++) {
			var child = children[i];
			if(child.tagName) {
				var htmlElm = document.createElement(''+child.nodeName+'');
				if(child.nodeName == 'img' && browser.isIE == true) {
					htmlElm.width = child.width;
					htmlElm.height = child.height;
				}
				for(var j=0; j<child.attributes.length; j++) {
					var attrKey = child.attributes[j].nodeName;
					var attrValue = child.getAttribute(attrKey);
					var link = '';
					if(attrKey == 'href') {
						link = encodeURI(attrValue);
						if(browser.isSafari == true) {
							link = link.replace(/&#38;/g, "&");
						}
						attrValue = link;
					}
					if(attrKey == 'class' && browser.isIE == true && attrValue != null) {
						htmlElm.className = attrValue;
					} else {
						htmlElm.setAttribute(attrKey, attrValue);
					}
				}
				try {
					if(child.firstChild.data) {
						var text = document.createTextNode(child.firstChild.data);
						htmlElm.appendChild(text);
					}
				} catch(e) {}
				if(elmAppendTo != null) {
					elmAppendTo.appendChild(htmlElm);
				}
				if(child.childNodes.length>0) this.traverseXML(child, htmlElm);
			}
		}

	},
	swapMovie: function() {
		if(this.oCurrentMovie) {
			this.oSwapContainer.style.paddingTop = '0';
			this.oSwapContainer.style.height = this.iSwapContainerHeight + 'px';
			this.oSwapContainer.innerHTML = '';
			this.oMovieContainer.innerHTML = '';
			this.oSwapContainer.appendChild(this.oMovieContainer);
			this.bMovieContainer = true;
			if(this.sTitleContainer) this.oSwapContainer.appendChild(this.oMovieTitle);
			if(this.sSizesContainer) {
				this.oSwapContainer.appendChild(this.oMovieSizesNav);
				this.oMovieSizesNav.innerHTML = '';
				this.traverseXML(this.oMovieSizesNavGuts,this.oMovieSizesNav);
				this.setMovieSizes();
			}
			this.playMovie();
		}
	},
	endMovie: function(oMovie) {
		this.stopMovie(oMovie);
		if(this.oSwapContainer && this.bEndStateSwap) {
			var self = this;
			this.oMovieContainer.style.visibility = 'hidden';
			//this.oMovieContainer.style.display = 'none';
			//this.oMovieContainer.removeChild(oMovie.movieobj);
			this.oSwapContainer.Fade(300,100,0,5,5,5,function() {
				self.oSwapContainer.style.opacity = (0 / 101);
				self.oSwapContainer.style.MozOpacity = (0 / 100);
				self.oSwapContainer.style.KhtmlOpacity = (0 / 100);
				self.oSwapContainer.style.filter = "alpha(opacity=" + 0 + ")";
				self.oSwapContainer.style.visibility = 'hidden';
				self.oSwapContainer.innerHTML = '';
				self.bMovieContainer = false;
				self.oSwapContainer.appendChild(oMovie.endstateobj);
				var endstateMargin = parseInt((self.oSwapContainer.offsetHeight-oMovie.endstateobj.offsetHeight)/2);
				oMovie.endstateobj.style.height = oMovie.endstateobj.firstChild.offsetHeight + 'px';
				self.oSwapContainer.style.paddingTop = endstateMargin + 'px';
				self.oSwapContainer.style.height = (self.iSwapContainerHeight-endstateMargin) + 'px';
				self.oSwapContainer.Fade(500,0,100,15,15,15);
				self.oMovieContainer.style.visibility = 'visible';
			});

		}
	},
	stopMovie: function(oMovie) {
		oMovie.isplaying = false;
		if(this.bNavSwapFlag) this.sNavSwapObjName.stopSwap();
	},
	playMovie: function() {
		
		if(this.oLastMovie && this.oLastMovie.isplaying == true) {
			try {
				if(!AC.Detector.isiPhone()) { this.oLastMovie.movieobj.Stop(); }
				if(this.oLastMovie.movieobj) {
					this.oLastMovie.movieobj.style.display = 'none';
					this.oLastMovie.movieobj.parentNode.removeChild(this.oLastMovie.movieobj);
				}
			}
			catch (err) { this.oMovieContainer.innerHTML = this.sNoQTLink; }
			this.stopMovie(this.oLastMovie);
		}
		if(isQTInstalled()) {
			var oMovieDimensions;
			var sMoviePath;
			var sMovieWidth;
			var sMovieHeight;
			if(!AC.Detector.isiPhone()) {
				oMovieDimensions = this.aMovieSizes[this.sCurrentSize].dimensions;
				if(this.oCurrentMovie.isNewSize) {
					switch(this.sCurrentSize) {
						case 'small':
							sMoviePath = this.oCurrentMovie.href+'_320x180.mov';
							sMovieWidth = '320';
							sMovieHeight = '196';
							break;
						case 'medium':
							sMoviePath = this.oCurrentMovie.href+'_480x272.mov';
							sMovieWidth = '480';
							sMovieHeight = '288';
							break;
						case 'large':
							sMoviePath = this.oCurrentMovie.href+'_640x360.mov';
							sMovieWidth = '640';
							sMovieHeight = '376';
							break;
						case 'hd':
							sMoviePath = this.oCurrentMovie.href+'_848x480.mov';
							sMovieWidth = '848';
							sMovieHeight = '496';
						default:
							break;
					}
				} else {
					sMoviePath = this.oCurrentMovie.href+'_'+oMovieDimensions+'.mov';
					sMovieWidth = oMovieDimensions.split('x')[0];
					sMovieHeight = parseInt(oMovieDimensions.split('x')[1]) + 16; // add 16 pixels to the height to allow for QT player controls along bottom
				}
			} else {
				
				if(this.oCurrentMovie.isNewSize) {
					sMoviePath = this.oCurrentMovie.href+'_i320x180.m4v';
					sMovieWidth = '320';
					sMovieHeight = '180';
				} else {
					sMoviePath = this.oCurrentMovie.href+'_e320x256.m4v';
					sMovieWidth = '320';
					sMovieHeight = '256';
				}
			}
			this.oCurrentSizeLink = new HTMLObject($(this.sCurrentSize));
			if(this.oLastSizeLink != this.oCurrentSizeLink) {
				if(this.oLastSizeLink && this.oLastSizeLink.hasClass('hi')) {
					this.oLastSizeLink.removeClass('hi');
				}
				if(!this.oCurrentSizeLink.hasClass('hi')) { this.oCurrentSizeLink.addClass('hi'); }
				this.oLastSizeLink = this.oCurrentSizeLink;
			}
			if(this.oCurrentMovie != this.oLastMovie) {
				var oLastMovieDiv = false;
				if(this.oLastMovie != false) {
					oLastMovieDiv = new HTMLObject($(this.oLastMovie.id));
				}
				var oCurrentMovieDiv = false;
				while(oCurrentMovieDiv == false) {
					if($(this.oCurrentMovie.id)) {
						oCurrentMovieDiv = new HTMLObject($(this.oCurrentMovie.id));
					} else {
						this.sMovieGalleryObjName.findClickedGalleryDiv(this.sMovieGalleryObjName);
					}
				}
				
				if(this.oLastMovie && oLastMovieDiv.hasClass('hi')) {
					oLastMovieDiv.removeClass('hi');
				}
				if(!oCurrentMovieDiv.hasClass('hi')) {
					oCurrentMovieDiv.addClass('hi');
				}
				this.oLastMovie = this.oCurrentMovie;
			}
			var sCurrentName = this.oCurrentMovie.id;

			var sMovieObject = createMovie(sMoviePath, sMovieWidth, sMovieHeight, '', sCurrentName, this.sCurrentSize, this.sObjName);
			
			this.oMovieContainer.innerHTML = sMovieObject;
			this.oMovieTitle.innerHTML = this.oCurrentMovie.title;
			if(this.oSwapContainer) {
				var sCurrScaleHeight = this.oMovieContainer.offsetHeight+this.oMovieTitle.offsetHeight+this.oMovieSizesNav.offsetHeight+this.iSwapContainerPadding;
				if(sCurrScaleHeight != this.iSwapContainerHeight) {
					var self = this;
					this.oSwapContainer.scaleAttrib('height','px',this.iSwapContainerHeight,sCurrScaleHeight,100,10,100,function(){
						self.iSwapContainerHeight = sCurrScaleHeight;
					});	
				}
			}
			this.oCurrentMovie.movieobj = document.getElementById('movie') || document.getElementById('movieID') || document['movie'];
			this.oCurrentMovie.isplaying = true;			
		} else {
			this.oMovieContainer.innerHTML = this.sNoQTLink;
		}
	}

};

function createMovie(moviePath, movieWidth, movieHeight, posterFrameUrl, movieName, movieSize, objName) {
	return QT_GenerateOBJECTText(
			moviePath,
			movieWidth,
			movieHeight,
			'',
			'id',
			'movie',
			'emb#name',
			'movie',
			'emb#id',
			'movieID',
			'autoplay',
			'TRUE',
			'cache',
			'TRUE',
			'type',
			'video/quicktime',
			'bgcolor',
			'#FFFFFF',
			'controller',
			'TRUE',
			'enablejavascript',
			'TRUE',
			'qtnext1',
			'javascript:'+objName+'.endMovie('+objName+'.oCurrentMovie);'
		);		
}


// Gallery
GalleryMovie.Gallery.prototype = {
	results: false,
	oMovieSelf: GalleryMovie.Movie,
	sGalleryContainer: false,
	sTitleClass: '',
	oSelf: false,
	fFunc: false,
	oGalleryXML: false,
	oGalleryImagesXMLObj: false,
	aGalleryHash: new Array(),
	oGalleryContainerHTML: new Object(),
	oGalleryRuleHTML: oDiv.cloneNode(true),
	oGalleryImgGalleryNavHTML: oDiv.cloneNode(true),
	oGalleryLeftOpacHTML: oDiv.cloneNode(true),
	oGalleryRightOpacHTML: 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: '',
	sPrevArrow: '',
	sNextArrow: '',
	iNextArrowHeight: 14,
	iNextArrowWidth: 14,
	iPrevArrowHeight: 14,
	iPrevArrowWidth: 14,
	iOnOffImgWidth: 0,
	iOnOffImgHeight: 0,
	oFullSizeImgHTML: oImg.cloneNode(true),
	oDateHTML: oH5.cloneNode(true),
	oDescriptionHTML: oP.cloneNode(true),
	sRequiredAttributeErrors: '',
	iRemainder: 0,
	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);
	},
	moveRight: function(scroll,nextBeginningThumbnail) {
		for(i=0;i<(this.aGalleryHash.length);i++) {
			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); return true;}
		this.iCurrentBeginningThumb = nextBeginningThumbnail;		
	},
	moveLeft: function(scroll,nextBeginningThumbnail) {
		for(i=(this.aGalleryHash.length)-1;i>=0;i--) {
			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); return true;}
		this.iCurrentBeginningThumb = nextBeginningThumbnail;	
	},
	move: function(direction,nextBeginningThumbnail) {
		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(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);
		}
		return false;		
	},
	processGalleryImageItem: function(ev) {
		stopDefaultAction(ev);
		var clickedLink = getClickedLink(ev);
		myGalleryObj.iCurrentGalleryImg = clickedLink.parentNode.id.split('_')[1];
		return false;		
	},
	findClickedGalleryDiv: function(obj) {
		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:oItem.getElementsByTagName('name')[0].firstChild.data,
				id:oItem.getAttribute('id'),
				//classstr:oItem.getAttribute('class'),
				classstr:'thumbStyle',
				//onclick:oItem.getAttribute('onclick'),
				onclick:'oVidGal.processMovie',
				//onmouseover:oItem.getAttribute('onmouseover'),
				onmouseover:'oVidGal.hideStatus',
				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();
		if(this.fFunc) {this.fFunc();}
	},
	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.oGalleryLeftOpacHTML.setAttribute('id',this.sGalleryContainer+'leftopacity');
		this.oGalleryRightOpacHTML.setAttribute('id',this.sGalleryContainer+'rightopacity');
		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';
	},
	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('src',this.sPrevArrow);
		this.oGalleryNavNextImgHTML.setAttribute('src',this.sNextArrow);
	
		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.left = (((this.iGalleryWidth-this.iThumbNavWidth)/2)-(parseInt(this.iPrevArrowWidth)+10)) + 'px';
		this.oGalleryNavNextHTML.style.right = (((this.iGalleryWidth-this.iThumbNavWidth)/2)-(parseInt(this.iNextArrowWidth)+10)) + '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 != '') {
				addEventToObject(galleryimageaHTML,'onclick',function(ev){myMovieObj.processMovie(myMovieObj,ev)});
				addEventToObject(galleryimagetitleaHTML,'onclick',function(ev){myMovieObj.processMovie(myMovieObj,ev)});
			}

			if(this.aGalleryHash[this.iThumbNum].onmouseover != '') {
				addEventToObject(galleryimageaHTML,'onmouseover',myMovieObj.hideStatus);
				addEventToObject(galleryimagetitleaHTML,'onmouseover',myMovieObj.hideStatus);
			}
			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) && (this.aGalleryHash[this.iThumbNum].name != "[empty]")){
				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 && (this.aGalleryHash[this.iThumbNum].name != "[empty]")) {
				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;
	}
};


// SwapAds
GalleryMovie.SwapAds.prototype = {
	sMovieObjName: false,
	aNavSwapImgs: new Array(),
	oNavSwapTimeout: false,
	iLastNavNum: 0,
	oNavSwapAnchor: false,
	oNavSwapImg: false,
	iSwapInterval: 10000,
	
	init: function() {
		var aNavSwapImgSrcs = new Array();
		for(var i=0; i<this.aNavSwapImgs.length; i++) {
			aNavSwapImgSrcs[aNavSwapImgSrcs.length] = this.aNavSwapImgs[i].src;
		}
		preloader(aNavSwapImgSrcs);
		if(!this.oNavSwapAnchor) this.oNavSwapAnchor = $('navmoreswap');
		//if(!this.oNavSwapImg) this.oNavSwapImg = this.oNavSwapAnchor.getElementsByTagName('img')[0];
	},
	stopSwap: function () {
		clearTimeout(this.oNavSwapTimeout);
	},
	beginSwap: function() {
		var iRandNum = Math.floor(Math.random() * this.aNavSwapImgs.length);
		if(iRandNum == this.iLastNavNum) {
			if(iRandNum < this.aNavSwapImgs.length-1) {iRandNum++;}
			else {iRandNum = 0;}
		}
		this.oNavSwapAnchor.href = this.aNavSwapImgs[iRandNum].href;
		this.oNavSwapImg.src = this.aNavSwapImgs[iRandNum].src;
		this.oNavSwapImg.alt = this.aNavSwapImgs[iRandNum].alt;
		this.iLastNavNum = iRandNum;
		var self = this;
		this.oNavSwapTimeout = setTimeout(function() {self.beginSwap();},this.iSwapInterval);	
	}
};





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