﻿Type.registerNamespace('Vehix.Presentation.MediaBrowser');

Vehix.Presentation.MediaBrowser = function(mediaGrid, activeImage) {
    Vehix.Presentation.MediaBrowser.initializeBase(this);
    var _mediaBrowser = null;
    var _isLoaded = false;

    //Public Properties
    this.grid = mediaGrid; 						 //Required  Note:  Media Grid Element
    this.activeDisplay = activeImage; 			 //Required  Note:  Vehix.Presentation.MediaActiveImage Class

    this.ID = null; 								 //Required  Note:  This ID should be set to the name you declared Vehix.Presentation.MediaBrowser
    this.menuContainerID = ""; 					 //Required	 Note:  Container Element of Menu Items of Media Browser
    this.mediaBrowserContainerID = ""; 			 //Required  Note:  Container Element of Media Browser
    this.isThumbsEmptyAndDefaultImageCustom;
    this.verticalNavigationContainerID = ""; //Required.
}

Vehix.Presentation.MediaBrowser.prototype =
{
	_error: function(err, funcName)
	{
		err.message = err.message + "\n :: Stack Trace: Vehix.Presentation.MediaBrowser." + funcName + "\n";
		return err;
	},

	bind: function(obj, fnc)
	{
		temp = function()
		{
			return fnc.apply(obj, arguments);
		};
		return temp;
	},

	create: function(imageArray)
	{
		try
		{
			if (this.ID === null)
				throw "Please Set the ID of the object to the name you declared it too."

			this.isThumbsEmptyAndDefaultImageCustom = false;
			if (this.grid.dataItems("Dealer") == null
				&& this.grid.dataItems("Seller") == null
				&& this.activeDisplay.defaultImagePath.toLowerCase().indexOf("homenetmedia") > 1
			  )
				this.isThumbsEmptyAndDefaultImageCustom = true;

			this._create_HTML();

			this.grid.mediaBrowserContainerID = this.mediaBrowserContainerID;
			this.grid.imageArrayDealerSmall = new Array();
			this.grid.imageArrayMFRSmall = new Array();
			this.grid.imageArrayLarge = new Array();
			this.grid._setsOfThree = 0;
			this.grid._setsOfNine = 0;
			this.grid.thumbLoadingImage = newImage();
			this.grid.thumbLoadingImage.setAttribute("height", this.grid.thumbHeight);
			this.grid.thumbLoadingImage.setAttribute("width", this.thumbWidth);
			var thumbImageLoadedEvent = function()
			{
				try
				{
					if (!this._isLoaded)
					{
						clearTimeout(this._lateThumbLoadTimer);
						this._loadLargeProgressBar();
					}
				}
				catch (loadEventErr) { throw this._error(loadEventErr, "create() --> thumbLoadingImage.onload()"); }
			};
			this.grid.thumbLoadingImage.onload = this.bind(this, thumbImageLoadedEvent);
			this._lateThumbLoadTimer = setTimeout(this.bind(this, thumbImageLoadedEvent), 1500);
		}
		catch (err) { throw this._error(err, "create()"); }
		finally
		{
			if (this.grid != null && this.grid.thumbLoadingImage != null)
				this.grid.thumbLoadingImage.src = gvx_ApplicationPath + '/_images/loading_thumbs.gif';
		}
	},

	load: function()
	{
		try
		{
			this.grid.ID = "grid";
			this.grid.setParent(this);
			this.grid.activateOnMouseEvents = true; //This property is set to false by default.
			this.grid.create();
			this.activeDisplay.create();
			this.activeDisplay.setParent(this);
			this.activeDisplay.showLoadingProgressBar();
			this.activeDisplay.load();
			this._isLoaded = true;
		}
		catch (err) { throw this._error(err, "load()"); }
	},

	_loadLargeProgressBar: function()
	{
		try
		{
			this.activeDisplay.largeProgressBarGif = newImage();
			this.activeDisplay.largeProgressBarGif.className = "galleryActiveImageProgressBar";
			this.activeDisplay.largeProgressBarGif.setAttribute("alt", "Loading");
			this.activeDisplay.largeProgressBarGif.style.borderWidth = "0px";
			var largeProgressBarLoadEvent = function()
			{
				try
				{
					//load media Browser if not loaded
					if (!this._isLoaded)
					{
						clearTimeout(this._lateLoadTimer);
						this.load();
					}
				}
				catch (loadEventErr)
				{
					throw loadEventErr + "\n :: Stack Trace: Vehix.Presentation.MediaBrowser._loadLargeProgressBar()--> _largeProgressBarGif.onload()\n";
				}
			};
			this.activeDisplay.largeProgressBarGif.onload = this.bind(this, largeProgressBarLoadEvent);
			this._lateLoadTimer = setTimeout(this.bind(this, largeProgressBarLoadEvent), 1500);
		}
		catch (err)
		{
			throw err + " :: Stack Trace: Vehix.Presentation.MediaBrowser._loadLargeProgressBar(image)";
		}
		finally
		{
			this.activeDisplay.largeProgressBarGif.src = gvx_ApplicationPath + '/_images/loading_sm.gif';
		}
	},

	//ad-hoc delegate
	onMouseOverThumb: function(image)
	{
		try
		{
			if (!this.grid.disableMouseOver)
			{
				this.activeDisplay.magnifyEnabled = true;
				this.activeDisplay.showImage(image);
			}
		}
		catch (err) { throw this._error(err, "onMouseOverThumb(image)"); }
	},

	unlockGrid: function()
	{
		try
		{
			this.grid.disableMouseOver = false;
		}
		catch (err) { throw this._error(err, "unlockGrid()"); }
	},

	reloadDealer: function()
	{
		try
		{
			this.activeDisplay.clear();
			this.grid.clear();
			this.grid.currentImageSet = (this.grid.dataItems("Dealer") != null) ? "Dealer" : "Seller";
			if (!this.isThumbsEmptyAndDefaultImageCustom)
				this.grid.load();

			this.activeDisplay.showImage(null, true);
		}
		catch (err) { throw this._error(err, "reloadDealer()"); }
	},

	reloadManufacturer: function()
	{
		try
		{
			this.activeDisplay.clear();
			this.grid.clear();
			this.grid.currentImageSet = "Manufacturer";
			this.grid.showNavigationForVerticalNavigation(this.verticalNavigationContainerID, this.menuContainerID);
			this.grid.load();
			this.activeDisplay.showImage(null, true);
		}
		catch (err) { throw this._error(err, "reloadManufacturer()"); }
	},

	_create_HTML: function()
	{
		var menuContainerDiv = null;
		var rightSpacerDiv = newDiv();
		var defaultCurrentDataSet = "none";

		try
		{
			menuContainerDiv = this._buildMenuContainer();
			if (this.grid.data.length > 0)
			{

				if (this.grid.dataItems("Dealer") != null || this.grid.dataItems("Seller") != null || this.isThumbsEmptyAndDefaultImageCustom)
				{
					if (!this.isThumbsEmptyAndDefaultImageCustom)
						defaultCurrentDataSet = (this.grid.dataItems("Dealer") != null) ? "Dealer" : "Seller";

					var containerDealerLinkDiv = newDiv();
					containerDealerLinkDiv.className = "panel galleryMenuPanels galleryDealerPanel";

					var dealerLinkDiv = newDiv();
					dealerLinkDiv.className = "panel galleryLinkContainers";

					var dealerAnchor = newAnchor();
					dealerAnchor.className = "link galleryLinks";
					dealerAnchor.href = "javascript:void(0);"

					if (this.isThumbsEmptyAndDefaultImageCustom)
						dealerAnchor.innerHTML = "Dealer";
					else
						dealerAnchor.innerHTML = defaultCurrentDataSet;

					dealerAnchor.mediaBrowseObj = this;
					dealerAnchor.onclick = function()
					{
						try
						{
							this.mediaBrowseObj.reloadDealer();
						}
						catch (sellerOnclickError)
						{
							try
							{
								this.mediaBrowserObj._loadLate();
								this.mediaBrowseObj.reloadDealer();
							}
							catch (sellerOnclickError)
							{
								throw this.mediaBrowseObj._error(sellerOnclickError, "_create_HTML() --> dealerAnchor.onclick()");
							}
						}
					};
					dealerLinkDiv.appendChild(dealerAnchor);
					containerDealerLinkDiv.appendChild(dealerLinkDiv);
					menuContainerDiv.appendChild(containerDealerLinkDiv);
				}

				if (this.grid.dataItems("Manufacturer") != null)
				{
					if (defaultCurrentDataSet == "none" && !this.isThumbsEmptyAndDefaultImageCustom)
						defaultCurrentDataSet = "Manufacturer";

					var containerManufacturerLinkDiv = newDiv();
					containerManufacturerLinkDiv.className = "panel galleryMenuPanels galleryManufacturerPanel";

					var manufacturerLinkDiv = newDiv();
					manufacturerLinkDiv.className = "panel galleryLinkContainers";

					var manufacturerAnchor = newAnchor();
					manufacturerAnchor.className = "link galleryLinks";
					manufacturerAnchor.href = "javascript:void(0);";
					manufacturerAnchor.innerHTML = "Manufacturer";
					manufacturerAnchor.mediaBrowseObj = this;
					manufacturerAnchor.onclick = function()
					{
						try
						{
							this.mediaBrowseObj.reloadManufacturer();
						}
						catch (err) { throw this.mediaBrowseObj._error(err, "_create_HTML() --> manufacturerAnchor.onclick()"); }
					};

					manufacturerLinkDiv.appendChild(manufacturerAnchor);
					containerManufacturerLinkDiv.appendChild(manufacturerLinkDiv);
					menuContainerDiv.appendChild(containerManufacturerLinkDiv);
				}

				if (this.grid.dataItems("360 Ext.") != null)
				{
					var containerExt360Div = newDiv();
					containerExt360Div.className = "panel galleryMenuPanels gallery360ExteriorPanel";

					var ext360LinkDiv = newDiv();
					ext360LinkDiv.className = "panel galleryLinkContainers";

					var ext360Anchor = newAnchor();
					ext360Anchor.className = "link galleryLinks";
					ext360Anchor.href = "javascript:void(0);";
					ext360Anchor.innerHTML = "360 Ext.";
					ext360Anchor.mediaBrowseObj = this;
					var ext360Click = function()
					{
						try
						{
							this.load360Exterior();
						}
						catch (eventErr)
						{
							throw eventErr + "\n :: Stack Trace: Vehix.Presentation.MediaBrowser._create_HTML()--> load360Exterior.onclick()\n";
						}
					};
					ext360Anchor.onclick = this.bind(this, ext360Click);

					ext360LinkDiv.appendChild(ext360Anchor);
					containerExt360Div.appendChild(ext360LinkDiv);
					menuContainerDiv.appendChild(containerExt360Div);
				}

				if (this.grid.dataItems("360 Int.") != null)
				{
					var containerInternal360Div = newDiv();
					containerInternal360Div.className = "panel galleryMenuPanels gallery360InteriorPanel";

					var internal360LinkDiv = newDiv();
					internal360LinkDiv.className = "panel galleryLinkContainers";

					var internal360Anchor = newAnchor();
					internal360Anchor.className = "link galleryLinks";
					internal360Anchor.href = "javascript:void(0);";
					internal360Anchor.innerHTML = "360 Int.";
					internal360Anchor.mediaBrowseObj = this;
					var i360click = function()
					{
						try
						{
							this.load360Interior();
						}
						catch (eventErr)
						{
							throw eventErr + "\n :: Stack Trace: Vehix.Presentation.MediaBrowser._create_HTML()--> internal360Anchor.onclick()\n";
						}
					};
					internal360Anchor.onclick = this.bind(this, i360click);
					internal360LinkDiv.appendChild(internal360Anchor);
					containerInternal360Div.appendChild(internal360LinkDiv);
					menuContainerDiv.appendChild(containerInternal360Div);
				}
			}
			else
			{
				if ($get(this.verticalNavigationContainerID))
					$get(this.verticalNavigationContainerID).style.display = "none";
				if ($get(this.grid.gridContainerID))
					$get(this.grid.gridContainerID).style.display = "none";
				if ($get(this.menuContainerID))
					$get(this.menuContainerID).style.display = "none";
			}
			this.grid.currentImageSet = defaultCurrentDataSet;

			var rightSpacerDiv = newDiv();
			rightSpacerDiv.className = "panel galleryMenuSpacer";
			menuContainerDiv.appendChild(rightSpacerDiv);
		}
		catch (err) { throw this._error(err, "_create_HTML()"); }
	},

	_buildMenuContainer: function()
	{
		var menuContainerDiv = $get(this.menuContainerID);
		var leftSpacerDiv = newDiv();

		try
		{
			leftSpacerDiv.className = "panel galleryMenuSpacer";
			leftSpacerDiv.innerHTML = "&nbsp;";
			menuContainerDiv.appendChild(leftSpacerDiv);

			//Build "Photos:" Text
			var photoTextDiv = newDiv();
			photoTextDiv.className = "panel galleryMenuPhotosText";
			if (this.grid.data.length)
				photoTextDiv.innerHTML = "Photos:";
			else
				photoTextDiv.innerHTML = "  ";
			var containerPhotoTextDiv = newDiv();

			containerPhotoTextDiv.className = "panel galleryMenuPanels galleryMenuPhotoPanel";
			containerPhotoTextDiv.appendChild(photoTextDiv);
			menuContainerDiv.appendChild(containerPhotoTextDiv);
			return menuContainerDiv;
		}
		catch (err) { throw this._error(err, "_buildMenuContainer()"); }
	},

	load360Exterior: function()
	{
		try
		{
			this.grid.clear();
			this.grid.hideNavigationForVerticalNavigation(this.verticalNavigationContainerID, this.menuContainerID);
			this.activeDisplay._show360Exterior(this.grid.dataItems("360 Ext.")[0].Url);
		}
		catch (err) { throw this._error(err, "load360Exterior()"); }
	},

	load360Interior: function()
	{
		try
		{
			this.grid.clear();
			this.grid.hideNavigationForVerticalNavigation(this.verticalNavigationContainerID, this.menuContainerID);
			this.activeDisplay._show360Interior(this.grid.dataItems("360 Int.")[0].Url);
		}
		catch (err) { throw this._error(err, "load360Interior()"); }
	}
}
//======================================================================================================================================================================
//======================================================================================================================================================================

Type.registerNamespace('Vehix.Presentation.MediaActiveImage');

Vehix.Presentation.MediaActiveImage = function() {
	Vehix.Presentation.MediaActiveImage.initializeBase(this);
	//Private Properties
	var _imageContainer = null;
	var _currentImage = null;
	var _progressBarDiv = null;
	var _cancelHideProgressBarInterval = null;

	//public Properties
	this.ID = "activeDisplay";
	this.magnifyEnabled = false;
	this.activeImageContainer = null;  //Required
	this.largeProgressBarGif = null;  // Load progressbar externally
	this.imagePath = "none";
	this.defaultImagePath = "";
	this.showSoldBanner = false;
	this.imageArray = null;
	this.parent = null;
	this.showExceptions = false;
	this.sold = false;
	this.expired = false;
	this.slideShowDimmerClientID = ""; //Required  Note:  Div for Dimmer
	this.mediaSlideShow = null;
	this.iframe360 = null;
	this.iframeExteriorObj = null;
	this.iframeInteriorObj = null;
	this.defaultImageHasBeenLoaded = false;
	this.checkImageInterval = null;
}

Vehix.Presentation.MediaActiveImage.prototype =
{
	_error: function(err, funcName) {
		err.message = err.message + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage." + funcName + "\n";
		return err;
	},

	setParent: function(obj) {
		try {
			this.parent = obj;
		}
		catch (err) { throw this._error(err, "setParent()"); }
	},

	create: function() {
		try {
			this._buildImageContainer();
		}
		catch (err) { throw this._error(err, "create()"); }
	},

	load: function() {
		try {
			this.showImage(null, true);
		}
		catch (err) { throw this._error(err, "load()"); }
	},

	clear: function() {
		var childNodeCount = 0;
		var elem = null;

		try {
			childNodeCount = this._imageContainer.childNodes.length;
			if (childNodeCount > 0) {
				for (var i = 0; i < childNodeCount; i++)
					if (typeof (this._imageContainer.childNodes[i]) != "undefined")
					this._imageContainer.removeChild(this._imageContainer.childNodes[i]);

				this.clear();
			}
		}
		catch (err) { throw this._error(err, "clear()"); }
	},

	_show360Interior: function(url) {
		try {
			this.clear();
			this._shutDown360ExteriorViewIfOpen();
			this._show360InteriorIFrame(url);
		}
		catch (err) { throw this._error(err, "_show360Interior()"); }
	},

	_show360Exterior: function(url) {
		try {
			this.clear();
			this._shutDown360InteriorViewIfOpen();
			this._show360ExteriorIFrame(url);
		}
		catch (err) { throw this._error(err, "_show360Exterior()"); }
	},

	showLoadingProgressBar: function() {
		try {
			this._progressBarDiv = newDiv();
			this._progressBarDiv.style.display = "block";
			this._progressBarDiv.innerHTML = "LOADING...";
			this._progressBarDiv.appendChild(newBr());
			this._progressBarDiv.appendChild(this.largeProgressBarGif);
			this._imageContainer.appendChild(this._progressBarDiv);
			this._cancelHideProgressBarInterval = setInterval(this.parent.ID + "." + this.ID + ".hideProgressBar()", 10000);
		}
		catch (err) { throw this._error(err, "showLoadingProgressBar()"); }
	},

	_show360InteriorIFrame: function(url) {
		var media360Div = null;
		var media360Iframe = null;

		try {
			media360Iframe = $get("mediaBrowser360InteriorIframe");
			media360Div = $get("mediaBrowser360InteriorDiv");
			if (typeof (media360Iframe) != undefined && media360Iframe != null) {
				media360Iframe.style.display = "block";
				media360Div.style.display = "block";
			}
			else {
				media360Div = $get("mediaBrowser360InteriorDiv");
				media360Div.setAttribute("width", "320px");
				media360Div.setAttribute("height", "240px");

				if (!document.createElement)
					return true;

				var tempIFrame = document.createElement('iframe');
				tempIFrame.setAttribute('id', 'mediaBrowser360InteriorIframe');
				tempIFrame.setAttribute('name', 'mediaBrowser360InteriorIframe');
				tempIFrame.style.border = '0px';
				tempIFrame.setAttribute('frameBorder', '0');
				tempIFrame.setAttribute('border', 'none');
				tempIFrame.style.width = '320px';
				tempIFrame.style.height = '240px';
				tempIFrame.style.border = '0px';
				tempIFrame.setAttribute("scrolling", "no");
				tempIFrame.className = 'gallery360Iframe';
				this.iframeInteriorObj = media360Div.appendChild(tempIFrame);
				window.setTimeout(this.parent.ID + "." + this.ID + ".load360InteriorIframe(\"" + url + "\")", 10);
			}
		}
		catch (err) { throw this._error(err, "_show360InteriorIFrame()"); }
	},

	load360InteriorIframe: function(url) {
		var IFrameDoc;

		try {
			if (document.frames) {
				this.iframeInteriorObj = document.frames['mediaBrowser360InteriorIframe'];
			}

			if (this.iframeInteriorObj.contentWindow) {
				IFrameDoc = this.iframeInteriorObj.contentWindow.document;
			}
			else if (this.iframeInteriorObj) {
				IFrameDoc = this.iframeInteriorObj;
			}
			else {
				return true;
			}
			var params = "?width=320&height=240&videoPath=" + url;
			var path = gvx_ApplicationPath + "/_video/videoIframeSource.aspx" + params;
			IFrameDoc.location.replace(path);
		}
		catch (err) { throw this._error(err, "load360Iframe(url)"); }
	},

	_show360ExteriorIFrame: function(url) {
		var media360Div = null;
		var media360Iframe = null;

		try {
			media360Iframe = $get("mediaBrowser360ExteriorIframe");
			media360Div = $get("mediaBrowser360ExteriorDiv");
			//Check to see if Iframe is already built
			if (typeof (media360Iframe) != undefined && media360Iframe != null) {
				media360Iframe.style.display = "block";
				media360Div.style.display = "block";
			}
			else {
				media360Div = $get("mediaBrowser360ExteriorDiv");
				media360Div.setAttribute("width", "320px");
				media360Div.setAttribute("height", "239px");

				if (!document.createElement)
					return true;

				var tempIFrame = document.createElement('iframe');
				tempIFrame.setAttribute('id', 'mediaBrowser360ExteriorIframe');
				tempIFrame.setAttribute('name', 'mediaBrowser360ExteriorIframe');
				tempIFrame.setAttribute('frameBorder', '0');
				tempIFrame.setAttribute('border', '0');
				tempIFrame.style.width = '320px';
				tempIFrame.style.height = '239px';
				tempIFrame.style.border = '0px';
				tempIFrame.setAttribute("scrolling", "no");
				tempIFrame.className = 'gallery360Iframe';
				this.iframeExteriorObj = media360Div.appendChild(tempIFrame);

				window.setTimeout(this.parent.ID + "." + this.ID + ".load360ExteriorIframe(\"" + url + "\")", 10);
			}
		}
		catch (err) { throw this._error(err, "_show360ExteriorIFrame()"); }
	},

	load360ExteriorIframe: function(url) {
		var IFrameDoc;

		try {
			if (document.frames) {
				this.iframeExteriorObj = document.frames['mediaBrowser360ExteriorIframe'];
			}

			if (this.iframeExteriorObj.contentWindow) {
				// For FF, IE5.5 and IE6 
				IFrameDoc = this.iframeExteriorObj.contentWindow.document;
			}
			else if (this.iframeExteriorObj) {
				// For IE7
				IFrameDoc = this.iframeExteriorObj;
			}
			else {
				return true;
			}
			var params = "?width=320&height=240&videoPath=" + url;
			var path = gvx_ApplicationPath + "/_video/videoIframeSource.aspx" + params;
			IFrameDoc.location.replace(path);
		}
		catch (err) { throw this._error(err, "load360ExteriorIframe()"); }
	},

	hideProgressBar: function() {
		try {
			if (this._cancelHideProgressBarInterval != null && this._cancelHideProgressBarInterval > 0) {
				clearInterval(this._cancelHideProgressBarInterval);
			}
			if (typeof (this._progressBarDiv) != "undefined" && this._progressBarDiv != null) {
				this._progressBarDiv.style.display = "none";
			}
		}
		catch (err) { throw this._error(err, "hideProgressBar()"); }
	},

	_shutDown360InteriorViewIfOpen: function() {
		var threeSixtyContainerDiv = null;
		var threeSixtyIframe = null;

		try {
			threeSixtyContainerDiv = $get("mediaBrowser360InteriorDiv");
			threeSixtyIframe = $get("mediaBrowser360InteriorIframe");
			if (threeSixtyContainerDiv != null && threeSixtyIframe != null) {
				threeSixtyContainerDiv.setAttribute("width", "0px");
				threeSixtyContainerDiv.setAttribute("height", "0px");
				threeSixtyIframe.setAttribute("width", "0");
				threeSixtyIframe.setAttribute("height", "0");
				threeSixtyContainerDiv.style.display = "none";
				threeSixtyIframe.style.display = "none";
			}
		}
		catch (err) { throw this._error(err, "_shutDown360InteriorViewIfOpen()"); }
	},

	_shutDown360ExteriorViewIfOpen: function() {
		var threeSixtyContainerDiv = null;
		var threeSixtyIframe = null;

		try {
			threeSixtyContainerDiv = $get("mediaBrowser360ExteriorDiv");
			threeSixtyIframe = $get("mediaBrowser360ExteriorIframe");
			if (threeSixtyContainerDiv != null && threeSixtyIframe != null) {
				threeSixtyContainerDiv.setAttribute("width", "0px");
				threeSixtyContainerDiv.setAttribute("height", "0px");
				threeSixtyContainerDiv.style.display = "none";
				threeSixtyIframe.setAttribute("width", "0");
				threeSixtyIframe.setAttribute("height", "0");
				threeSixtyIframe.style.display = "none";
			}
		}
		catch (err) { throw this._error(err, "_shutDown360ExteriorViewIfOpen()"); }
	},

	//Show the Active Image
	showImage: function(image, useDefault) {
		var displayImage = null;
		var imageSource = "";

		try {
			this._shutDown360ExteriorViewIfOpen();
			this._shutDown360InteriorViewIfOpen();
			this._currentImage = null;
			var displayImage = new Image();
			if (typeof (useDefault) != 'undefined' && useDefault) {
				displayImage.className = "galleryLargeImage";
				if (this.defaultImagePath != "") {
					var displayImage = new Image();
					displayImage.src = this.defaultImagePath;
					if (((this.defaultImagePath.toLowerCase().indexOf("homenetmedia") > 1) || (this.defaultImagePath.toLowerCase().indexOf("sellers") > 1)) && this.sold == false && this.expired == false)
						this.magnifyEnabled = true;
				}
				else
					throw "Default Image Unavailable\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.showImage(image, useDefault)\n";
			}
			else //if useDefault is not set to true then try to set the activeImage to the image passed in.
			{
				this.clear();
				imageSource = (image != null) ? image.src : "";
				if ((imageSource.toLowerCase().indexOf("evox") || imageSource.toLowerCase().indexOf("homenetmedia")) > 1 && imageSource.toLowerCase().indexOf("stills_0640"))
					this.magnifyEnabled = true;

				try {
					var img = this.imageArray[parseInt(image.getAttribute("id").replace("thumb", ""))];
					displayImage = new Image();
					displayImage.id = img.id;
					displayImage.src = img.src;
					displayImage.lowsrc = img.lowsrc;
					displayImage.style.height = "280px";
					displayImage.className = "galleryLargeImage";
				}
				catch (err) {
					var errorMsg = "";
					if (typeof (image) != 'undefined' && image == null)
						errorMsg = "\nThe image parameter passed into the Vehix.Presentation.MediaActiveImage.showImage(image, useDefault) method is null. The useDefault parameter is also not set: ";

					throw err + errorMsg + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.showImage(image, useDefault)";
				}
			}

			this._currentImage = displayImage;
			if (typeof (useDefault) != 'undefined' && useDefault)
				this._currentImage.style.display = "none";
			this._currentImage.imageObj = this;
			this._currentImage.onmouseover = function() {
				try {
					this.imageObj.parent.unlockGrid();
				}
				catch (mouseErr) {
					throw mouseErr + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.showImage(image, useDefault) --> onmouseover()";
				}
			};

			this._currentImage.useDefault = useDefault;
			this._currentImage.onload = function() {
				try {
					this.imageObj.checkDimensionsAndSwapLoadingImage(this.useDefault);
				}
				catch (onloadErr) {
					throw onloadErr + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.showImage(image, useDefault) --> onload()";
				}
			};

			if (typeof (useDefault) != 'undefined' && useDefault)
				this.checkImageInterval = setInterval(this.parent.ID + "." + this.ID + ".checkImageDimensions(" + useDefault.toString() + ")", 150);

			if (this.defaultImageHasBeenLoaded)
				this.checkDimensionsAndSwapLoadingImage(useDefault);

			this._imageContainer.appendChild(this._currentImage);

			if (this.sold) {
				this._showSoldOverlay();
			}
			else {
				this.displayMagnifyGlassImage();
				this.displaySlideShowImage();
			}
		}
		catch (err) { throw this._error(err, "showImage(image, useDefault)"); }
	},

	//Insurance -- For back button suport.
	checkImageDimensions: function(useDefault) {
		try {
			if (typeof (this._currentImage) != 'undefined' && this._currentImage != null) {
				if (this._currentImage.width > 365) //Active Image has NOT been resized.
				{
					this.checkDimensionsAndSwapLoadingImage(useDefault);
				}
				else if (this._currentImage.complete) //Active Image has been resized and is completly loaded.
				{
					this._currentImage.style.display = "block";
					clearInterval(this.checkImageInterval);
				}
			}
		}
		catch (err) { throw this._error(err, "checkImageDimensions(useDefault)"); }
	},

	///Need to impliment progress bar
	checkDimensionsAndSwapLoadingImage: function(useDefault) {
		try {
			if (typeof (useDefault) != 'undefined' && useDefault) {
				if (this.defaultImagePath != "") {
					var width = this._currentImage.width;
					var height = this._currentImage.height;

					while (width > 360 || height > 270) {
						width = (width * .75)
						height = (height * .75)
					}

					this._currentImage.width = width;
					this._currentImage.height = height;
					this._currentImage.style.paddingTop = Math.floor(((280 - height) / 2)) + 'px';
					this._currentImage.style.paddingLeft = Math.floor(((360 - width) / 2)) + 'px';
					this.defaultImageHasBeenLoaded = true;
					this.hideProgressBar();
					this._currentImage.style.display = "block";
				}
			}
		}
		catch (err) { throw this._error(err, "checkDimensionsAndSwapLoadingImage()"); }
	},

	_showSoldOverlay: function() {
		var soldOverLayDiv = newDiv();
		var soldImage = newImage();

		try {
			soldImage.className = "gallerySoldOverlayImage";
			if (this.expired) {
				soldImage.src = gvx_ApplicationPath + '/_images/expiredoverlay.gif';
			}
			else {
				soldImage.src = gvx_ApplicationPath + '/_images/SoldOverlay.gif';
			}
			soldOverLayDiv.className = "gallerySoldOverlayContainerDiv";
			soldOverLayDiv.appendChild(soldImage);
			this._imageContainer.appendChild(soldOverLayDiv);
		}
		catch (err) { throw this._error(err, "_showSoldOverlay()"); }
	},

	//Determine if the magnifying glass needs to be displayed
	displayMagnifyGlassImage: function() {
		var anchor = newAnchor();
		var magnifyGlassImage = newImage();

		try {
			if (this.magnifyEnabled) {
				anchor.activeImageObj = this;
				anchor.onclick = function() {
					try {
						this.activeImageObj.doMagifyImage();
					}
					catch (onclickErr) {
						throw onclickErr + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.displayMagnifyGlassImage() -->onclick()"
					};
				}
				anchor.className = "galleryImageMagnifier";
				anchor.setAttribute("style", "display: block");
				anchor.setAttribute("title", "Magnify");
				magnifyGlassImage.src = gvx_ApplicationPath + "/_images/magnify.gif";
				magnifyGlassImage.setAttribute("style", "border-width: 0px;cursor:pointer;cursor:hand;");
				anchor.appendChild(magnifyGlassImage);
				this._imageContainer.appendChild(anchor);
			}
		}
		catch (err) { throw this._error(err, "displayMagnifyGlassImage()"); }
	},

	//Determine if the slide show image needs to be displayed
	displaySlideShowImage: function() {
		var anchor = newAnchor();
		var slideShowImage = newImage();

		try {
			if (this.parent != null && this.parent.grid != null) {
				if (this.parent.grid.currentImageSet != "none" && this.parent.grid.dataItems(this.parent.grid.currentImageSet) != null && this.parent.grid.dataItems(this.parent.grid.currentImageSet).length > 1) {
					anchor.activeImageObj = this;
					anchor.onclick = function() {
						try {
							this.activeImageObj.doSlideShow();
						}
						catch (onclickErr) {
							throw onclickErr + "\n :: Stack Trace: Vehix.Presentation.MediaActiveImage.displaySlideShowImage() -->onclick()"
						};
					}
					anchor.className = "gallerySlidShowImage";
					anchor.setAttribute("style", "display: block");
					anchor.setAttribute("title", "Slideshow");
					slideShowImage.src = gvx_ApplicationPath + "/_images/slideShow.gif";
					slideShowImage.setAttribute("style", "border-width: 0px;cursor:pointer;cursor:hand;");
					anchor.appendChild(slideShowImage);
					this._imageContainer.appendChild(anchor);
				}
			}
			else {
				alert("The slide show is unavailable at the moment, please check back later");
			}
		}
		catch (err) { throw this._error(err, "displaySlideShow()"); }
	},

	doMagifyImage: function() {
		try {
			if (this.slideShowDimmerClientID != "") {
				this.mediaSlideShow = new Vehix.Presentation.MediaSlideShow(this, this.slideShowDimmerClientID);
				this.mediaSlideShow.showMagnifiedImage(this._currentImage);
			}
		}
		catch (err) { throw this._error(err, "doMagifyImage()"); }
	},

	doSlideShow: function() {
		try {
			if (this.slideShowDimmerClientID != "") {
				this.mediaSlideShow = new Vehix.Presentation.MediaSlideShow(this, this.slideShowDimmerClientID);
				this.mediaSlideShow.buildSlideShow(this.parent.grid.imageArrayLarge);
				this.mediaSlideShow.autoSlideShowBegin()
			}
		}
		catch (err) { throw this._error(err, "doSlideShow()"); }
	},

	_buildImageContainer: function() {
		try {
			this._imageContainer = newDiv();
			//this._imageContainer.className = "panel galleryActive galleryWidth";
			this._imageContainer.setAttribute("id", "mediaActiveImage");
			this._imageContainer.style.height = "280px";
			$get(this.activeImageContainer).appendChild(this._imageContainer);
		}
		catch (err) { throw this._error(err, "_buildImageContainer()"); }
	}
}

//======================================================================================================================================================================
//======================================================================================================================================================================

Type.registerNamespace('Vehix.Presentation.MediaGrid');
Vehix.Presentation.MediaGrid = function() {
    Vehix.Presentation.MediaGrid.initializeBase(this);

    //private
    var _totalColumns = 0;
    var _moveRightElement = null;
    var _moveLeftElement = null;
    var _mediaArrowImageLeft = null;
    var _mediaArrowImageRight = null;
    var _gridPanelElement = null;
    var _setsOfThree = 0;
    var _setsOfNine = 0;
    var _insureThumbNailsLoadInterval;
    var _fullResolutionThumbsonOnLoadInvoked = false;
    var _columnsRemainingToScroll = 0;

    //public
    //scrolling
    this.scrollLeftInterval;
    this.scrollRightInterval;
    this.scrollAmount = 10;
    this.scrollContainerWidth = 302;
    this.scrollContentWidth = 0;
    this.imageCount = 0;
    this.imageWidth = 100;
    this.timeLapse = 100;
    this.mediaBrowserContainerID = "";
    this.rowCount = 0;


    //values for grid layout and activeimage implementation.
    this.ID = "grid"; 	//Required -- This is the name of the custom Name (ex: "grid") given to this object after instantiated it---> var grid = Vehix.Presentation.MediaGrid(); this is needed because the I need a window.setTimeOut wich happens on the window level.
    this.gridContainerID = ""; 		//Required
    this.data = null; 	//Required
    this.parent = null; 	//Is required for onmouseoverevent
    this.imageArrayLarge = null;
    this.imageArrayDealerSmall = null;
    this.imageArrayMFRSmall = null;
    this.currentlyLoadedImageSet = "";

    this.activateOnMouseEvents = false;
    this.maxRowCount = 3;
    this.backgroundColor = "#eeeeee"
    this.moveButtonsPanelColor = "#ffffff";
    this.thumbHeight = "75px";
    this.thumbWidth = "100px";
    this.currentImageSet = "Dealer"; //Default to dealer imageset
    this.disableMouseOver = false;
    this.thumbLoadingImage = null;
    this.overrideAndLoadSinglePanel = false;
}

Vehix.Presentation.MediaGrid.prototype =
{
	_error: function(err, funcName) {
		err.message = err.message + "\n :: Stack Trace: Vehix.Presentation.MediaGrid." + funcName + "\n";
		return err;
	},

	bind: function(obj, fnc) {
		temp = function() {
			return fnc.apply(obj, arguments);
		};

		return temp;
	},

	setParent: function(parent) {
		try {
			this.parent = parent;
		}
		catch (err) { throw this._error(err, "setParent()") }
	},

	clear: function() {
		var childNodeCount = 0;
		var elem = null;

		try {
			if (typeof (this._gridPanelElement) != "undefined" && this._gridPanelElement != null) {
				childNodeCount = this._gridPanelElement.childNodes.length;
				if (childNodeCount > 0) {
					if (typeof (this._gridPanelElement.childNodes[0]) != "undefined")
						this._gridPanelElement.removeChild(this._gridPanelElement.childNodes[0]);
					this.clear();
				}
				this.disableNavigation();
				this.imageArrayLarge = new Array();
				this.currentlyLoadedImageSet = "";
			}
		}
		catch (err) { throw this._error(err, "clear()") }
	},

	create: function() {
		try {
			if (this.currentImageSet != "none") {
				this._create_HTML();
				this.load();
			}
		}
		catch (err) { throw this._error(err, "create()") }
	},

	load: function() {
		var panelSets = 0;

		try {
			if (this.data.length) {
				this._renderNavigation();
				this.imageCount = this.dataItems(this.currentImageSet).length;
				panelSets = (((this._totalColumns) % 3) != 0) ? (Math.floor((this._totalColumns) / 3)) + 1 : Math.floor((this._totalColumns) / 3);
				if (this.overrideAndLoadSinglePanel) {
					this._loadImagesSinglePanel();
				}
				else {
					if (this.imageCount > 9) {
						this._setsOfThree = panelSets;
						this._loadImagesVertically();
					}
					else {
						this._setsOfNine = panelSets;
						this._loadImagesHorizontally();
					}
				}
			}
			this.loadLargeImageArray();
		}
		catch (err) { throw this._error(err, "load()") }
		finally {
			//This is a hack to get around IE's craptacular way of handling the the onload event of an image.
			this._insureThumbNailsLoadInterval = setInterval(this.parent.ID + "." + this.ID + "._insureThumbsLoad()", 50);
		}
	},


	_loadImagesVertically: function() {
		var thumbDiv = null;
		var setsOfThreeDiv = null;
		var imageNumber = 0;
		var rowsWithinSetCount = 3;

		try {
			imageArrayIsLoaded = this._isImageArrayLoaded();
			this._fullResolutionThumbsonOnLoadInvoked = false;
			for (var i = 0; i < this._totalColumns; i++) {
				setsOfThreeDiv = newDiv();
				setsOfThreeDiv.className = "gallerySetOfThreeDiv";
				for (var j = 0; j < rowsWithinSetCount; j++) {
					if (imageNumber < this.imageCount) {
						thumbDiv = newDiv();
						thumbDiv.setAttribute("id", "galleryThumbnailContainer" + imageNumber.toString());
						thumbDiv.className = "galleryThumbnailContainer";

						if (!imageArrayIsLoaded) {
							thumbDiv.appendChild(this._thumbLoadingGif());
							this._addThumb(imageNumber);
						}
						else
							thumbDiv.appendChild(this._getExistingSmallImage(imageNumber));

						setsOfThreeDiv.appendChild(thumbDiv);
						rowSeperator = newDiv();
						rowSeperator.className = "galleryThumbnailRowSeperator";
						setsOfThreeDiv.appendChild(rowSeperator);
						imageNumber++;
					}
					else
						break;
				}
				this._gridPanelElement.appendChild(setsOfThreeDiv);
			}
		}
		catch (err) { throw this._error(err, "_loadImagesVertically()") }
	},


	_loadImagesHorizontally: function() {
		var thumbDiv = null;
		var rowSeperator = null;
		var setOfNineDiv = null;
		var imageNumber = 0;
		var rowsWithinSetCount = 3;
		var colsWithinSetCount = 3;
		var needRowDivider = false;
		var loadingImage = null;
		var finishedLoading = false;
		var imageArrayIsLoaded = false;

		try {
			if (this.data.length) {
				this._renderNavigation();
				this.imageCount = this.dataItems(this.currentImageSet).length;
				imageArrayIsLoaded = this._isImageArrayLoaded();
				this._fullResolutionThumbsonOnLoadInvoked = false;
				for (var i = 0; i < this._setsOfNine; i++) {
					setOfNineDiv = newDiv();
					setOfNineDiv.className = "gallerySetOfNineDiv";
					for (var j = 0; j < rowsWithinSetCount; j++) {
						for (k = 0; k < colsWithinSetCount; k++) {
							if (imageNumber < this.imageCount) {
								thumbDiv = newDiv();
								thumbDiv.setAttribute("id", "galleryThumbnailContainer" + imageNumber.toString());
								thumbDiv.className = "galleryThumbnailContainer";

								if (!imageArrayIsLoaded) {
									thumbDiv.appendChild(this._thumbLoadingGif());
									this._addThumb(imageNumber);
								}
								else
									thumbDiv.appendChild(this._getExistingSmallImage(imageNumber));

								setOfNineDiv.appendChild(thumbDiv);
								imageNumber++;
							}
							else {
								finishedLoading = true;
								break;
							}
							needRowDivider = true;
						}
						if (needRowDivider) {
							rowSeperator = newDiv();
							rowSeperator.className = "galleryThumbnailRowSeperator";
							setOfNineDiv.appendChild(rowSeperator);
							needRowDivider = false;
						}
						if (finishedLoading)
							break;
					}
					this._gridPanelElement.appendChild(setOfNineDiv);
					if (finishedLoading)
						break;
				}

			}
			this.loadLargeImageArray();
		}
		catch (err) { throw this._error(err, "_loadImagesHorizontally()") }
		finally {
			//This is a hack to get around IE's craptacular way of handling the the onload event of an image.
			this._insureThumbNailsLoadInterval = setInterval(this.parent.ID + "." + this.ID + "._insureThumbsLoad()", 10);
		}
	},

	_loadImagesSinglePanel: function() {
		var thumbDiv = null;
		var rowSeperator = null;
		var singlePanelDiv = null;

		var imageNumber = 0;
		var rowsWithinSetCount = 1;
		var colsWithinSetCount = 6;
		var needRowDivider = false;
		var loadingImage = null;
		var finishedLoading = false;
		var imageArrayIsLoaded = false;
		var totalImagesHeight = 0;

		try {
			if (this.data.length && this.currentlyLoadedImageSet != this.currentImageSet) {
				this.rowCount = 0; //reset rowCount.
				this.currentlyLoadedImageSet = this.currentImageSet;
				this.imageCount = this.dataItems(this.currentImageSet).length;
				rowsWithinSetCount = Math.abs(Math.floor((this.imageCount / 6)));
				if ((this.imageCount / 6) > rowsWithinSetCount)
					rowsWithinSetCount++;

				totalImagesHeight = ((rowsWithinSetCount * 75) + 10);
				imageArrayIsLoaded = this._isImageArrayLoaded();
				this._fullResolutionThumbsonOnLoadInvoked = false;
				singlePanelDiv = newDiv();
				singlePanelDiv.className = "gallerySinglePanelDivDiv";
				singlePanelDiv.id = "gallerySinglePanel";
				for (var j = 0; j < rowsWithinSetCount; j++) {
					for (k = 0; k < colsWithinSetCount; k++) {
						if (imageNumber < this.imageCount) {
							thumbDiv = newDiv();
							thumbDiv.setAttribute("id", "galleryThumbnailContainer" + imageNumber.toString());
							thumbDiv.className = "galleryThumbnailContainer";

							if (!imageArrayIsLoaded) {
								thumbDiv.appendChild(this._thumbLoadingGif());
								this._addThumb(imageNumber);
							}
							else
								thumbDiv.appendChild(this._getExistingSmallImage(imageNumber));

							singlePanelDiv.appendChild(thumbDiv);
							imageNumber++;
						}
						else {
							finishedLoading = true;
							break;
						}
						needRowDivider = true;
					}
					if (needRowDivider) {
						rowSeperator = newDiv();
						rowSeperator.className = "galleryThumbnailRowSeperator";
						singlePanelDiv.appendChild(rowSeperator);
						needRowDivider = false;
						this.rowCount++;
					}
					if (finishedLoading)
						break;
				}
				this._gridPanelElement.appendChild(singlePanelDiv);
			}
			this.loadLargeImageArray();
		}
		catch (err) { throw this._error(err, "_loadImagesSinglePanel()") }
		finally {
			//This is a hack to get around IE's craptacular way of handling the the onload event of an image.
			this._insureThumbNailsLoadInterval = setInterval(this.parent.ID + "." + this.ID + "._insureThumbsLoad()", 10);
		}
	},

	_insureThumbsLoad: function() {
		try {
			if (!this._fullResolutionThumbsonOnLoadInvoked) {
				if (((this.currentImageSet == "Dealer" || this.currentImageSet == "Seller") && this.imageArrayDealerSmall != null) && this.imageArrayDealerSmall.length > 0) {
					clearInterval(this._insureThumbNailsLoadInterval);
					this.parent.reloadDealer();
					this._fullResolutionThumbsonOnLoadInvoked = true;
				}
				else if ((this.currentImageSet == "Manufacturer" && this.imageArrayMFRSmall != null) && this.imageArrayMFRSmall.length > 0) {
					clearInterval(this._insureThumbNailsLoadInterval);
					this.parent.reloadManufacturer();
					this._fullResolutionThumbsonOnLoadInvoked = true;
				}
				else {
					clearInterval(this._insureThumbNailsLoadInterval);
				}
			}
			else {
				clearInterval(this._insureThumbNailsLoadInterval);
			}
		}
		catch (err) { throw this._error(err, "_insureThumbsLoad()") }
	},

	_isImageArrayLoaded: function() {
		var retVal = false;

		try {
			if (((this.currentImageSet == "Dealer" || this.currentImageSet == "Seller") && this.imageArrayDealerSmall != null) && this.imageArrayDealerSmall.length > 0)
				retVal = true;
			else if ((this.currentImageSet == "Manufacturer" && this.imageArrayMFRSmall != null) && this.imageArrayMFRSmall.length > 0)
				retVal = true;

			return retVal;
		}
		catch (err) { throw this._error(err, "_isImageArrayLoaded()") }
	},

	_getExistingSmallImage: function(imageNumber) {
		try {
			if (this.currentImageSet == "Dealer" || this.currentImageSet == "Seller") {
				return this.imageArrayDealerSmall[imageNumber];
			}

			if (this.currentImageSet == "Manufacturer") {
				return this.imageArrayMFRSmall[imageNumber];
			}
		}
		catch (err) { throw this._error(err, "_getExistingSmallImage(imageNumber)") }
	},

	dataItems: function(name) {
		var found = false;

		try {
			for (var i = 0; i < this.data.length; i++) {
				if (this.data[i].Name == name) {
					found = true;
					return this.data[i].Items;
					break;
				}
			}
			if (!found)
				return null;
		}
		catch (err) { throw this._error(err, "dataItems(name)") }
	},


	_thumbLoadingGif: function() {
		var loadingImage = newImage();

		try {
			loadingImage.setAttribute("height", this.thumbHeight);
			loadingImage.setAttribute("width", this.thumbWidth);
			loadingImage.src = gvx_ApplicationPath + '/_images/loading_thumbs.gif';
			return loadingImage;
		}
		catch (err) { throw this._error(err, "_thumbLoadingGif()") }
	},

	_addThumb: function(increment) {
		var thumb = new Image();

		try {
			$(thumb).attr({ id: "thumb" + increment.toString(),
				height: this.thumbHeight,
				width: this.thumbWidth,
				index: increment.toString()
			});
			
			thumb.gridObj = this;

			thumb.onclick = function() {
				try {
					this.gridObj.lock();
					this.gridObj.parent.activeDisplay.magnifyEnabled = true;
					this.gridObj.parent.activeDisplay.showImage(this);
				}
				catch (eventErr) {
					throw eventErr + "\n :: Stack Trace: Vehix.Presentation.MediaGrid._addThumb(increment) -- > onclick()\n";
				}
			};
			if (this.parent != null)
				thumb.parentObj = this.parent; //Parent is MediaBrowser
			if (this.activateOnMouseEvents)
				thumb.onmouseover = function() {
					try {
						this.parentObj.onMouseOverThumb(this);
					}
					catch (eventErr) {
						throw eventErr + "\n :: Stack Trace: Vehix.Presentation.MediaGrid._addThumb(increment) --> onmouseover\n";
					}
				};

			if (this.currentImageSet == "Dealer" || this.currentImageSet == "Seller")
				this.imageArrayDealerSmall[increment] = thumb;

			if (this.currentImageSet == "Manufacturer")
				this.imageArrayMFRSmall[increment] = thumb;
		}
		catch (err) { throw this._error(err, "_addThumb(increment)") }
		finally {
			thumb.src = this.dataItems(this.currentImageSet)[increment].Thumbnail; //Be sure that the source is loaded last.
		}
	},

	_loadFullResolution: function(image) {
		var increment = "";
		var parentContainer = null;

		try {
			increment = image.id.replace("thumb", "");
			parentContainer = $get("galleryThumbnailContainer" + increment);
			if (typeof (parentContainer) != "undefined" && parentContainer != null && parentContainer.childNodes.length > 0) {
				parentContainer.removeChild(parentContainer.childNodes[0]);
				parentContainer.appendChild(image);
				this._fullResolutionThumbsonOnLoadInvoked = true;
			}
		}
		catch (err) { throw this._error(err, "_loadFullResolution(image)") }
	},

	loadLargeImageArray: function() {
		try {
			this.imageArrayLarge = new Array();
			for (var i = 0; i < this.imageCount; i++)
				this._addLargeImage(i);

			this.parent.activeDisplay.imageArray = this.imageArrayLarge;
		}
		catch (err) { throw this._error(err, "loadLargeImageArray()") }
	},

	_addLargeImage: function(increment) {
		try {
			largeImage = { "id": "image" + increment.toString(), "src": this.dataItems(this.currentImageSet)[increment].Url, "lowsrc": gvx_ApplicationPath + "/_images/loading_thumbs.gif" };
			this.imageArrayLarge[increment] = largeImage;
			return largeImage;
		}
		catch (err) { throw this._error(err, "_addLargeImage(increment)") }
	},

	_renderNavigation: function() {
		var thumbNailColumnCount = 0;
		var fullSetImageCount = 0;
		var lastSetImageCount = 0;
		var remainingColumns = 0;
		var minColumns = 3;

		try {
			if (this.data.length > 0 && this.currentImageSet != "none") {
				if (typeof (this._gridPanelElement) == "undefined" || this._gridPanelElement == null)
					this._create_HTML();

				this._gridPanelElement.style.left = "0px"; //reset grid scroll to starting point.
				this.disableMouseOver = false;
				this.imageCount = this.dataItems(this.currentImageSet).length;

				fullSetImageCount = Math.floor(this.imageCount / 9);
				lastSetImageCount = (this.imageCount % 9);
				remainingColumns = (lastSetImageCount > 3) ? (lastSetImageCount <= 6) ? 2 : (lastSetImageCount > 6) ? 3 : 1 : (lastSetImageCount == 0) ? 0 : 1;

				if (fullSetImageCount >= 1)
					this._totalColumns = (fullSetImageCount * 3) + remainingColumns;
				else if (fullSetImageCount < 1)
					this._totalColumns = remainingColumns;

				if (this._totalColumns > minColumns) {
					this._mediaArrowImageLeft.style.display = "block";
					this._mediaArrowImageRight.style.display = "block";
					this._moveLeftElement.style.backgroundColor = this.moveButtonsPanelColor;
					this._moveRightElement.style.backgroundColor = this.moveButtonsPanelColor;
					this._moveRightElement.className = "galleryGridMoveRight";
					this._moveLeftElement.className = "galleryGridMoveLeft";
					this._enableMouseEvents();
				}
				else
					this.disableNavigation();

				this._columnsRemainingToScroll = this._totalColumns;
			}
		}
		catch (err) { throw this._error(err, "_renderNavigation()") }
	},

	disableNavigation: function() {
		try {
			this._mediaArrowImageLeft.style.display = "none";
			this._mediaArrowImageRight.style.display = "none";
			this._moveLeftElement.style.backgroundColor = this.backgroundColor;
			this._moveRightElement.style.backgroundColor = this.backgroundColor;
			this._moveRightElement.className = "galleryGridMoveRightOff";
			this._moveLeftElement.className = "galleryGridMoveLeftOff";
			this._disableMouseEvents();
		}
		catch (err) { throw this._error(err, "disableNavigation()") }
	},

	lock: function() {
		try {
			if (!this.disableMouseOver)
				this.disableMouseOver = true;
			else
				this.disableMouseOver = false;
		}
		catch (err) { throw this._error(err, "lock()") }
	},

	_create_HTML: function() {
		var gridContainerElement = $get(this.gridContainerID);
		var moveLeftPanelElement = newDiv();
		var moveRightPanelElement = newDiv();
		var moveRightArrowImage = new Image();
		var moveLeftArrowImage = new Image();
		var gridFrameElement = newDiv();
		var gridElement = newDiv();

		try {
			if (this.data.length > 0 && this.currentImageSet != "none") {
				if (this.activateOnMouseEvents)
					this._checkOnMouseEventDependancy();

				//<DIV ID="MoveLeft">
				moveLeftArrowImage.setAttribute("ID", "MediaArrowLeft");
				moveLeftArrowImage.setAttribute("src", gvx_ApplicationPath + "/_images/mediagridleftarrow.gif");
				moveLeftArrowImage.className = "image galleryGridLeftArrow";
				this._mediaArrowImageLeft = moveLeftArrowImage;

				moveLeftPanelElement.setAttribute("ID", "MoveLeft");
				moveLeftPanelElement.className = "panel galleryGridMoveLeft";
				moveLeftPanelElement.appendChild(moveLeftArrowImage);
				moveLeftPanelElement.gridObj = this;
				if (this.activateOnMouseEvents) {
					if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
						moveLeftPanelElement.onclick = function() { this.gridObj.doMoveColumnsRight(1); }
						moveLeftPanelElement.onclick = function() { this.gridObj.doMoveColumnsLeft(-1); }
					}
					else {
						moveLeftPanelElement.onmouseover = function() { this.gridObj.doScrollLeft(); }
						moveLeftPanelElement.onmouseout = function() { this.gridObj.stopScroll(); }
					}
				}
				this._moveLeftElement = moveLeftPanelElement;
				gridContainerElement.appendChild(this._moveLeftElement);
				//</Div>

				//<DIV ID="GridFrame">
				gridElement.setAttribute("ID", "Grid");
				gridElement.className = "panel galleryImageGrid";
				gridElement.style.backgroundColor = this.backgroundColor;
				this._gridPanelElement = gridElement;
				gridFrameElement.setAttribute("ID", "GridFrame");
				gridFrameElement.className = "panel galleryImageGridFrame";
				gridFrameElement.appendChild(gridElement);
				gridContainerElement.appendChild(gridFrameElement);
				//</DIV>

				//<DIV ID="MoveRight">						
				moveRightArrowImage.setAttribute("ID", "MediaArrowRight");
				moveRightArrowImage.setAttribute("src", gvx_ApplicationPath + "/_images/mediagridrightarrow.gif");
				moveRightArrowImage.className = "image galleryGridRightArrow";
				this._mediaArrowImageRight = moveRightArrowImage;
				moveRightPanelElement.setAttribute("ID", "MoveRight");
				moveRightPanelElement.className = "panel galleryGridMoveRight";
				moveRightPanelElement.gridObj = this;
				if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
					moveRightPanelElement.onclick = function() { this.gridObj.doMoveColumnsRight(1); }
					moveRightPanelElement.onclick = function() { this.gridObj.doMoveColumnsRight(-1); }
				}
				else {
					moveRightPanelElement.onmouseover = function() { this.gridObj.doScrollRight(); }
					moveRightPanelElement.onmouseout = function() { this.gridObj.stopScroll(); }
				}
				moveRightPanelElement.appendChild(moveRightArrowImage);
				this._moveRightElement = moveRightPanelElement;
				gridContainerElement.appendChild(this._moveRightElement);
				//</DIV>
			}
			else {
				$get("panelMenuPhotoText").style.display = "none";
			}
		}
		catch (err) { throw this._error(err, "_create_HTML()") }
	},

	_disableMouseEvents: function() {
		try {
			this._moveLeftElement.onclick = null;
			this._moveLeftElement.onclick = null;
			this._moveLeftElement.onmouseover = null;
			this._moveLeftElement.onmouseout = null;

			this._moveRightElement.onclick = null;
			this._moveRightElement.onclick = null;
			this._moveRightElement.onmouseover = null;
			this._moveRightElement.onmouseout = null;
		}
		catch (err) { throw this._error(err, "_disableMouseEvents()") }
	},

	_enableMouseEvents: function() {
		try {
			if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
				this._moveRightElement.onclick = function() { this.gridObj.doMoveColumnsRight(1); }
				this._moveRightElement.onclick = function() { this.gridObj.doMoveColumnsRight(-1); }
				this._moveLeftElement.onclick = function() { this.gridObj.doMoveColumnsRight(1); }
				this._moveLeftElement.onclick = function() { this.gridObj.doMoveColumnsLeft(-1); }
			}
			else {
				this._moveRightElement.onmouseover = function() { this.gridObj.doScrollRight(); }
				this._moveRightElement.onmouseout = function() { this.gridObj.stopScroll(); }
				this._moveLeftElement.onmouseover = function() { this.gridObj.doScrollLeft(); }
				this._moveLeftElement.onmouseout = function() { this.gridObj.stopScroll(); }
			}
		}
		catch (err) { throw this._error(err, "_enableMouseEvents()") }
	},

	_checkOnMouseEventDependancy: function() {
		try {
			if (this.parent === null)
				throw "Exception Occured!  Please set the Parent Object.  Also be sure to set the Parent ID";
			if (this.parent.ID === null)
				throw "Exception Occured! Please set the ID property of the parent"
			if (this.parent.onMouseOverMethodName === null)
				throw "Exception Occured! Please set the 'onMouseOverMethodName' property of the parent"
		}
		catch (err) { throw this._error(err, "_checkOnMouseEventDependancy()") }
	},

	doMoveColumnsLeft: function(increment) {
		var columnsScrolled = 0;
		var currentLocation = 0;
		var preLoadedColumns = 0;

		try {
			preLoadedColumns = (this._totalColumns >= 3) ? 3 : this._totalColumns;
			backLocation = Math.abs(Math.floor((this._columnsRemainingToScroll + preLoadedColumns) / 3));
			backLocation = (backLocation >= 1) ? backLocation = 3 : this._columnsRemainingToScroll + preLoadedColumns;
			currentLocation = Math.abs(Number(this._gridPanelElement.style.left.replace('px', '')));
			columnsScrolled = backLocation;
			backLocation = (currentLocation - (backLocation * 100)) * -1;
			if (backLocation > 0) {
				backLocation = 0;
				this._columnsRemainingToScroll = this._totalColumns;
			}

			if (Number(this._gridPanelElement.style.left.replace('px', '')) < 0) {
				this._gridPanelElement.style.left = (backLocation + 2).toString() + 'px';
				if (backLocation != 0)
					this._columnsRemainingToScroll = this._columnsRemainingToScroll + columnsScrolled;
			}
		}
		catch (err) { throw this._error(err, "doMoveColumnsLeft(increment)") }
	},

	doMoveColumnsRight: function(increment) {
		var columnsScrolled = 0;
		var currentLocation = 0;
		var nextLocation = 0;
		var preLoadedColumns = 0;

		try {
			preLoadedColumns = (this._totalColumns >= 3) ? 3 : this._totalColumns;
			currentLocation = Math.abs(Number(this._gridPanelElement.style.left.replace('px', '')));
			nextLocation = Math.floor((this._columnsRemainingToScroll - preLoadedColumns) / 3);
			nextLocation = (nextLocation >= 1) ? 3 : this._columnsRemainingToScroll - preLoadedColumns;
			columnsScrolled = nextLocation;
			nextLocation = (currentLocation + (nextLocation * 100)) * -1;
			if (((this._totalColumns * 100) >= currentLocation) && (Math.abs(nextLocation) - Math.abs(Math.abs(currentLocation))) > 90) {
				this._gridPanelElement.style.left = (nextLocation - 2).toString() + 'px';
				this._columnsRemainingToScroll = this._columnsRemainingToScroll - columnsScrolled;
			}
		}
		catch (err) { throw this._error(err, "doMoveColumnsRight(increment)") }
	},

	//Srolling Methods - These are public only because the setTimeOut Method was needed is invoked on the window level.
	doScrollRight: function() {
		try {
			this.scrollRightInterval = setInterval(this.parent.ID + "." + this.ID + ".scrollGridRight()", this.timeLapse);
		}
		catch (err) { throw this._error(err, "doScrollRight()") }
	},

	scrollGridRight: function() {
		try {
			var currentLeftLocation = Number(this._gridPanelElement.style.left.replace('px', ''));
			if (currentLeftLocation >= -((this._totalColumns - 3) * 100))
				this._gridPanelElement.style.left = (currentLeftLocation - this.scrollAmount) + 'px';

			if (Number(this._gridPanelElement.style.left.replace('px', '')) < -((this._totalColumns - 3) * 100)) {
				clearInterval(this.scrollRightInterval);
			}
		}
		catch (err) { throw this._error(err, "scrollGridRight()") }
	},

	doScrollLeft: function() {
		try {
			this.scrollLeftInterval = setInterval(this.parent.ID + "." + this.ID + ".scrollGridLeft()", this.timeLapse);
		}
		catch (err) { throw this._error(err, "doScrollLeft()") }
	},

	scrollGridLeft: function() {
		try {
			var i = Number(this._gridPanelElement.style.left.replace('px', ''));
			this._gridPanelElement.style.left = (i + this.scrollAmount) + 'px';
			if (Number(this._gridPanelElement.style.left.replace('px', '')) > 0) {
				clearInterval(this.scrollLeftInterval);
				this._gridPanelElement.style.left = '0px';
			}
		}
		catch (err) { throw this._error(err, "scrollGridLeft()") }
	},

	scrollContentsWidth: function() {
		try {
			if (this.scrollContentWidth == 0) {
				for (var i = 0; i < this._gridPanelElement.childNodes.length; i++) {
					if (this._gridPanelElement.childNodes[i].className == "galleryThumbnailContainer")
						this.imageCount++;
				}
				if (this.maxRowCount != 0)
					this.imageCount = Math.ceil(this.imageCount / this.maxRowCount);

				this.scrollContentWidth = this.imageCount * this.imageWidth;
				if (this.scrollContentWidth < this.scrollContainerWidth)
					this.scrollContentWidth = this.scrollContainerWidth;
			}
			return this.scrollContentWidth;
		}
		catch (err) { throw this._error(err, "scrollContentsWidth()") }
	},

	scrollUp: function() {
		try {
			var currentLocation = Number(this._gridPanelElement.style.top.replace('px', ''));
			if (currentLocation != 0)
				this._gridPanelElement.style.top = (currentLocation + (3 * 76)) + 'px';
			if (Number(this._gridPanelElement.style.top.replace('px', '')) > 0)
				this._gridPanelElement.style.top = '0px';
		}
		catch (err) { throw this._error(err, "scrollUp()") }
	},

	scrollDown: function() {
		try {
			var numberOfFullRows = Math.floor(this.imageCount / 6);
			var remainingImages = Math.floor(this.imageCount % 6);
			var partialSection = 0;
			if (remainingImages > 0)
				numberOfFullRows++;

			var maxheight = -numberOfFullRows * 76;
			var currentTopLocation = Number(this._gridPanelElement.style.top.replace('px', ''));

			partialSection = Math.abs(currentTopLocation - 228) + maxheight;

			if (Math.abs(partialSection) < 228)
				this._gridPanelElement.style.top = (currentTopLocation + partialSection) + 'px'
			else if (maxheight < (currentTopLocation - 228) && currentTopLocation >= -((numberOfFullRows - 3) * 76)) {
				this._gridPanelElement.style.top = (currentTopLocation - (3 * 76)) + 'px';
			}
		}
		catch (err) { throw this._error(err, "scrollDown()") }
	},

	stopScroll: function() {
		try {
			clearInterval(this.scrollRightInterval);
			clearInterval(this.scrollLeftInterval);
		}
		catch (err) { throw this._error(err, "stopScroll()") }
	},

	hideNavigationForVerticalNavigation: function(navigationContainerID, menuContainerID) {
		try {
			if (this.overrideAndLoadSinglePanel) {
				$get(this.gridContainerID).style.display = "none";
				$get(navigationContainerID).style.display = "none";
				$get(menuContainerID).style.position = "relative";
				$get(menuContainerID).style.top = "0px";
			}
		}
		catch (err) { throw this._error(err, "hideNavigationForVerticalNavigation()") }
	},

	showNavigationForVerticalNavigation: function(navigationContainerID, menuContainerID) {
		try {
			if (this.overrideAndLoadSinglePanel) {
				$get(this.gridContainerID).style.display = "block";
				$get(navigationContainerID).style.display = "block";
				$get(menuContainerID).style.position = "absolute";
				$get(menuContainerID).style.top = "280px";
			}
		}
		catch (err) { throw this._error(err, "showNavigationForVerticalNavigation()") }
	}
}

//======================================================================================================================================================================
//======================================================================================================================================================================

Type.registerNamespace('Vehix.Presentation.MediaSlideShow');

Vehix.Presentation.MediaSlideShow = function(parentObj, containerID) {
    Vehix.Presentation.MediaSlideShow.initializeBase(this);

    //Private Properties
    var _mainContainer = null;
    var _enablePhotoCount = false;
    var _enableNavigation = false;
    var _enableTitleBar = false;
    var _imageArray = null;
    var _currentSlidePosition = 0;
    var _timer = null;
    var _mainSlideShowImage = null;
    var _playBtnImage = null;

    //public Properties
    this.slideShowContainerID = containerID;

    //Initialize
    this.ID = "mediaSlideShow";
    this.setParent(parentObj);
    this.create();
    this._photoCounterDiv = "";
}

Vehix.Presentation.MediaSlideShow.prototype =
{
	_error: function(err, funcName)
	{
		err.message = err.message + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow." + funcName + "\n";
		return err;
	},

	setParent: function(obj)
	{
		try
		{
			this.parent = obj;
		}
		catch (err) { throw this._error(err, "setParent()") }
	},

	create: function()
	{
		try
		{
			this._currentSlidePosition = 0; //default
			this._mainSlideShowImage = newImage();
			this._playBtnImage = newImage();
			this._buildContainer();
		}
		catch (err) { throw this._error(err, "create()") }
	},

	load: function()
	{
		try
		{
			this.showImage(null, true);
		}
		catch (err) { throw this._error(err, "load()") }
	},

	clear: function()
	{
		var childNodeCount = 0;
		var elem = null;

		try
		{
			childNodeCount = this._mainContainer.childNodes.length;
			if (childNodeCount > 0)
			{
				for (var i = 0; i < childNodeCount; i++)
				{
					if (typeof (this._mainContainer.childNodes[i]) != "undefined")
					{
						this._mainContainer.removeChild(this._mainContainer.childNodes[i]);
						this.clear();
					}
				}
			}
			else
			{
				$get(this.slideShowContainerID).removeChild(this._mainContainer);
			}
		}
		catch (err) { throw this._error(err, "clear()") }
	},

	_buildContainer: function()
	{
		var grandParentContainerID = "";
		var grandParentContainerHeight = 0;
		var slideShowContainerDiv = null;

		try
		{
			this._mainContainer = newDiv();
			this._mainContainer.setAttribute("id", "gallerySlideShowPopUp");
			this._mainContainer.className = "panel gallerySlideShowPopUp";
			this._mainContainer.innerHTML = "";
			grandParentContainerID = $get($get(this.parent.parent.mediaBrowserContainerID).parentNode.getAttribute("ID")).parentNode.getAttribute("ID");
			slideShowContainerDiv = $get(this.slideShowContainerID);
			slideShowContainerDiv.style.display = "block";
			grandParentContainerHeight = Number($get(grandParentContainerID).offsetHeight);
			slideShowContainerDiv.style.height = (grandParentContainerHeight + 1).toString() + "px";
			slideShowContainerDiv.appendChild(this._mainContainer);
		}
		catch (err) { throw this._error(err, "_buildContainer()") }
	},

	showMagnifiedImage: function(image)
	{
		try
		{
			this._mainContainer.appendChild(this._headerRow());
			this._mainContainer.appendChild(this._mainImagePanel(image));
			this._mainContainer.setAttribute("style", "height:522px;");
			$get(this.slideShowContainerID).style.display = "block";
		}
		catch (err) { throw this._error(err, "showMagnifiedImage(image)") }
	},

	buildSlideShow: function(imageArray)
	{
		try
		{
			this._imageArray = imageArray;
			this._mainContainer.appendChild(this._headerRow());
			this._lrgImageArray = new Array();
			for (var i = 0; i < this._imageArray.length; i++)
			{
				var img = new Image();
				img.setAttribute("id", this._imageArray[i].id);
				img.src = this._imageArray[i].src;
				img.lowsrc = this._imageArray[i].lowsrc;
				this._lrgImageArray.push(img);
			}
			this._mainContainer.appendChild(this._mainImagePanel(this._lrgImageArray[0]));
			this._mainContainer.appendChild(this._navigationPanel());
			_photoCounterDiv.innerHTML = "Photo 1 of " + this._imageArray.length.toString();
		}
		catch (err) { throw this._error(err, "buildSlideShow(imageArray)") }
	},

	autoSlideShowBegin: function()
	{
		var thisWindowLevelMethodCall = "";

		try
		{
			thisWindowLevelMethodCall = this.parent.parent.ID + "." + this.parent.ID + "." + this.ID + "." + "autoSlideShowBegin()";
			if (typeof (this._lrgImageArray) != 'undefined' && this._lrgImageArray != null)
			{
				if (this._lrgImageArray[this._currentSlidePosition] != null)
				{
					if (this._lrgImageArray[this._currentSlidePosition].width > 641)
						this._mainSlideShowImage.width = 640;
					this._mainSlideShowImage.src = this._lrgImageArray[this._currentSlidePosition].src;
					clearTimeout(this._timer);
					_photoCounterDiv.innerHTML = "Photo " + (this._currentSlidePosition + 1).toString() + " of " + this._lrgImageArray.length.toString();
					this._currentSlidePosition++;
					this._timer = setTimeout(thisWindowLevelMethodCall, 3000);
				}
				else
				{
					clearTimeout(this._timer);
					this._currentSlidePosition = 0;
					_photoCounterDiv.innerHTML = "Photo 1 of " + this._lrgImageArray.length.toString();
					this._timer = setTimeout(thisWindowLevelMethodCall, 3000);
				}
			}
		}
		catch (err) { throw this._error(err, "autoSlideShowBegin()") }
	},

	_headerRow: function()
	{
		var headerDiv = newDiv();
		var closePanel = newDiv();
		var photoCounterContainerDiv = newDiv();
		var dealerLogoImage = newImage();
		var closeImage = newImage();
		var closeAnchor = newAnchor();

		try
		{
			headerDiv.setAttribute("id", "panel gallerySlideShowHeaderContainer");
			headerDiv.className = "panel gallerySlideShowHeaderContainer";

			//Build Photo Counter
			_photoCounterDiv = newDiv();
			photoCounterContainerDiv.className = "gallerySlideShowPhotoCounter";
			photoCounterContainerDiv.appendChild(_photoCounterDiv);
			headerDiv.appendChild(photoCounterContainerDiv);

			//Build Close Panel
			closePanel.setAttribute("id", "gallerySlideShowClosePanel");
			closePanel.className = "gallerySlideShowClosePanel";

			//Build Close Anchor
			closeAnchor.innerHTML = "Close";
			closeAnchor.slideShowObj = this;
			closeAnchor.onclick = function() { this.slideShowObj._closeSlideShow(); };
			closePanel.appendChild(closeAnchor);

			//Build Close Image
			closeImage.setAttribute("id", "gallerySlideShowImageClose");
			closeImage.className = "gallerySlideShowImageClose";
			closeImage.slideShowObj = this;
			closeImage.onclick = function() { this.slideShowObj._closeSlideShow(); };
			closeImage.onmouseover = function() { this.style.backgroundPosition = 'right'; };
			closeImage.onmouseout = function() { this.style.backgroundPosition = 'left'; };
			closeImage.setAttribute("style", "border: 0px none ; background-position: left center;");
			closeImage.src = gvx_ApplicationPath + "/!.gif";
			closePanel.appendChild(closeImage);

			headerDiv.appendChild(closePanel);
			return headerDiv;
		}
		catch (err) { throw this._error(err, "_headerRow()") }
	},

	_mainImagePanel: function(image)
	{
		var imageDiv = newDiv();

		try
		{
			this._mainSlideShowImage.src = image.src;
			this._mainSlideShowImage.setAttribute("style", "border-width: 0px; width: 640px;padding:0px;margin:0px");
			this._mainSlideShowImage.className = "gallerySlideShowMainImage"
			imageDiv.setAttribute("id", "gallerySlideShowMainImagePanel");
			imageDiv.className = "gallerySlideShowMainImagePanel";
			imageDiv.appendChild(this._mainSlideShowImage);
			return imageDiv;
		}
		catch (err) { throw this._error(err, "_mainImagePanel()") }
	},

	_navigationPanel: function()
	{
		var containerDiv = newDiv();
		var mainNavigationDiv = newDiv();
		var previousBtnImage = newImage();
		//var playBtnImage = newImage();  Made global -->  _playBtnImage
		var nextBtnImage = newImage();

		try
		{
			//Build Previous Button
			previousBtnImage.slidShowObj = this;
			previousBtnImage.setAttribute("style", "border: 0px none;");
			previousBtnImage.className = "galleryBtnPrevious"
			previousBtnImage.src = gvx_ApplicationPath + "/!.gif";
			previousBtnImage.onclick = function()
			{
				try
				{
					this.slidShowObj._movePreviousImage();
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onclick";
				}
			}
			previousBtnImage.onmouseout = function()
			{
				try
				{
					this.style.backgroundPosition = 'left';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}
			previousBtnImage.onmouseover = function()
			{
				try
				{
					this.style.backgroundPosition = 'right';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}

			//BuildPlay/Pause Button
			this._playBtnImage.slidShowObj = this;
			this._playBtnImage.setAttribute("style", "border: 0px none;");
			this._playBtnImage.className = "galleryBtnPause"
			this._playBtnImage.src = gvx_ApplicationPath + "/!.gif";
			this._playBtnImage.onclick = function()
			{
				try
				{
					this.slidShowObj._playPauseButton_Click();
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onclick";
				}
			}
			this._playBtnImage.onmouseout = function()
			{
				try
				{
					this.style.backgroundPosition = 'left';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}
			this._playBtnImage.onmouseover = function()
			{
				try
				{
					this.style.backgroundPosition = 'right';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}

			//Build Next Button							
			nextBtnImage.setAttribute("style", "border: 0px none;");
			nextBtnImage.className = "galleryBtnNext"
			nextBtnImage.src = gvx_ApplicationPath + "/!.gif";
			nextBtnImage.slidShowObj = this;
			nextBtnImage.onclick = function()
			{
				try
				{
					this.slidShowObj._moveNextImage();
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onclick";
				}
			}
			nextBtnImage.onmouseout = function()
			{
				try
				{
					this.style.backgroundPosition = 'left';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}
			nextBtnImage.onmouseover = function()
			{
				try
				{
					this.style.backgroundPosition = 'right';
				}
				catch (err)
				{
					throw err + "\n :: Stack Trace: Vehix.Presentation.MediaSlideShow._navigationPanel() --> previousBtnImage.onmouseout";
				}
			}


			mainNavigationDiv.setAttribute("id", "galleryNavigationContainer");
			mainNavigationDiv.className = "galleryNavigation";
			mainNavigationDiv.appendChild(previousBtnImage);
			mainNavigationDiv.appendChild(this._playBtnImage);
			mainNavigationDiv.appendChild(nextBtnImage);

			containerDiv.className = "galleryNavigationContainer";
			containerDiv.appendChild(mainNavigationDiv);
			containerDiv.appendChild(this._descriptorPanel());
			return containerDiv;
		}
		catch (err) { throw this._error(err, "_navigationPanel()") }
	},

	_descriptorPanel: function()
	{
		var descriptorDiv = newDiv();
		var textDiv = newDiv();

		try
		{
			textDiv.setAttribute("id", "gallerySlideShowGalleryDescriptorText");
			textDiv.className = "gallerySlideShowGalleryDescriptorText";
			textDiv.innerHTML = "Actual Vehicle Photos";
			descriptorDiv.setAttribute("id", "gallerySlideShowGalleryDescriptor");
			descriptorDiv.className = "gallerySlideShowGalleryDescriptor";
			descriptorDiv.appendChild(textDiv);
			return descriptorDiv;
		}
		catch (err) { throw this._error(err, "_descriptorPanel()") }
	},

	_moveNextImage: function()
	{
		try
		{
			clearTimeout(this._timer);
			this._currentSlidePosition++;
			if (this._lrgImageArray[this._currentSlidePosition] == null)
				this._currentSlidePosition = 0;
			if (this._lrgImageArray[this._currentSlidePosition].src == this._mainSlideShowImage.src)
				this._currentSlidePosition++;
			if (this._lrgImageArray[this._currentSlidePosition] == null)
				this._currentSlidePosition = 0;

			this._mainSlideShowImage.src = this._lrgImageArray[this._currentSlidePosition].src;
			_photoCounterDiv.innerHTML = "Photo " + (this._currentSlidePosition + 1).toString() + " of " + this._lrgImageArray.length.toString();
			this._playBtnImage.className = "galleryBtnPlay";
		}
		catch (err) { throw this._error(err, "_moveNextImage()") }
	},

	_movePreviousImage: function()
	{
		try
		{
			clearTimeout(this._timer);
			if (this._lrgImageArray[this._currentSlidePosition].src == this._mainSlideShowImage.src)
				this._currentSlidePosition--;
			if (this._currentSlidePosition < 0)
				this._currentSlidePosition = this._lrgImageArray.length - 1;
			this._mainSlideShowImage.src = this._lrgImageArray[this._currentSlidePosition].src;
			_photoCounterDiv.innerHTML = "Photo " + (this._currentSlidePosition + 1).toString() + " of " + this._lrgImageArray.length.toString();
			this._playBtnImage.className = "galleryBtnPlay";
		}
		catch (err) { throw this._error(err, "_movePreviousImage()") }
	},

	_playPauseButton_Click: function()
	{
		try
		{
			if (this._playBtnImage.className == "galleryBtnPlay")
			{
				this._resumeSlideShow();
				this._playBtnImage.className = "galleryBtnPause";
			}
			else
			{
				this._pauseSlideShow();
				this._playBtnImage.className = "galleryBtnPlay";
			}
		}
		catch (err) { throw this._error(err, "_playPauseButton_Click()") }
	},

	_pauseSlideShow: function()
	{
		try
		{
			clearTimeout(this._timer);
		}
		catch (err) { throw this._error(err, "_pauseSlideShow()") }
	},

	_resumeSlideShow: function()
	{

		try
		{
			this.autoSlideShowBegin();
		}
		catch (err) { throw this._error(err, "_resumeSlideShow()") }
	},

	_closeSlideShow: function()
	{
		try
		{
			$get(this.slideShowContainerID).style.display = "none";
			this.clear();
		}
		catch (err) { throw this._error(err, "_closeSlideShow()") }
	}
}

