
var index = 0;
var interval = null;
var slideShow = false;
var slideShowInterval = 0;
var slideShowCheckbox = false;
var slideShowCheckbox_uncheck = false;
var images = new Array();
var thumbs = new Array();

var lastInfo1Tab, lastInfo1Content;

function scroll(direction) {
	var thumb;
	var thumbCount = 0;
	var pos = 0;
	var startPos = 0;
	var loopCount = 0;
	
	if (thumbs.length > 7) {
		thumbCount = 7;
		startPos = 1;
		loopCount = 7;
	}
	else 
		if (thumbs.length > 5) {
			thumbCount = 5;
			startPos = 2;
			loopCount = 6;
		}
		else 
			if (thumbs.length > 3) {
				thumbCount = 3;
				startPos = 3;
				loopCount = 5;
			}
	
	if (thumbCount == 0) return;
	
	if (direction == 'left')
		index = (index == 0) ?	thumbs.length - 1 :	index - 1;
	else	
		index =	(index >= (thumbs.length - 1)) ?	0 : index + 1;
	
	pos = (Math.floor(thumbCount / 2) + 1) * -1;
		
	for (var i = startPos; i <= loopCount; i++) {	
		thumb = document.getElementById("Thumb" + i);
		pos += 1;
		//alert(pos);
		if (pos < 0)
			if (index + pos >= 0) 
				thumb.src = thumbs[index + pos].url;
			else 
				thumb.src = thumbs[thumbs.length + (index + pos)].url;
		else 
			if (pos == 0) 
				thumb.src = thumbs[index].url;
			else 
				if (index + pos >= thumbs.length) 
					thumb.src = thumbs[(index + pos) - thumbs.length].url;
				else 
					thumb.src = thumbs[index + pos].url;
	}
	
	document.getElementById("Image").src = images[index].url;
	var imageCount = document.getElementById("ImageCount");
	if (imageCount != null) imageCount.innerHTML = (index + 1) + " of " + images.length; 
}

function thumbClick(pos) {
	stopSlideShow();	
	if (pos > 0) {
		if ((index + pos) > thumbs.length)
			index = (index + pos) - thumbs.length;
		else
			index = index + pos;
		scroll('left');
	}
	else { 
		if ((index + pos) >= 0) 
			index = index + pos;
		else 
			index = thumbs.length + (index + pos);		
		scroll('right');	
	}
}

function leftScrollClick() {
	 stopSlideShow();
	 scroll('left');
}

function rightScrollClick() {
	 stopSlideShow();
	 scroll('right');
}

function startSlideShow(){
	if (!slideShow) return; 
	if (slideShowCheckbox_uncheck) return;
	
	if (slideShowCheckbox) {
		var chkBox = document.getElementById("SlideShowCheckbox");
		if (chkBox != null) chkBox.checked = true;
  }
	clearInterval(interval);
	interval = window.setInterval("scroll('right')", slideShowInterval);
}

function stopSlideShow() {
	if (slideShowCheckbox) {
		var chkBox = document.getElementById("SlideShowCheckbox");
		if (chkBox != null) chkBox.checked = false;
  }
	clearInterval(interval);
}

function slideShowCheckboxClick() {
	var chkBox = document.getElementById("SlideShowCheckbox");
	if (chkBox.checked) {
		slideShowCheckbox_uncheck = false;
		slideShow = true;
		startSlideShow();
	}
	else
		stopSlideShow();	
}

function swapImage(pos) {
	index = pos - 1;
	document.getElementById("Image").src = images[index].url;
}

function info1TabClick(current, start) {
	// set tabs
	if (lastInfo1Tab == null) lastInfo1Tab = document.getElementById(start + "Tab");
	lastInfo1Tab.className = "DetailTab";
	
	var tab = document.getElementById(current + "Tab");
	tab.className = "DetailTabActive";
	lastInfo1Tab = tab;

	// set content
	if (lastInfo1Content == null) lastInfo1Content = document.getElementById(start + "Content");
	lastInfo1Content.style.display = 'none';
	
	var content = document.getElementById(current + "Content");
	content.style.display = 'block';
	lastInfo1Content = content;
}

function GetVideo(videoID) {
	window.open('http://dls.diamondlot.com/inventory/VideoCaller.aspx?videoID='+videoID,'','width=420,height=420');
}

function popUpLargeImage() {
	popUp("inventoryDisplay1.aspx?s=imagegallery&veh=imagegallery&index=" + index + "&id=" + vehicleID, "img", 682, 545);
}
