function startPhotoGallerySpecialtyVehicle(){
	if(document.getElementById("photoCarouselExterior")&& document.getElementById("photoCarouselInterior")){
		var widthFirstUL = document.getElementById("photoCarouselExterior").getElementsByTagName("li");
		var widthSecondUL = document.getElementById("photoCarouselInterior").getElementsByTagName("li");
		setArrowDisplay(widthFirstUL.length, widthSecondUL.length);
		widthFirstUL = 88* widthFirstUL.length;
		widthSecondUL = 88* widthSecondUL.length;
		document.getElementById("photoCarouselExterior").style.width = widthFirstUL + "px";
		document.getElementById("photoCarouselInterior").style.width = widthSecondUL + "px";
	}else{
		var widthFirstUL = document.getElementById("photoCarouselExterior").getElementsByTagName("li");
		setArrowDisplayInterior(widthFirstUL.length);
		widthFirstUL = 88* widthFirstUL.length;
		document.getElementById("photoCarouselExterior").style.width = widthFirstUL + "px";
	}	
} 

function setArrowDisplay(numImagesExterior, numImagesInterior){
		if(numImagesExterior > 4){
			document.getElementById("nextImageExterior2").className="arrowLeft_on";
		}else{
			document.getElementById("prevImageExterior").className="arrowDisabled";
			document.getElementById("nextImageExterior2").className="arrowDisabled";
		}
		
		if(numImagesInterior > 4){
			document.getElementById("nextImageInterior").className="arrowLeft_on";
		}else{
			document.getElementById("prevImageInterior").className="arrowDisabled";
			document.getElementById("nextImageInterior").className="arrowDisabled";
		}
}

function setArrowDisplayInterior(numImagesExterior){
		if(numImagesExterior > 4){
			document.getElementById("nextImageExterior2").className="arrowLeft_on";
		}else{
			document.getElementById("prevImageExterior").className="arrowDisabled";
			document.getElementById("nextImageExterior2").className="arrowDisabled";
		}
}


function rightCarouselSpeciality(elementID){
	var leftSize= parseInt(document.getElementById(elementID).style.left);
	var widthUL=parseInt(document.getElementById(elementID).style.width);
	var lastLI= widthUL - 440;
	var positiveLeft = 0;
	if(leftSize < 0){ 
		positiveLeft = leftSize*-1;
	}
	if(positiveLeft < widthUL && positiveLeft < lastLI){
		document.getElementById(elementID).style.left= leftSize - 88 +"px";
		if (elementID=="photoCarouselExterior"){
			document.getElementById("prevImageExterior").className="arrowRight_on";
		}else{
			document.getElementById("prevImageInterior").className="arrowRight_on";
		}
	}
	
	if((positiveLeft + 88) == lastLI){
		if (elementID=="photoCarouselExterior"){
			document.getElementById("nextImageExterior2").className="arrowLeft_off";
		}else{
			document.getElementById("nextImageInterior").className="arrowLeft_off";
		}
	}
	
}

function leftCarouselSpeciality(elementID){
	var leftSize= parseInt(document.getElementById(elementID).style.left);
	var widthUL=parseInt(document.getElementById(elementID).style.width);
	if(leftSize != 0){
		document.getElementById(elementID).style.left= leftSize + 88 +"px";
		if (elementID=="photoCarouselExterior"){
			document.getElementById("nextImageExterior2").className="arrowLeft_on";
		}else{
			document.getElementById("nextImageInterior").className="arrowLeft_on";
		}
	}
	if(leftSize == -88){
		if (elementID=="photoCarouselExterior"){
			document.getElementById("prevImageExterior").className="arrowRight_off";
		}else{
			document.getElementById("prevImageInterior").className="arrowRight_off";
		}
	}
}

function switchImageSpecialtyVehicle(current){
	document.getElementById("thumbVideo").style.border="#F8F8F8 3px solid";
	document.getElementById("showVideo").style.display = "none";
	document.getElementById("showImage").style.display = "block";
	
	var imgSrc=current.childNodes[0].src;
	imgSrc= imgSrc.replace("sml/","med/");		
	document.getElementById("overviewImage").src= imgSrc;
	classActive(current);
}
function classActive(obj){
	var anchorImages = document.getElementById("photoGallery").getElementsByTagName("img");
	
	for(var i=0; i<anchorImages.length; i++) 
		anchorImages[i].style.border="#F8F8F8 3px solid";
	
	if (obj)
		obj.childNodes[0].style.border="#71A1C7 3px solid";
}	

function switchImage(current){/*This function take the scr from the small photogallery image and change it for its medium image*/
	var imgSrc=current.childNodes[0].src;
	imgSrc= imgSrc.replace("sml/","med/");		
	document.getElementById("overviewImage").src= imgSrc;
	classActive(current);
	}

function changeColor(makeDescription, year, model, subModelCD, chip, colorDesc){
	document.getElementById("overviewImage").src= "/images/overview/" + makeDescription + "/" + year + "/" + model + "/" + subModelCD + "/" + "color" + "/" + chip+".jpg";	
}

function rightCarousel(elementID, arrow){
	var leftSize= parseInt(document.getElementById(elementID).style.left);
	var widthUL=parseInt(document.getElementById(elementID).style.width);
	var lastLI= widthUL - 440;
	var positiveLeft = 0;
	var classPrevElement = arrow.className.replace("next","prev");
	if(leftSize < 0)
		positiveLeft = leftSize*-1;
	if(positiveLeft < widthUL && positiveLeft < lastLI){
		document.getElementById(elementID).style.left= leftSize - 88 +"px";			
			arrow.previousSibling.previousSibling.className = classPrevElement;
		}
	leftSize= parseInt(document.getElementById(elementID).style.left) * -1;
	if(leftSize >= lastLI){
		if(arrow.className.indexOf("Disable") == -1)
			arrow.className= arrow.className + "Disable";
	}
}

function leftCarousel(elementID, arrow){
	var leftSize= parseInt(document.getElementById(elementID).style.left);
	var widthUL=parseInt(document.getElementById(elementID).style.width);
	var classNextElement = arrow.className.replace("prev","next");
	classNextElement = classNextElement.replace("Disable","");
	if(leftSize != 0){
		document.getElementById(elementID).style.left= leftSize + 88 +"px";
		arrow.nextSibling.nextSibling.className= classNextElement;
		}
	leftSize= parseInt(document.getElementById(elementID).style.left);
	if(leftSize == 0){
		if(arrow.className.indexOf("Disable") == -1)
			arrow.className= arrow.className + "Disable";
	}
	}


function showColorTip(id){
	var chip = document.getElementById(id);
	var cNameContainer = document.getElementById("cChipName");
	cNameContainer.getElementsByTagName("span")[0].innerHTML = chip.getElementsByTagName("span")[0].innerHTML;		
	var text = cNameContainer.getElementsByTagName("span")[0].innerHTML;
	var tipContainerWidth = cNameContainer.offsetWidth;	
	var size = text.length * 6 + 10; 

	if(document.body.className.indexOf("Explorer6") > -1)
		cNameContainer.style.width = size;
		
	var containerPosX = containerPosY = 0;
	var arrow = document.getElementById("tipArrow");
	
	if(document.body.className.indexOf("Explorer7") > -1 || document.body.className.indexOf("Explorer8") > -1){
		var chipPos = getPosition(chip);
		containerPosX = Math.round((chipPos[0] + 20) - (tipContainerWidth/2));
		containerPosY = chipPos[1] - 32;
	}else{
		if(document.body.className.indexOf("Explorer6") > -1){
			var chipPos = getPosition(chip);
			containerPosX = Math.round((chipPos[0] + 20) - (size/2));
			containerPosY = chipPos[1] - 32;	
		}else{
			containerPosX = Math.round((chip.offsetLeft + 20) - (tipContainerWidth/2));
			containerPosY = chip.offsetTop - 32;	
		}
	}
	cNameContainer.style.left = containerPosX + "px";
	cNameContainer.style.top = containerPosY + "px";
	
	if(document.body.className.indexOf("Explorer6") > -1)
		arrow.style.left = Math.round(containerPosX + (size/2) - 8) + "px";
	else
		arrow.style.left = Math.round(containerPosX + (tipContainerWidth/2) - 12) + "px";
		
	arrow.style.top = containerPosY + 19 + "px";
	
	cNameContainer.style.visibility = "visible";
	arrow.style.visibility = "visible";
}

function hideColorTip(){
	document.getElementById("cChipName").style.visibility = "hidden";
	document.getElementById("tipArrow").style.visibility = "hidden";
}

function getPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showVideo() {
	classActive();
	document.getElementById("thumbVideo").style.border="#71A1C7 3px solid";
	document.getElementById("showImage").style.display = "none";
	document.getElementById("showVideo").style.display = "block";
}