var photoindex;
var numphotos;
function switchPhotoGallery(galleryid) {
	$('photo_slides').style.left = 0;	// REPOSITION THE PHOTO SLIDER
	var url = "/actions/switch_gallery.php";
	var params = "id=" + galleryid;
	var aj = new Ajax.Request(
					url,
					{
						method: 'post',
						parameters: params,
						onSuccess: updateGallery
					} );
	return false;
}
function updateGallery(response) {
	var fields = response.responseText.split("}|{");
	$('photo_slides').innerHTML = fields[3];
	switchPhoto(fields[1], fields[2]);
	photoindex = 0;
	numphotos = fields[0];
}
function switchPhoto(filename, description) {
	$('photo').style.display = 'none';
	//$('photo').innerHTML = '<img src="/images/photos/m_' + filename + '" border="0" alt="' + description + '" />';
	$('photo').innerHTML = '<img src="/images/photos/' + filename + '" border="0" alt="' + description + '" id="thePhoto" onload=getImageSize() />';
	if (description == '') {
		$('media_description').innerHTML = '';
	} else {
		$('media_description').innerHTML = '<strong>description: </strong>' + description;
	}
}

	// THIS FUNCTION RESIZES THE IMAGE DEPENDING ON WHETHER THE WIDTH OR HEIGHT HAVE MORE TO CLIP OFF
function getImageSize() {
	var wdTo = 400;
	var hgTo = 260;

	var img = document.getElementById('thePhoto');
	var wd = img.width;
	var hg = img.height;

	var wdDif = wd - wdTo
	var hgDif = hg - hgTo;

	if (wdDif >= hgDif) {
		img.width = wdTo;
	} else {
		img.height = hgTo;
	}

	$('photo').style.display = 'block';
}

Effect.Transitions.exponential = function(pos) {
  return 1-Math.pow(1-pos,2);
}

function MoveLeft() {
	if(photoindex != 0 && numphotos > 6) {
	    new Effect.MoveBy('photo_slides', 0, 64 , 
							{
							  duration: 0.4,  
							  transition: Effect.Transitions.exponential,
							  queue: 'end'
							});
		photoindex--;
	}
}

function MoveRight() {
	if((numphotos - photoindex - 6) > 0) {
	    new Effect.MoveBy('photo_slides', 0, -64 , 
							{
							  duration: 0.4,  
							  transition: Effect.Transitions.exponential,
							  queue: 'end'
							});
		photoindex++;
	}
}
