
var interval = null;
var index = 0;
var slideShow = false;
var slideShowInterval = 0;
var slideShowCheckbox = false;
var slideShowCheckbox_uncheck = false;
var thumbScroll = false;
var thumbs = new Array();
var images = new Array();
var imagesLarge = new Array();
var imagesLarger = new Array();

var lastInfoTab, lastInfoContent;
var lastInfo1Tab, lastInfo1Content;
var lastImagesTab, lastImagesContent;

var isIE = document.all;
var startIndex = 0;
var overLayActive = false;

function formStart() {
  var f = document.forms[0];
  f.onsubmit = validateForm;
  startSlideShow();
}

function scroll(direction) {
	
	var image = document.getElementById("Image");
	var thumb1 = document.getElementById("Thumb1");
	var thumb2 = document.getElementById("Thumb2");
	var thumb3 = document.getElementById("Thumb3");
	
	if (thumb3 == null) return; 

	if (direction == 'left')
		index = (index == 0) ?	thumbs.length - 1 :	index - 1;
	else
		index =	(index >= (thumbs.length - 1)) ?	0 : index + 1;
		
	if (index - 1 >= 0) 
		thumb1.src = thumbs[index - 1].url;
	else 
		thumb1.src = thumbs[thumbs.length + (index - 1)].url;

	thumb2.src = thumbs[index].url;
	
	if (index + 1 >= thumbs.length) 
		thumb3.src = thumbs[(index + 1) - thumbs.length].url;
	else 
		thumb3.src = thumbs[index + 1].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 == '1')
		scroll('left');
	else 
		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);
	if (thumbScroll) 
		interval = window.setInterval("scroll('right')", slideShowInterval);
	else
		interval = window.setInterval("start_AllThumbs()", 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 swapImage_AllThumbs(i) {
    index = i;
    stopSlideShow();

    var imageCount = document.getElementById("ImageCount");
    if (imageCount != null) imageCount.innerHTML = (index + 1) + " of " + images.length;

    var image = document.getElementById("Image");
    image.src = images[index].url;

    if (document.all) {
        image.style.filter = "progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)";
        image.filters[0].Apply();
        image.filters[0].Play();
    }
}

function start_AllThumbs() {
    if (index == images.length - 1)
        index = 0;
    else
        index += 1;

    var imageCount = document.getElementById("ImageCount");
    if (imageCount != null) imageCount.innerHTML = (index + 1) + " of " + images.length;

    var image = document.getElementById("Image");
    image.src = images[index].url;

    if (document.all) {
        image.style.filter = "progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)";
        image.filters[0].Apply();
        image.filters[0].Play();
    }
}

function imageBack_AllThumbs() {
  stopSlideShow();
	index -= 1;
	if (index < 0) index = images.length - 1;
	swapImage_AllThumbs(index);
}

function imageNext_AllThumbs() {
  stopSlideShow();
	index += 1;
	if (index == images.length) index = 0;
	swapImage_AllThumbs(index);
}

function swapColor(index) {
    document.getElementById("largeColorImage").src = colors[index].url;
	document.getElementById("largeColorImageName").innerHTML = colors[index].name;
}

function swapEvoxStill(index) {
    document.getElementById("EvoxStill").src = evoxStills[index].url;
}

function showOptions(containerID) {
    var el = document.getElementById(containerID);
    if (el.style.display == 'block') {
        el.style.display = 'none';
    }
    else {
        el.style.display = 'block';
    }
}
				
function infoTabClick(current, start) {
	// set tabs
	if (lastInfoTab == null) lastInfoTab = document.getElementById(start + "Tab");
	lastInfoTab.className = "DetailTab";
	
	var tab = document.getElementById(current + "Tab");
	tab.className = "DetailTabActive";
	lastInfoTab = tab;

	// set content
	if (lastInfoContent == null) lastInfoContent = document.getElementById(start + "Content");
	lastInfoContent.style.display = 'none';
	
	var content = document.getElementById(current + "Content");
	content.style.display = 'block';
	lastInfoContent = content;
}

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 imagesTabClick(current, start) {
	// set tabs
	if (lastImagesTab == null) lastImagesTab = document.getElementById(start + "Tab");
	lastImagesTab.className = "DetailTab";
	
	var tab = document.getElementById(current + "Tab");
	tab.className = "DetailTabActive";
	lastImagesTab = tab;

	if (current == 'EvoxVideo')
	    showEvoxVideo();
	else
	    hideEvoxVideo();

	if (current == 'InteriorSpins') showInteriorSpin();
	if (current == 'ExteriorSpins') showExteriorSpin();
	  
	// set content
	if (lastImagesContent == null) lastImagesContent = document.getElementById(start + "Content");
	lastImagesContent.style.display = 'none';
	
	var content = document.getElementById(current + "Content");
	content.style.display = 'block';
	lastImagesContent = content;
}

function showExteriorSpin() {
    try {
        swfobject.embedSWF(exteriorSpinUrl, "ExteriorSpin", "320", "240", "9", "swf/expressInstall.swf");
    }
    catch (e) {
        // do nothing
    }
}

function showInteriorSpin() {
    try {
        swfobject.embedSWF(interiorSpinUrl, "InteriorSpin", "320", "240", "9", "swf/expressInstall.swf");
    }
    catch (e) {
        // do nothing
    }
}

function showEvoxVideo() {
    try {

        var el = document.getElementById("evox-video");
        if (el == null) {
            var vc = document.getElementById("VideoContainer");
            vc.innerHTML = "<div id='evox-video'><h3>This page requires <a href='http://www.macromedia.com/go/getflashplayer'>Adobe Flash Player</a>.</h3></div>";
        }

        var flashvars = { file: evoxVideoUrl, autostart: "true" };
        var params = { allowfullscreen: "true", allowscriptaccess: "always" };
        var attributes = {};

        swfobject.embedSWF('swf/player.swf', "evox-video", "320", "240", "9", "swf/expressInstall.swf", flashvars, params, attributes);

        //        var so = new swfobject('swf/player.swf', 'ply', '320', '240', '9', '#ffffff');
        //        so.addParam('allowfullscreen', 'true');
        //        so.addParam('allowscriptaccess', 'always');
        //        so.addParam('wmode', 'opaque');
        //        so.addVariable('file', evoxVideoUrl);
        //        so.addVariable('autostart', 'true');
        //        so.write('evox-video');
    }
    catch (e) {
        // do nothing
    }
}

function hideEvoxVideo() {
    var vc = document.getElementById("VideoContainer");
    if (vc != null) vc.innerHTML = "";
}

//function popUpLargeImage() {
//	popUp("inventoryDisplay1.aspx?s=imagegallery&veh=imagegallery&index=" + index + "&id=" + vehicleID, "img", 682, 545);
//}
