curNum = 0;
imageTarget = null;
images = null;
callBackMethod = null;
wrapper = null;

function buildGallery( imgId, imageArray, callBack ){
	wrapper = document.getElementById( "wrapper" );
	images = imageArray;
	imageTarget = imgId;
	callBackMethod = callBack;	
	
}

function prev(){
	var desiredNum = curNum - 1;
	if ( desiredNum < 0 ){
		desiredNum = images.length-1;
	}
	showNum( desiredNum  );
}

function nextImage(){
	var desiredNum = curNum + 1;
	if ( desiredNum > images.length -1 ){
		desiredNum = 0;
	}	
	showNum( desiredNum  );
}

function showNum(num){
	
	var oldThumb = document.getElementById( "thumb_" + curNum );
	oldThumb.style.border = "3px solid #fbeed4";
	
	curNum = num;
	document.getElementById( imageTarget ).style.display = "none";
	document.getElementById( imageTarget ).src = images[ num ];
	wrapper.style.display = "none";


	if ( callBackMethod != null ){
		callBackMethod( images[ num ] );
	}
	
	var curThumb = document.getElementById( "thumb_" + num );
	curThumb.style.border = "3px solid #ab9168";	
}

function fadeImgIn(){
	
	wrapper.style.display = "";
	
	document.getElementById( imageTarget ).style.display = "none";
	Effect.Appear( imageTarget,  { duration: 0.8 });
}
