var currentImage = 1;

function switchPhoto(value) {

	if (value == -1 && currentImage < totalPhotos) {
		currentImage++;
	}
	else if (value == -1) {
		currentImage = 0;
	}
	else if (value == -2 && currentImage > 0) {
		currentImage--;
	}
	else if (value == -2) {
		currentImage = totalPhotos;
	}
	else if (value <= totalPhotos) {
		currentImage = value;
	}
	
	showPhoto(folder, photoIds[currentImage], widths[currentImage], heights[currentImage], captions[currentImage]);
	
	return false;
}
function showPhoto(folder, id, width, height, caption) {

	var photo = document.getElementById('large');
	var container = document.getElementById('light');
	var fade = document.getElementById('fade');
	var captionSpan = document.getElementById('caption');
	var countSpan = document.getElementById('currentImage');
	var video = document.getElementById('videoPlayer');
	var audio = document.getElementById('audioPlayer');
	var printLink = document.getElementById('printLink');
	var photoId = id.replace(memberID + "_", "");
	
	photo.src = 'http://images.starnow.com/images/1pixel.gif';

	if (height > 0 && width > 0) {

		if (height > f_clientHeight() - 200) {
			width = ((width / height) * (f_clientHeight() - 200));
			height = f_clientHeight() - 200;
		}
		container.style.top = f_scrollTop() + ((f_clientHeight() - (height + 100)) / 2) + 'px';
		photo.style.height = height + 'px';

	} else {
		width = 500;
		container.style.top = f_scrollTop() + 50 + 'px';
		photo.style.height = 'auto';
		
	}
	
	container.style.width = width + 80 + 'px';
	container.style.left = (f_clientWidth() - (width + 80)) / 2 + 'px';
	container.style.right = (f_clientWidth() - (width + 80)) / 2 + 'px';
	container.style.display = 'block';
	
	photo.alt = caption;
	photo.style.width = width + 'px';

	photo.src = 'http://images.starnow.com/images/member_profile_large/' + folder + '/' + id + '.jpg';


	captionSpan.innerHTML = caption;
	countSpan.innerHTML = currentImage + 1;
	printLink.href = "/profile/PrintProfileHandler.ashx?pdf=head&m_id=" + memberID + "&application_id=" + applicationID + "&photo_id=" + photoId;

	fade.style.display = 'block';

	if (video)
		video.innerHTML = "<div style=\"width:500px;height:340px;background:#eee\"></div>";
	if (audio)
		audio.innerHTML = "<div style=\"width:500px;height:340px;background:#eee\"></div>";
	
	doXMLHTTPRequest("/profile/PhotosTrackView.aspx?photo_id=" + photoId);
}

function hidePhoto() {
	document.getElementById('light').style.display = 'none';
	document.getElementById('fade').style.display = 'none';

}
function f_clientWidth() {
	return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
