//gallery array is set in VehicleGallery
//gallery contstants
var photoLoopOn=false;
var currentPhoto=0;
//gallery methods
function goPhoto(idx,halt){
	if(halt)photoLoopOn=false;
	var divPhoto=document.getElementById('divPhoto');
	divPhoto.style.width=widthArray[idx]+'px';
	//divPhoto.style.marginTop=offSetHeightArray[idx]+'px';
	var divLightboxBefore=document.getElementById('divLightboxBefore');
	var divLightboxAfter=document.getElementById('divLightboxAfter');
	var strBefore="";
	var strPrevious="";
	var strAfter="";
	if(photoArray.length>1){
		var before;
		for(before=idx;before>0;before=before-1){
			strPrevious=strBefore;
			strBefore='<a href="'+photoArray[before-1]+'" rel="lightbox[portfolio]" title="'+captionArray[before-1]+'"></a>'+strPrevious;
		}
		var after;
		for(after=idx;after<photoArray.length-1;after=after+1){
			strAfter=strAfter+'<a href="'+photoArray[after+1]+'" rel="lightbox[portfolio]" title="'+captionArray[after+1]+'"></a>';
		}
	}
	//alert(strBefore);
	divLightboxBefore.innerHTML=strBefore;
	divLightboxAfter.innerHTML=strAfter;

	var photoLink=document.getElementById('photoLink');
	photoLink.href=photoArray[idx];
	photoLink.title=captionArray[idx];

	var photoCaption=document.getElementById('photoCaption');
	photoCaption.innerHTML=captionArray[idx];

	var photo=document.getElementById('photo');
	photo.src=photoArray[idx];
	photo.width=widthArray[idx];
	photo.height=heightArray[idx];
	photo.alt=captionArray[idx];
	photo.title=captionArray[idx];

	currentPhoto=idx;
}
function focusThumb(idx){
	if(parseInt(document.body.clientHeight)>550){
		var thumb=document.getElementById('thumb'+(idx+1));
		thumb.focus();
	}
}
function firstPhoto(halt){
	goPhoto(0,halt);
	if(halt)focusThumb(0);
}
function prevPhoto(){
	if(currentPhoto>0){
		var idx=currentPhoto-1;
		goPhoto(idx,true);
		focusThumb(idx);
	}else{
		photoLoopOn=false;
	}
}
function nextPhoto(){
	if(currentPhoto<photoArray.length-1){
		var idx=currentPhoto+1;
		goPhoto(idx,true);
		focusThumb(idx);
	}else{
		photoLoopOn=false;
	}
}
function lastPhoto(){
	goPhoto(photoArray.length-1,true);
	focusThumb(photoArray.length-1);
}
function loopPhotos(){
	if(photoLoopOn){
		if(currentPhoto>=photoArray.length-1){
			firstPhoto(false);
		}else{
			goPhoto(currentPhoto+1,false);
		}
		setTimeout('loopPhotos()',3000);
	}
}
function togglePhotoLoop(){
	if(photoLoopOn){
		photoLoopOn=false;
	}else{
		photoLoopOn=true;
		loopPhotos();
	}
}
