SearchResults = {
	type : "SearchResults",
	loaded : false,
	resultsContainerId : "resultsContainer",
	resultsContainer : null,
	containerTop : 0,
	containerRight : 0,
	containerBottom : 0,
	containerLeft : 0,
	currIndex : null,
	currVehicleId : null,
	currWebId : null,
	currRow : null,
	onClickUrl : null,
	currOutClass : null,
	hoverClass : null,
	init : function(newResultsContainerId, newOnClickUrl, newHoverClass) {
		if (newResultsContainerId) SearchResults.setResultsContainer(newResultsContainerId);
		else SearchResults.setResultsContainer();
		if (newOnClickUrl) SearchResults.onClickUrl = newOnClickUrl;
		if (newHoverClass) SearchResults.hoverClass = newHoverClass;
		SearchResults.loaded = true;
	},
	setResultsContainer : function(newResultsContainerId) {
		if (!newResultsContainerId) var newResultsContainerId = "resultsContainer";
		SearchResults.resultsContainer = document.getElementById(newResultsContainerId);
		SearchResults.containerTop = SearchResults.getAbsOffsetTop(SearchResults.resultsContainer);
		SearchResults.containerBottom = (SearchResults.containerTop + SearchResults.resultsContainer.offsetHeight);
		SearchResults.containerLeft = SearchResults.getAbsOffsetLeft(SearchResults.resultsContainer);
		SearchResults.containerRight = (SearchResults.containerLeft + SearchResults.resultsContainer.offsetWidth);
	},
	getResultsContainer : function() { return SearchResults.resultsContainer; },
	setHoverClass : function(newHoverClass) { SearchResults.hoverClass = newHoverClass; },
	setOnClickUrl : function(newOnClickUrl) { SearchResults.onClickUrl = newOnClickUrl; },
	getOnClickUrl : function(newParams) { return SearchResults.onClickUrl + newParams; },
	mouseOver : function(e, newIndex, newVehicleId, newWebId) {
		if (e) e.cancelBubble = true;
		if (!SearchResults.loaded) return;
		if (SearchResults.currIndex == newIndex) return;
		if (SearchResults.currIndex != null) SearchResults.mouseOut(e);
		SearchResults.currIndex = newIndex;
		SearchResults.currVehicleId = newVehicleId;
		SearchResults.currWebId = newWebId;
		SearchResults.currRow = document.getElementById("row_" + SearchResults.currIndex);
		if (SearchResults.hoverClass) {
			SearchResults.currOutClass = SearchResults.currRow.className;
			SearchResults.currRow.className = SearchResults.hoverClass;
		}
		if (window.ThumbnailUtility) {
			ThumbnailUtility.hide();
			ThumbnailUtility.display(e, newIndex, true);
		}
	},
	mouseOut : function(e) {
		if (e) e.cancelBubble = true;
		if (!SearchResults.loaded) return;
		if (SearchResults.currIndex == null) return;
		if (SearchResults.hoverClass) SearchResults.currRow.className = SearchResults.currOutClass;
		SearchResults.currIndex = null;
	},
	clickRow : function() {
		if (SearchResults.currIndex == null) return;
		if (SearchResults.currVehicleId == null) return;
		window.location.href = SearchResults.getOnClickUrl("&id=" + SearchResults.currVehicleId + "&web_id=" + SearchResults.currWebId);
	},
	getAbsOffsetLeft : function(element) {
		if (element.offsetParent) return element.offsetLeft + SearchResults.getAbsOffsetLeft(element.offsetParent);
		else return element.offsetLeft;
	},
	getAbsOffsetTop : function(element) {
		if (element.offsetParent) return element.offsetTop + SearchResults.getAbsOffsetTop(element.offsetParent);
		else return element.offsetTop;
	},
	getStyleValue : function(element, iePropName, mozPropName){
		if (!element) return null;
		if (element.currentStyle) { //if IE5+
			return element.currentStyle[iePropName];
		} else if (window.getComputedStyle) { //if NS6+
			var elstyle = window.getComputedStyle(element, "");
			return elstyle.getPropertyValue(mozPropName);
		}
	}
}


ThumbnailUtility = {
	urlArray : new Array(),
	imgArray : null,
	thumbnailImg : null,
	useLarge : false,
	displayThumbnail : false,
	init : function(urlArray, newThumbnailImgId, useLarge) {
		ThumbnailUtility.urlArray = urlArray;
		ThumbnailUtility.imgArray = ThumbnailUtility.getImages();
		ThumbnailUtility.useLarge = (useLarge) ? useLarge : false;
		if (newThumbnailImgId) ThumbnailUtility.setThumbnailImg(newThumbnailImgId);
	},
	setThumbnailImg : function(thumbnailImgId) {
		if (!thumbnailImgId) var thumbnailImgId = "thumbnailImg";
		ThumbnailUtility.thumbnailImg = document.getElementById(thumbnailImgId);
		ThumbnailUtility.displayThumbnail = (ThumbnailUtility.thumbnailImg) ? true : false;
	},
	getImages : function() {
		var imageArray = new Array();
		for (var i=0; i<ThumbnailUtility.urlArray.length; i++) {
			imageArray[i] = (ThumbnailUtility.urlArray[i]) ? new Image() : null;
			if (imageArray[i]) imageArray[i].src = ThumbnailUtility.urlArray[i];
		}
		return imageArray;
	},
	getWidth : function() { return (ThumbnailUtility.useLarge) ? 150 : 72; },
	display : function(e, rowIndex, isRowDisplayed) {
		if (e) e.cancelBubble = true;
		// need this to happen first so currIndex will be correct
		if (!isRowDisplayed) document.getElementById("row_" + rowIndex).onmouseover.call();
		var targetThumbnail = ThumbnailUtility.imgArray[rowIndex];
		if (!targetThumbnail) return;
		if (!ThumbnailUtility.thumbnailImg) ThumbnailUtility.setThumbnailImg();
		if (!ThumbnailUtility.displayThumbnail) return;
		ThumbnailUtility.thumbnailImg.src = targetThumbnail.src;
		ThumbnailUtility.thumbnailImg.width = ThumbnailUtility.getWidth();
		var xPos = ThumbnailUtility.getXPos();
		var yPos = ThumbnailUtility.getYPos();
		ThumbnailUtility.thumbnailImg.style.left = xPos;
		ThumbnailUtility.thumbnailImg.style.top = yPos;
		ThumbnailUtility.thumbnailImg.style.visibility = "visible";
	},
	hide : function() {
		if (!ThumbnailUtility.displayThumbnail) return;
		ThumbnailUtility.thumbnailImg.style.visibility = "hidden";
	},
	getXPos : function() {
		var xPos = parseInt(SearchResults.getStyleValue(SearchResults.resultsContainer, "width", "width"));
		xPos += SearchResults.getAbsOffsetLeft(SearchResults.currRow);
		xPos = xPos - ThumbnailUtility.getWidth();
		return xPos;
	},
	getYPos : function() {
		var yPos = SearchResults.getAbsOffsetTop(SearchResults.currRow);
		return yPos;
	}
}
