$(function() {

	$('a.lightbox').lightBox(); // Select all links with lightbox class
	$('.cycle').cycle({ 
    	next:   '#left_arrow', 
	    prev:   '#right_arrow' 
	}); // Put rotate cycle
	
	
	/* Really not a very good way to do this... */
	
	$('.image_link_previous').click(function() {
	
		var image_id = $('#image_' + $('#current_image').attr('image_id')).prev().attr('image_id');
		
		if(image_id > 0) {

			// Hide the current image to show the "loading" background
			$('img#current_image').css("display", "none");
				
			// Load new image in the background
			var img = new Image();
			
			img.onload = function() { 
				$('img#current_image').attr("src", img.src);
				$('img#current_image').attr("image_id", image_id);
				$('img#current_image').css("display", "block");
			}
			
			// Load image
			img.src = $('#image_' + $('#current_image').attr('image_id')).attr('previous_image');

		}
				
		return false;

	});
		
	$('.image_link_next').click(function() {
	
		// Hide the current image to show the "loading" background
		$('img#current_image').css("display", "none");

		var image_id = $('#image_' + $('#current_image').attr('image_id')).next().attr('image_id');
				
		// Load new image in the background
		var img = new Image();
		
		img.onload = function() { 
			$('img#current_image').attr("src", img.src);
			$('img#current_image').attr("image_id", image_id);
			$('img#current_image').css("display", "block");
		}
		
		// Load image
		img.src = $('#image_' + $('#current_image').attr('image_id')).attr('next_image');
				
		return false;
	});


/* GALLERY IMAGE LOADER */

	$('.image_link').click(function() {

		// Replace "Current" class to show full opacity on correct thumbnail image
		//$('#gallery_images img').removeClass("current");
		//$(this).addClass("current");
	
		// Hide the current image to show the "loading" background
		$('img#current_image').css("display", "none");

		var image_id = $(this).attr("image_id");
				
		// Load new image in the background
		var img = new Image();
		
		img.onload = function() { 
			$('img#current_image').attr("src", img.src);
			$('img#current_image').attr("image_id", image_id);
			$('img#current_image').css("display", "block");
		}
		
		// Load image
		img.src = $(this).attr("image");
		
		return false;

	});

});
