var image_current = 1;
var pageLoaded = null;

function imageReset (image_current) {

	document.getElementById('counter').innerHTML			= image_current + "/" + image_count;
	if (document.getElementById('teaser-caption')) 
		document.getElementById('teaser-caption').innerHTML		= image_body[image_current];
	if (document.getElementById('teaser-body'))
		document.getElementById('teaser-body').innerHTML		= image_body[image_current];
	//jQuery("#counter").html (image_current + "/" + image_count);
	$('#teaser-image').fadeOut('def', function() {$(this).attr('src', image_paths[image_current]).fadeIn();});
	$('#gallery-lineup a').removeClass('thumbSelected');
	$('#thumb'+image_current).addClass('thumbSelected');
	//document.images["teaser-image"].src 					= image_paths[image_current];
	document.images["teaser-image"].title 					= image_titles[image_current];
	document.images["teaser-image"].alt 					= image_alts[image_current];
	if(image_credit[image_current] != "") {
		document.getElementById('teaser-credit').innerHTML = "<strong>Photo credit:</strong> <span>"+image_credit[image_current]+"</span>";
	}
	else {document.getElementById('teaser-credit').innerHTML = "";
	}
	image_reset = image_current;
}

function imageRotate (direction) {
	image_current = image_reset;
	if (image_current == 1) {
		if (direction == "next") {
			image_current++;
		} else if (direction == "previous") {
			image_current = image_count ;
		}
	} else if (image_current == image_count) {
		if (direction == "next") {
			image_current = 1;
		} else if (direction == "previous") {
			image_current--;
		}
	} else {
		if (direction == "next") {
			image_current++;
		} else if (direction == "previous") {
			image_current--;
		}
	}
	
	imageReset (image_current);
}

function thumbReset (image_current) {

	document.getElementById('counter').innerHTML			= image_current + "/" + image_count;
	if (document.getElementById('teaser-caption')) 
		document.getElementById('teaser-caption').innerHTML		= image_body[image_current];
	if (document.getElementById('teaser-body'))
		document.getElementById('teaser-body').innerHTML		= image_body[image_current];
	//jQuery("#counter").html (image_current + "/" + image_count);
	$('#teaser-image').fadeOut('def', function() {$(this).attr('src', image_paths[image_current]).fadeIn();})
	//document.images["teaser-image"].src 					= image_paths[image_current];
	document.images["teaser-image"].title 					= image_titles[image_current];
	document.images["teaser-image"].alt 					= image_alts[image_current];
	if(image_credit[image_current] != "" && document.getElementById('teaser-credit')) {
		document.getElementById('teaser-credit').innerHTML = "<strong>Photo credit:</strong> <span>"+image_credit[image_current]+"</span>";
	}
	else if (image_credit[image_current] == "" && document.getElementById('teaser-credit')) {document.getElementById('teaser-credit').innerHTML = "";
	}
	//image_reset = image_current;
}

function thumbRotate (direction) {
	//image_current = image_reset;
	if (image_current == 1) {
		if (direction == "next") {
			image_current++;
		} else if (direction == "previous") {
			image_current = image_count ;
		}
	} else if (image_current == image_count) {
		if (direction == "next") {
			image_current = 1;
		} else if (direction == "previous") {
			image_current--;
		}
	} else {
		if (direction == "next") {
			image_current++;
		} else if (direction == "previous") {
			image_current--;
		}
	}
	
	thumbReset (image_current);
}

function imageLoad() {
	image_current = 1;
	document.getElementById('counter').innerHTML			= image_current + "/" + image_count;
	if (document.getElementById('teaser-caption')) 
		document.getElementById('teaser-caption').innerHTML		= image_body[image_current];
	if (document.getElementById('teaser-body'))
		document.getElementById('teaser-body').innerHTML		= image_body[image_current];
	//jQuery("#counter").html (image_current + "/" + image_count);
	document.images["teaser-image"].src 					= image_paths[image_current];
	document.images["teaser-image"].title 					= image_titles[image_current];
	document.images["teaser-image"].alt 					= image_alts[image_current];
	if(image_credit[image_current] != "" && document.getElementById('teaser-credit')) {
		document.getElementById('teaser-credit').innerHTML = "<strong>Photo credit:</strong> <span>"+image_credit[image_current]+"</span>";
	}
	image_reset = image_current;
}

$(document).ready(function(){
	imageLoad();
});
