

function animateImage(image, link, description){
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == '7') {
	var isIE7 = true;
}

for(var i = 0; i < album_data.length; i++){

	if(album_data[i] == image) {
	current_item = i; break;
	}
 }

	$('#gallery_image_description').html(description);
	$('#galleryLoader').fadeIn('1000');
	if (isIE7) {
		image = image + '&noCache=' + Math.random();
	}
	$('<img>').attr('src',image).load(function(){
		$('#galleryItemPreviewImg').fadeOut('1000', function(){
			$('#galleryLoader').fadeOut('500');
			$('#galleryItemPreviewImg').attr('src', image);
			$('#galleryItemPreviewImg').parent().attr('href',link);
			$('#galleryItemPreviewImg').fadeIn('1000');
		})
	});
}

jQuery(document).ready(function() {
	jQuery('#gallerySliderList').jcarousel({'scroll':5});

	$('.gallerySliderThumbnail img').hover(function() {
		var fade = $(this);					 
		fade.stop().fadeTo(100, 0.75);
		
	}, function () {
		var fade = $(this);					 
		fade.stop().fadeTo(100, 1);
	});

	$('#galleryNextItem').click( function(){
		current_item -= 1;
		if(current_item < 0){ current_item = album_data.length -1;}
		if(current_item > album_data.length -1){ current_item = 0;}
		animateImage(album_data[current_item],album_data_fullsize[current_item],item_descriptions[current_item]);
	});
	$('#galleryPrevItem').click( function(){
		current_item += 1;
		if(current_item < 0){ current_item = album_data.length -1;}
		if(current_item > album_data.length -1){ current_item = 0;}
		animateImage(album_data[current_item],album_data_fullsize[current_item],item_descriptions[current_item]);
	});

	$('.gallerySliderThumbnail img').click(function(){
		$('#galleryItemPreviewImg').attr('src', 'url('+$(this).attr('src').replace('/thumbnails/','/')+')');
	});
});

