var isWebKit = navigator.userAgent.toLowerCase().indexOf('webkit') > 0;
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > 0;
var isMSIE = navigator.userAgent.toLowerCase().indexOf('msie') > 0;

var gtThumbsAreActive = (document.getElementById('gtThumbsActive'));
var glSizesAreActive = (document.getElementById('glSizesActive'));
var isInCurrentAuctions = false;
var isInAuctionResults = false;
var isInAuctionArchives = false;
var totalImagesForLot = 0;
var cursorOverLeftHalfOfHighlightImage = false;
var cursorOverMiddleOfHighlightImage = false;
var dashedImageNumbering = false;
var runSlideshow = false;
var viewingLargerImages = false;
var slideshowTimeout;

var formsOnPage = document.forms;
if (formsOnPage && window.location.toString().match(/\/admin/))
{
	for (var i = 0; i < formsOnPage.length; i++)
	{
		if (formsOnPage[i].action == 'https://bid.mclemoreauction.com/cgi-bin/mnadmin.cgi')
		{
			formsOnPage[i].removeAttribute('target');
			formsOnPage[i].parentNode.parentNode.nextSibling.nextSibling.style.display = 'none'; // Hide non-secure admin login
			break;
		}
	}
}

var navLinksObject = document.getElementById('NavLinks');
if (navLinksObject)
{
	var thisLink = navLinksObject.firstChild;
	do
	{
		if (thisLink.nodeName == 'A')
		{
			var hrefString = thisLink.href.toString();
			
			if (hrefString == 'http://bid.mclemoreauction.com/cgi-bin/mncal.cgi?mclemore' || hrefString == '/cgi-bin/mncal.cgi?mclemore')
			{
				thisLink.href = 'http://www.mclemoreauction.com/';
				isInCurrentAuctions = true;
			}
			
			if (hrefString == 'http://bid.mclemoreauction.com/cgi-bin/mncal2.cgi?mclemore' || hrefString == '/cgi-bin/mncal2.cgi?mclemore')
				isInAuctionResults = true;
			
			if (hrefString.match(/\/mnregister/))
			{
				var registerHrefSplit = hrefString.split('?');
				if (registerHrefSplit.length == 2 && registerHrefSplit[1] != 'mclemore')
				{
					var workspace = registerHrefSplit[1];
					
					var registerToBidHeaderLinkObject = document.getElementById('RegisterToBidHeaderLink');
					
					if (registerToBidHeaderLinkObject && registerToBidHeaderLinkObject.nodeName == 'A')
						registerToBidHeaderLinkObject.href = 'https://bid.mclemoreauction.com/cgi-bin/mnregister.cgi?' + workspace;
					
					var editProfileHeaderLinkObject = document.getElementById('EditProfileHeaderLink');
					
					if (editProfileHeaderLinkObject && editProfileHeaderLinkObject.nodeName == 'A')
						editProfileHeaderLinkObject.href = 'https://bid.mclemoreauction.com/cgi-bin/mnregup.cgi?' + workspace;
				}
			}
		}
	}
	while (thisLink = thisLink.nextSibling);
}

var arcsearchObject = document.getElementById('arcsearch');
if (arcsearchObject)
{
	isInAuctionArchives = true;
}

var auctionTitleObject = document.getElementById('auction_title');
if (auctionTitleObject)
{
	if (window.location == 'http://bid.mclemoreauction.com/cgi-bin/mnarcview.cgi' || window.location == 'http://bid.mclemoreauction.com/cgi-bin/mnarcview.cgi/all')
	{
		document.title = 'Auction Archives | McLemore Auction Company, LLC';
	}
	else if (window.location == 'http://bid.mclemoreauction.com/cgi-bin/mncal2.cgi?mclemore')
	{
		document.title = 'Auction Results | ' + document.title;
	}
	else
	{
		document.title = auctionTitleObject.innerHTML.replace(/(&amp;)/g, '&').replace(/(&nbsp;)/g,' ').replace(/<.*?>/g, ' ') +
			' | ' + document.title;
	}
}

var picasa_gallery = document.getElementById('picasa_gallery');
var picasa_url = document.getElementById('picasa_url');
if (picasa_gallery && picasa_url && !isFlashInstalled())
{
	picasa_gallery.style.display = 'none';
	picasa_url.style.display = 'block';
}

var loadDynamicRE = document.getElementById('loadRE');
var reURLObject = document.getElementById('reURL');
if (loadDynamicRE && reURLObject)
{
  // glSizesAreActive = true;
	
	var getTables = document.getElementsByTagName('<table>');
	var detailsTable = getTables[0];
	
	var reLink = reURLObject.innerHTML;
	
	var SearchArea = document.getElementById('SearchArea');
	if (SearchArea)
    	SearchArea.style.display = "none";

		var req = createXHR(); 

		document.ajax.dyn.value="Started...";
		
		req.onreadystatechange = function()
		{ 
			document.ajax.dyn.value="Wait server...";
			if(req.readyState == 4)
			{
				if(req.status == 200)
				{
					/*
					var start_photo_area_content_location = req.responseText.split('<div id="PhotoArea" align="center">');
					var start_photo_area_content = start_photo_area_content_location[1];
					var end_photo_area_content_location = start_photo_area_content.split('<table id="TableTop" width="100%" border="0">');
                    var photo_area_content = end_photo_area_content_location[0];
                    loadDynamicRE.innerHTML = '<div id="PhotoArea" align="center">'+ photo_area_content;  
					*/
					
                    var start_lot_content_locator = req.responseText.split('<br /><br /><div id="lotInformation">');
                    var start_lot_content = start_lot_content_locator[1];
                    var end_lot_content_locator = start_lot_content.split('</table><a name="pgbottom">');
                    var lot_content = end_lot_content_locator[0];
                    loadDynamicRE.innerHTML += '<table id="DataTable" border="0" width="100%" align="center" cellpadding="3" cellspacing="1"><tbody><tr><td><div id="lotInformation">'+ lot_content +'</table>';

				}	
				else	
				{
                    document.ajax.dyn.value="Loaded";                  
                    document.ajax.dyn.value="Error: returned status code " + req.status + " " + req.statusText;
				}	
			} 
		}; 
		req.open("GET", reLink, true); 
        req.setRequestHeader("User-Agent",navigator.userAgent); 
		req.send(null); 
} 

function createXHR() 
{
	var request = false;
	
	try {
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (err2) {
		try {
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (err3) {
			try {
				request = new XMLHttpRequest();
			}
			catch (err1) 
			{
				request = false;
			}
		}
	}
	
	return request;
}

var photoArea = document.getElementById('PhotoArea');
if (photoArea)
{
	var thisObject = photoArea.firstChild;
	var firstImage = '';
	var allSmallerImages = '';
	var allLargerImages = '';
	var highlightThumbnails = '';
	var lightboxThumbnails = '';
	var imageCount = 0;
	
	do
	{
		if (thisObject.nodeName == 'IMG')
		{
			var imageSource = thisObject.src;
			var thumbSource = imageSource;
			
			if (gtThumbsAreActive)
			{
				var imageSourceGTSplit = imageSource.split('/');
				imageSourceGTSplit[imageSourceGTSplit.length - 1] = 'gt' + imageSourceGTSplit[imageSourceGTSplit.length - 1];
				thumbSource = imageSourceGTSplit.join('/');
			}
			if (glSizesAreActive)
			{
				var imageSourceGLSplit = imageSource.split('/');
				imageSourceGLSplit[imageSourceGLSplit.length - 1] = 'gl' + imageSourceGLSplit[imageSourceGLSplit.length - 1];
				largerSource = imageSourceGLSplit.join('/');
				
				allLargerImages += '<img src="' + largerSource + '"  onerror="this.src=\'/images/image_not_found_logo.gif\';" /><br/>\n';
			}
			
			allSmallerImages += '<img src="' + imageSource + '"  onerror="this.src=\'/images/image_not_found_logo.gif\';" /><br/>\n';
			
			highlightThumbnails += '<a href="javascript:displayHighlightImage(\'' + imageSource + '\');"><img src="' + thumbSource + '" ' + ((imageCount == 0) ? 'style="border-color: #6CB3C8"' : '') + ' onerror="this.src=\'http://bid.mclemoreauction.com/images/image_not_found_logo.gif\';" alt="Thumbnail ' + thisObject.alt + '" /></a> ';
			
			if (imageCount == 0)
			{
				firstImage = imageSource;
			}
			
			imageCount ++;
		}
	}
	while (thisObject = thisObject.nextSibling);
	
	totalImagesForLot = imageCount;
	
	var firstImageFilename = firstImage.replace(/^.*\//, '');
	dashedImageNumbering = (firstImageFilename.match(/\-/));
	
	var highlightGallery = '<div id="highlightImageArea">';
	
	highlightGallery += '<div id="loadingGalleryTop">Loading Gallery...</div><div id="highlightImageToolbarTop" style="display: none;"><a href="javascript:displayPreviousImage();" class="highlightGalleryNavigation" id="highlightGalleryNavigationTopLeft" style="float: left;">&lt;</a><div class="highlightImageToolbarInfoOptions" id="highlightImageToolbarInfoOptionsTop">' + ((dashedImageNumbering) ? '<a href="javascript:toggleGallery();">All Images</a> &middot; ' : '') + '<a href="javascript:toggleHighlightGalleryThumbnails();" id="toggleThumbnailsTop">Toggle Thumbnails</a> &middot; ' + ((glSizesAreActive) ? '<a href="javascript:toggleGalleryImageSize();" id="toggleImageSizeTop">Larger Images</a> &middot; ' : '') + '<a href="javascript:toggleGallerySlideshow();" id="toggleGallerySlideshowTop">Start Slideshow</a><br/><span id="highlightImageSummaryTop">1 of ' + totalImagesForLot + '</span></div><a href="javascript:displayNextImage();" class="highlightGalleryNavigation" id="highlightGalleryNavigationTopRight" style="float: right;">&gt;</a></div>';
	
	highlightGallery += '<img src="' + firstImage + '" id="highlightImage" onclick="highlightImageAction();" onmousemove="getCursorPosition(this, event);" onmouseout="clearCursor();" onerror="skipImage(this);" alt="Highlight Image" />';
	
	highlightGallery += '<div id="loadingGalleryBottom">Loading Gallery...</div><div id="highlightImageToolbarBottom" style="display: none;"><a href="javascript:displayPreviousImage();" class="highlightGalleryNavigation" id="highlightGalleryNavigationBottomLeft" style="float: left;">&lt;</a><div class="highlightImageToolbarInfoOptions" id="highlightImageToolbarInfoOptionsBottom"><span id="highlightImageSummaryBottom">1 of ' + totalImagesForLot + '</span><br/>' + ((dashedImageNumbering) ? '<a href="javascript:toggleGallery();">All Images</a> &middot; ' : '') + '<a href="javascript:toggleHighlightGalleryThumbnails();" id="toggleThumbnailsBottom">Toggle Thumbnails</a> &middot; ' + ((glSizesAreActive) ? '<a href="javascript:toggleGalleryImageSize();" id="toggleImageSizeBottom">Larger Images</a> &middot; ' : '') + '<a href="javascript:toggleGallerySlideshow();" id="toggleGallerySlideshowBottom">Start Slideshow</a></div><a href="javascript:displayNextImage();" class="highlightGalleryNavigation" id="highlightGalleryNavigationBottomRight" style="float: right;">&gt;</a></div>';
	
	highlightGallery += '</div>';
	
	if (!dashedImageNumbering)
		highlightGallery += '<br/><div><a href="javascript:toggleGallery();">All Images</a> &middot; <b>Highlight Gallery</b></div>';
	
	highlightGallery += '<div id="highlightThumbnails" style="display: none;">' + highlightThumbnails + '</div>';
	
	var allSmallerImagesGallery =
		'<div><b>All Images</b> &middot; <a href="javascript:toggleGallery();">Highlight Gallery</a></div>' +
		'<br/><div>' + allSmallerImages + '</div><br/>' +
		'<div><a href="javascript:scrollTo(0,0);">Top of All Images</a> &middot; <a href="javascript:toggleGallery();">Highlight Gallery</a></div>';
	
	var allLargerImagesGallery =
		'<div><b>All Images</b> &middot; <a href="javascript:toggleGallery();">Highlight Gallery</a></div>' +
		'<br/><div>' + allLargerImages + '</div><br/>' +
		'<div><a href="javascript:scrollTo(0,0);">Top of All Images</a> &middot; <a href="javascript:toggleGallery();">Highlight Gallery</a></div>';
	if (loadDynamicRE)
	{
	photoArea.innerHTML =
		'<div id="allSmallerImages" align="center" style="display: none;">' + allSmallerImagesGallery + '</div>' +
		'<div id="allLargerImages" align="center" style="display: none;">' + allLargerImagesGallery + '</div>' +
		'<div id="highlightGallery">' + highlightGallery + '</div>' +
		'<br/><br/>';	
	}
	else
	{
  photoArea.innerHTML =
		'<div id="allSmallerImages" align="center" style="display: none;">' + allSmallerImagesGallery + '</div>' +
		'<div id="allLargerImages" align="center" style="display: none;">' + allLargerImagesGallery + '</div>' +
		'<div id="highlightGallery">' + highlightGallery + '</div>' +
		'<br/><hr/><br/>';		  
	}
	var highlightThumbnailsObject = document.getElementById('highlightThumbnails');
	
	// Loader code...
	if (!isMSIE)
	{
		var lastThumbnailLinkObject = highlightThumbnailsObject.lastChild.previousSibling;
		var lastThumbnailObject = lastThumbnailLinkObject.firstChild;
		if (lastThumbnailObject.nodeName != 'IMG') lastThumbnailObject = lastThumbnailObject.nextSibling;
		
		lastThumbnailObject.onerror = function() { this.src = '/images/image_not_found_logo.gif'; doneLoadingGallery(); };
		lastThumbnailObject.onload = function() { doneLoadingGallery(); };
	}
	else // Fake it for IE
	{
		setTimeout('doneLoadingGallery()', 3000);
	}
		
}

function doneLoadingGallery()
{
	var highlightImageAreaObject = document.getElementById('highlightImageArea');
	var highlightThumbnailsObject = document.getElementById('highlightThumbnails');
	var loadingGalleryTopObject = document.getElementById('loadingGalleryTop');
	var loadingGalleryBottomObject = document.getElementById('loadingGalleryBottom');
	var toggleThumbnailsTopObject = document.getElementById('toggleThumbnailsTop');
	var toggleThumbnailsBottomObject = document.getElementById('toggleThumbnailsBottom');
	
	highlightThumbnailsObject.style.display = '';
	loadingGalleryTopObject.style.display = 'none';
	loadingGalleryBottomObject.style.display = 'none';
	
	if (dashedImageNumbering)
	{
		var highlightImageToolbarTopObject = document.getElementById('highlightImageToolbarTop');
		var highlightImageToolbarBottomObject = document.getElementById('highlightImageToolbarBottom');
		
		highlightImageAreaObject.style.padding = '0px';
		highlightImageToolbarTopObject.style.display = highlightImageToolbarBottomObject.style.display = '';
		
		if (getCookie('highlightGalleryThumbnails') == 'hidden')
			toggleHighlightGalleryThumbnails();
		
		toggleThumbnailsTopObject.innerHTML = toggleThumbnailsBottomObject.innerHTML = (highlightThumbnailsObject.style.display == '') ?
			'Hide Thumbnails' : 'Show Thumbnails';
	}
	else
	{
		highlightImageAreaObject.style.padding = '40px 0px 40px 0px';
	}
	
	if (glSizesAreActive && getCookie('highlightGalleryImageSize') == 'larger')
			toggleGalleryImageSize();
}

var dataTable = document.getElementById('DataTable');
if (dataTable)
{
    var thisTbody = dataTable.firstChild;
    if (thisTbody.nodeName != 'TBODY') thisTbody = thisTbody.nextSibling;
    var thisTR = thisTbody.firstChild;
    if (thisTR.nodeName != 'TR') thisTR = thisTR.nextSibling;
    
    do
    {
    	if (thisTR.nodeName == 'TR')
    	{
    		var thisTD = thisTR.firstChild;
    		var lotNumber = 0;
    		var tdCount = 0;
    		var tdArray = new Array();
    		
    		do
    		{
    			if (thisTD.nodeName == 'TD')
    			{
    				tdArray[tdCount] = thisTD;
    				
    				if (tdCount == 0) lotNumber = thisTD.firstChild.innerHTML;
    				
    				tdCount++;
    			}
    		}
    		while (thisTD = thisTD.nextSibling);
    		
    		var maxBidInput = tdArray[tdCount - 1].firstChild;
    		if (maxBidInput.nodeName != 'INPUT') maxBidInput = maxBidInput.nextSibling;
    		if (maxBidInput && maxBidInput.nodeName == 'INPUT')
    		{
    			maxBidInput.setAttribute('placeholder', 'Max Bid');
    			maxBidInput.setAttribute('class', 'bid-input');
    		}
    		
    		if (tdArray[tdCount - 2])
    		{
    			var bidInput = tdArray[tdCount - 2].firstChild;
    			
    			if (bidInput.nodeName != 'INPUT') bidInput = bidInput.nextSibling;
    			
    			if (bidInput && bidInput.nodeName == 'INPUT')
    			{
    				bidInput.setAttribute('placeholder', 'Your Bid');
    				bidInput.setAttribute('class', 'bid-input');
    			}
    		}
    	}
    }
    while (thisTR = thisTR.nextSibling);
    
}

var lotInformationObject = document.getElementById('lotInformation');
var auctionInformationWrapperObject = document.getElementById('auctionInformationWrapper');

if (lotInformationObject && !auctionInformationWrapperObject)
{
	var descriptionLotInformationObject = document.getElementById('descriptionLotInformation');
	if (descriptionLotInformationObject)
		descriptionLotInformationObject.style.display = 'none';
	
	var lotDescriptionObject = document.getElementById('lotDescription');
	if (lotDescriptionObject)
		document.title = lotDescriptionObject.innerHTML.replace('&amp;', '&').replace(/<.*?>/g, ' ') + ' | ' + document.title;
	
	var selectCatObject = document.getElementById('SelectCat');
	if (selectCatObject && lotDescriptionObject)
	{
		selectCatObject.innerHTML += '<a href="#DataTable" id="lotTitle">' + lotDescriptionObject.innerHTML + '</a>';
		lotDescriptionObject.href = '#lotTitle';	
	}
	
	// Now Legacy code... need to keep for past lots
	var youtubeVideosObject = document.getElementById('youtubeVideos');
	if (youtubeVideosObject)
	{
		youtubeVideosObject.style.display = 'none';
		photoArea.innerHTML += '<div id="youtubeVideos">' + youtubeVideosObject.innerHTML + '</div><br/><br/><hr/><br/>';
		youtubeVideosObject.innerHTML = '';
		youtubeVideosObject.removeAttribute('id');
	}
	
	// New video code...
	var youtubeVideosObject = document.getElementById('videos');
	if (youtubeVideosObject)
	{
		youtubeVideosObject.style.display = 'none';
		
		var relocatedVideoContent = '<div id="videos">' + youtubeVideosObject.innerHTML + '</div><br/><hr/><br/>';
		
		if (photoArea)
			photoArea.innerHTML += relocatedVideoContent;
		else if (selectCatObject)
			selectCatObject.innerHTML += '<div id="PhotoArea" align="center"><br/><hr/><br/>' + relocatedVideoContent + '</div>';
		
		youtubeVideosObject.innerHTML = '';
		youtubeVideosObject.removeAttribute('id');
	}
	
	var parentTD = lotInformationObject.parentNode;
	var thisTDChild = parentTD.firstChild;
	var tdCount = 0;
	do
	{
		if (thisTDChild.nodeName == 'BR')
		{
			thisTDChild.style.display = 'none';
			tdCount ++;
			
			if (tdCount == 2) break;
		}
	}
	while (thisTDChild = thisTDChild.nextSibling);
	
	
	var parentTR = parentTD.parentNode;
	var thisTD = parentTR.firstChild;
	tdCount = 0;
	do
	{
	    if (thisTD.nodeName == 'TD')
	    {
	    	if (tdCount < 2) thisTD.setAttribute('rowspan', '2');
	    	
	    	tdCount++;
	    }
	}
	while (thisTD = thisTD.nextSibling)
	
	if (tdCount > 4)
	{
		thisTD = parentTR.lastChild;
		if (thisTD.nodeName == 'TD')
		{
			thisTD.setAttribute('rowspan', '2');
			
			if (thisTD.getAttribute('colspan') != 2)
			{
				thisTD = thisTD.previousSibling.previousSibling;
				if (thisTD.nodeName == 'TD') thisTD.setAttribute('rowspan', '2');
			}
		}
		
		var parentTableBody = parentTR.parentNode;
		
		if (parentTableBody.nodeName == 'TBODY' && navigator.userAgent.toLowerCase().indexOf('msie') == -1)
		{
			var lotInformationContent = lotInformationObject.innerHTML;
			
			lotInformationObject.style.display = 'none';
			lotInformationObject.innerHTML = '';
			lotInformationObject.removeAttribute('id');
			
			parentTableBody.innerHTML += '<tr><td colspan="' + (tdCount - 4) + '"><div id="lotInformation">' + lotInformationContent + '</div></td></tr>';
		}
	}
}

function highlightImageAction()
{
	var loadingGalleryObject = document.getElementById('loadingGalleryTop');
	var highlightThumbnailsObject = document.getElementById('highlightThumbnails');
	
	//if (highlightThumbnailsObject.style.display != 'none') highlightThumbnailsObject.scrollIntoView(true);
	if (loadingGalleryObject.style.display == 'none')
	{
		if (glSizesAreActive && cursorOverMiddleOfHighlightImage)
			toggleGalleryImageSize(true);
		else if (cursorOverLeftHalfOfHighlightImage)
			displayPreviousImage();
		else
			displayNextImage();
	}
}

function getCursorPosition(thisObject, thisEvent)
{
	var currentOffset = thisEvent.offsetX || thisEvent.layerX - thisObject.offsetLeft;
	
	cursorOverLeftHalfOfHighlightImage = (currentOffset < (thisObject.width / 2));
	cursorOverMiddleOfHighlightImage =
		(currentOffset > ((thisObject.width / 2) - 50)) && (currentOffset < ((thisObject.width / 2) + 50));
	
	var loadingGalleryObject = document.getElementById('loadingGalleryTop');
	
	if (loadingGalleryObject.style.display != 'none')
	{
		document.body.style.cursor = 'default';
	}
	else if (dashedImageNumbering)
	{
		var highlightGalleryNavigationTopLeftObject = document.getElementById('highlightGalleryNavigationTopLeft');
		var highlightGalleryNavigationTopRightObject = document.getElementById('highlightGalleryNavigationTopRight');
		var highlightGalleryNavigationBottomLeftObject = document.getElementById('highlightGalleryNavigationBottomLeft');
		var highlightGalleryNavigationBottomRightObject = document.getElementById('highlightGalleryNavigationBottomRight');
		
		if (glSizesAreActive && cursorOverMiddleOfHighlightImage)
		{
			highlightGalleryNavigationTopLeftObject.style.fontWeight = highlightGalleryNavigationBottomLeftObject.style.fontWeight = 
			highlightGalleryNavigationTopRightObject.style.fontWeight = highlightGalleryNavigationBottomRightObject.style.fontWeight = '';
			
			document.body.style.cursor = (viewingLargerImages) ?
				(isWebKit ? '-webkit-zoom-out' : (isFirefox ? '-moz-zoom-out' : 's-resize')) :
				(isWebKit ? '-webkit-zoom-in' : (isFirefox ? '-moz-zoom-in' : 'n-resize'));
		}
		else if (cursorOverLeftHalfOfHighlightImage)
		{
			highlightGalleryNavigationTopLeftObject.style.fontWeight = highlightGalleryNavigationBottomLeftObject.style.fontWeight = 'bold';
			highlightGalleryNavigationTopRightObject.style.fontWeight = highlightGalleryNavigationBottomRightObject.style.fontWeight = '';
			document.body.style.cursor = 'w-resize';
		}
		else
		{
			highlightGalleryNavigationTopLeftObject.style.fontWeight = highlightGalleryNavigationBottomLeftObject.style.fontWeight = '';
			highlightGalleryNavigationTopRightObject.style.fontWeight = highlightGalleryNavigationBottomRightObject.style.fontWeight = 'bold';
			document.body.style.cursor = 'e-resize';	
		}
	}
	else
		document.body.style.cursor = 'pointer';
}

function clearCursor()
{
	var highlightGalleryNavigationTopLeftObject = document.getElementById('highlightGalleryNavigationTopLeft');
	var highlightGalleryNavigationTopRightObject = document.getElementById('highlightGalleryNavigationTopRight');
	var highlightGalleryNavigationBottomLeftObject = document.getElementById('highlightGalleryNavigationBottomLeft');
	var highlightGalleryNavigationBottomRightObject = document.getElementById('highlightGalleryNavigationBottomRight');
	
	highlightGalleryNavigationTopLeftObject.style.fontWeight = highlightGalleryNavigationBottomLeftObject.style.fontWeight =
	highlightGalleryNavigationTopRightObject.style.fontWeight = highlightGalleryNavigationBottomRightObject.style.fontWeight = '';
	
	document.body.style.cursor = 'default';
}

function displayHighlightImage(clickedImageSource, continueSlideshow)
{
	if (!continueSlideshow)
		stopGallerySlideshow();
	
	var highlightImage = document.getElementById('highlightImage');
	var oldHighlightImageSource = highlightImage.src;
	var newHighlightImageSource = '';
	
	if (viewingLargerImages)
	{
		var imageSourceSplit = clickedImageSource.split('/');
		imageSourceSplit[imageSourceSplit.length - 1] = 'gl' + imageSourceSplit[imageSourceSplit.length - 1];
		newHighlightImageSource = imageSourceSplit.join('/');
	}
	else
		newHighlightImageSource = clickedImageSource;
	
	highlightImage.src = newHighlightImageSource;
	
	if (oldHighlightImageSource != newHighlightImageSource && !isMSIE)
	{
		setOpacity(highlightImage, 50);
		fadeIn('highlightImage', 50);
	}
	
	var highlightThumbs = document.getElementById('highlightThumbnails');
	var thisThumbLink = highlightThumbs.firstChild;
	
	var clickedThumbSource = clickedImageSource;
	if (gtThumbsAreActive)
	{
	    var imageSourceSplit = clickedImageSource.split('/');
	    imageSourceSplit[imageSourceSplit.length - 1] = 'gt' + imageSourceSplit[imageSourceSplit.length - 1];
	    clickedThumbSource = imageSourceSplit.join('/');
	}
	
	do
	{
	    var thisThumb = thisThumbLink.firstChild;
	    if (thisThumb)
	    {
	    	do
	    	{
	    		if (thisThumb.nodeName == 'IMG') break;
	    	}
	    	while(thisThumb = thisThumb.nextSibling);
	    	
	    	thisThumb.style.borderColor = (thisThumb.src == clickedThumbSource) ? '#6EB6CB' : '#ffffff';
	    }
	}
	while(thisThumbLink = thisThumbLink.nextSibling);
	
	var highlightImageFilename = highlightImage.src.replace(/^.*\//, '');
	
	if (dashedImageNumbering)
	{
		var lotNumber = parseInt(highlightImageFilename.replace(/\-.*/, ''));
		var highlightImageNumber = parseInt(highlightImageFilename.replace(/^.*\-/, '').replace(/\..*/, ''));
		
		var highlightImageSummaryTopObject = document.getElementById('highlightImageSummaryTop');
		var highlightImageSummaryBottomObject = document.getElementById('highlightImageSummaryBottom');
		highlightImageSummaryTopObject.innerHTML = highlightImageSummaryBottomObject.innerHTML = highlightImageNumber + ' of ' + totalImagesForLot;
	}
	
	if (!continueSlideshow)
		document.getElementById('highlightImageArea').scrollIntoView(true);
}

function toggleHighlightGalleryThumbnails()
{
	var loadingGalleryObject = document.getElementById('loadingGalleryTop');
	var highlightThumbnailsObject = document.getElementById('highlightThumbnails');
	var toggleThumbnailsTopObject = document.getElementById('toggleThumbnailsTop');
	var toggleThumbnailsBottomObject = document.getElementById('toggleThumbnailsBottom');
	
	if (loadingGalleryObject.style.display == 'none')
	{
		highlightThumbnailsObject.style.display = (highlightThumbnailsObject.style.display == '') ? 'none' : '';
		toggleThumbnailsTopObject.innerHTML = toggleThumbnailsBottomObject.innerHTML = (highlightThumbnailsObject.style.display == '') ?
			'Hide Thumbnails' : 'Show Thumbnails';
		
		if (highlightThumbnailsObject.style.display == '')
		{
			highlightThumbnailsObject.scrollIntoView(true);
			setCookie('highlightGalleryThumbnails', 'visible');
		}
		else
			setCookie('highlightGalleryThumbnails', 'hidden');
			
	}
}

function toggleGalleryImageSize(didClickImage)
{
	var loadingGalleryObject = document.getElementById('loadingGalleryTop');
	var highlightImageToolbarInfoOptionsTopObject = document.getElementById('highlightImageToolbarInfoOptionsTop');
	var highlightImageToolbarInfoOptionsBottomObject = document.getElementById('highlightImageToolbarInfoOptionsBottom');
	var toggleImageSizeTopObject = document.getElementById('toggleImageSizeTop');
	var toggleImageSizeBottomObject = document.getElementById('toggleImageSizeBottom');
	var highlightImageAreaObject = document.getElementById('highlightImageArea');
	var highlightImageObject = document.getElementById('highlightImage');
	var imageSource = highlightImageObject.src;
	
	if (loadingGalleryObject.style.display == 'none')
	{
		if (viewingLargerImages)
		{
			highlightImageAreaObject.style.width = '720px';
			highlightImageToolbarInfoOptionsTopObject.style.width = highlightImageToolbarInfoOptionsBottomObject.style.width = '460px';
			
			var imageSourceSplit = imageSource.split('/');
			imageSourceSplit[imageSourceSplit.length - 1] = imageSourceSplit[imageSourceSplit.length - 1].replace('gl', '');
			newImageSource = imageSourceSplit.join('/');
			
			highlightImageObject.src = newImageSource;
			
			toggleImageSizeTopObject.innerHTML = 'Larger Images';
			toggleImageSizeBottomObject.innerHTML = 'Larger Images';
			viewingLargerImages = false;
			
			setCookie('highlightGalleryImageSize', 'smaller');
		}
		else
		{
			highlightImageAreaObject.style.width = '920px';
			highlightImageToolbarInfoOptionsTopObject.style.width = highlightImageToolbarInfoOptionsBottomObject.style.width = '660px';
			
			var imageSourceSplit = imageSource.split('/');
			imageSourceSplit[imageSourceSplit.length - 1] = 'gl' + imageSourceSplit[imageSourceSplit.length - 1];
			newImageSource = imageSourceSplit.join('/');
			
			highlightImageObject.src = newImageSource;
			
			toggleImageSizeTopObject.innerHTML = 'Smaller Images';
			toggleImageSizeBottomObject.innerHTML = 'Smaller Images';
			viewingLargerImages = true;
			
			setCookie('highlightGalleryImageSize', 'larger');
		}
		
		if (didClickImage)
		{
			document.body.style.cursor = (viewingLargerImages) ?
				(isWebKit ? '-webkit-zoom-out' : (isFirefox ? '-moz-zoom-out' : 's-resize')) :
				(isWebKit ? '-webkit-zoom-in' : (isFirefox ? '-moz-zoom-in' : 'n-resize'));
		}
	}
}

function setOpacity(obj, opacity)
{
	opacity = (opacity >= 100) ? ((isFirefox) ? 99.999 : 100) : opacity;
	
	// IE 8
	obj.style.MSFilter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
	
	// IE/Win
	obj.style.filter = 'alpha(opacity: ' + opacity + ')';
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity / 100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity / 100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity / 100;
}

function fadeIn(objId, opacity)
{
	var obj = document.getElementById(objId);
	if (opacity <= 100)
	{
		setOpacity(obj, opacity);
		opacity += 10;
		window.setTimeout("fadeIn('" + objId + "', " + opacity + ")", 2);
	}
}

function toggleGallerySlideshow()
{
	if (runSlideshow) stopGallerySlideshow();
	else startGallerySlideshow();
}

function startGallerySlideshow()
{
	runSlideshow = true;
	displayImage(1);
	
	var toggleGallerySlideshowTopObject = document.getElementById('toggleGallerySlideshowTop');
	var toggleGallerySlideshowBottomObject = document.getElementById('toggleGallerySlideshowBottom');
	
	toggleGallerySlideshowTopObject.innerHTML = toggleGallerySlideshowBottomObject.innerHTML = 'Stop Slideshow';
}

function stopGallerySlideshow()
{
	runSlideshow = false;
	clearTimeout(slideshowTimeout);
	
	var toggleGallerySlideshowTopObject = document.getElementById('toggleGallerySlideshowTop');
	var toggleGallerySlideshowBottomObject = document.getElementById('toggleGallerySlideshowBottom');
	
	toggleGallerySlideshowTopObject.innerHTML = toggleGallerySlideshowBottomObject.innerHTML = 'Start Slideshow';
}

function skipImage(skippedImageObject)
{
	// Could be more sophisticated
}

function displayNextImage()
{
	stopGallerySlideshow();
	displayImage(1);
}

function displayPreviousImage()
{
	stopGallerySlideshow();
	displayImage(-1);
}

function displayImage(imageOffset)
{
	var loadingGalleryObject = document.getElementById('loadingGalleryTop');
	
	if (loadingGalleryObject.style.display == 'none')
	{
		if (dashedImageNumbering)
		{
			var highlightImage = document.getElementById('highlightImage');
			var highlightImageFilename = highlightImage.src.replace(/^.*\//, '');
			
			var lotNumber = parseInt(highlightImageFilename.replace(/\-.*/, '').replace('gl', ''));
			var highlightImageNumber = parseInt(highlightImageFilename.replace(/^.*\-/, '').replace(/\..*/, ''));
		
			var newHighlightImageNumber = highlightImageNumber + imageOffset;
			if (newHighlightImageNumber == 0 || newHighlightImageNumber > totalImagesForLot)
			{
				if (runSlideshow) newHighlightImageNumber = 1;
				else newHighlightImageNumber = highlightImageNumber;
			}
			var newHighlightImageFilename = lotNumber + '-' + newHighlightImageNumber + '.JPG';
			
			displayHighlightImage(highlightImage.src.replace(highlightImageFilename, newHighlightImageFilename), true);
			
			if (runSlideshow)
				slideshowTimeout = setTimeout('displayImage(1)', 3500);
		}
		else
		{
			var highlightThumbnailsObject = document.getElementById('highlightThumbnails');
			if (highlightThumbnailsObject.style.display != 'none')
				highlightThumbnailsObject.scrollIntoView(true);
		}
	}
}

function toggleGallery()
{
	if (runSlideshow) stopGallerySlideshow();
	
	scroll(0,0);
	
	var highlightGalleryArea = document.getElementById('highlightGallery');
	var allSmallerImagesArea = document.getElementById('allSmallerImages');
	var allLargerImagesArea = document.getElementById('allLargerImages');
	
	if (highlightGalleryArea.style.display == 'none')
	{
	    highlightGalleryArea.style.display = '';
	    if (viewingLargerImages)
			allLargerImagesArea.style.display = 'none';
		else
			allSmallerImagesArea.style.display = 'none';
	}
	else
	{
		highlightGalleryArea.style.display = 'none';
	    if (viewingLargerImages)
			allLargerImagesArea.style.display = '';
		else
			allSmallerImagesArea.style.display = '';
	}
}

function activatePlaceholders() {
	if (navigator.userAgent.toLowerCase().indexOf('webkit') > 0) return false;
	var inputs = document.getElementsByTagName('input');
	for (var i=0;i<inputs.length;i++) {
		if (inputs[i].getAttribute('type') == 'text') {
			if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) {
				inputs[i].value = inputs[i].getAttribute('placeholder');
				if (inputs[i].getAttribute('placeholder')) inputs[i].setAttribute('style', 'color: #A9A9A9;');
				inputs[i].onclick = function() {
					if (this.value == this.getAttribute('placeholder')) {
						this.value = '';
						if (this.getAttribute('placeholder')) this.setAttribute('style', 'color: #000000;');
					}
					return false;
				}
				inputs[i].onblur = function() {
					if (this.value.length < 1) {
						this.value = this.getAttribute('placeholder');
						if (this.getAttribute('placeholder')) this.setAttribute('style', 'color: #A9A9A9;');
					}
				}
			}
		}
	}
}

activatePlaceholders();

function isFlashInstalled()
{
	//return (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]);
    var hasFlash = false;
    try {
        var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if(fo) hasFlash = true;
      }
  catch(e){
    if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
  }
  return hasFlash;
}

/*
// http://www.webreference.com/programming/javascript/onloads/
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function()
{
	var splitURL = window.location.href.split('#');
	if (splitURL.length > 1)
	{
		var scrollToElement = document.getElementById(splitURL[1]);
	}
})
*/
