
// ********************************************************************************************** //
// Gallery


var currentImage = null;
var previousImage = null;
var preventClick = 0;

$(document).ready(function() {
	
	currentImage = $('#mainimage img');
	
	$('#thumbs a').click(function() {
		return false;
	});
	
	$('#thumbs a').hover(function() {
		$(this).css({ border:"3px solid #3F9F3F" });
		if( $(currentImage).attr("src") != $(this).attr("href") ) {
			if(preventClick == 0) {
				loadImage($(this).attr("href"),$(this).attr("title"));
				preventClick = 1;
			}
		}
		return false;
	},
		function() {
			$(this).css({ border:"3px solid #5A5A5A" });
		}
	);
	
	$('#thumbs a').click(function() {
		if( $(currentImage).attr("src") != $(this).attr("href") ) {
			if(preventClick == 0) {
				loadImage($(this).attr("href"),$(this).attr("title"));
				preventClick = 1;
			}
		}
		return false;
	});
	
	$('.datepicker').datepicker();   
	init_ExternalLinks();
	
});

function loadImage(imageSrc,imageTitle) {
	
	previousImage = currentImage;
	var img = new Image();
	
	$(img).load(
		function() {
			$(img).hide();
			$('#mainimage').append(img);
			$(img).fadeIn('normal',function() {
				preventClick = 0;
				if(previousImage != null) {
					$(previousImage).remove();
				}
		});
	}).attr(
		{
			'src':imageSrc,
			'width':'590',
			'height':'336',
			'alt':imageTitle
		}
	);
	
	currentImage = img;
	
}


