;jQuery.fullslide || (function($){
	var images = new Array();
	var imagesSrc;
	var currentImage = 0;
	var imagesLoaded = 0;
	var maxImage;
	var slideshowInterval;
	var options;
	var imagePreloader = new Array();
	
	$.fn.fullslide = function() {
		imagesSrc = arguments;
		maxImage = imagesSrc.length;
		options = $.extend($.fn.fullslide.defaults, $.fn.fullslide.options);
		
		
		$(window).bind("load", function(){
			$('#nextPhoto').click(function(){
				$(this).next();
			});
			$('#previousPhoto').click(function(){
				$(this).previous();
			});
			$('#switchSlideshow').click(function(){
				$(this).switchSlideshow();
			});
		});

		
		$(document).ready(function() {
			images[0] = new imageDetails(imagesSrc[0], 0);
			
			$(imagePreloader[0] = new Image()).load(function() {
				$(this).firstImageLoaded();
			}).attr('src',imagesSrc[0]);
		});
	};
	
	$(window).bind("resize", function(){
   		$(this).redraw();
	});
	
	$.fn.firstImageLoaded = function(){
		currentImage=0;
		imagesLoaded = 1;
		$(this).goToImage(currentImage);
		
		for(var i = 1; i<imagesSrc.length; i++) {
			images[i] = new imageDetails(imagesSrc[i], i);
				
			$(imagePreloader[i] = new Image()).load(function() {
				$(this).startSlide();
			}).attr('src',imagesSrc[i]);
		}
	};
	
	$.fn.startSlide = function(){
		imagesLoaded = imagesLoaded + 1;

		if (imagesLoaded == maxImage){
			if (options.slideshow){
				slideshowInterval = setInterval("$(this).slide()", options.slide_interval);
				currentImage=1;
				$(this).goToImage(currentImage);
			}
			
			$('#nowloading').hide();
			$('#nextPhoto').show();
			$('#slideshow').show();
			$('#previousPhoto').show();
		}		
	};
	
	$.fn.redraw = function(){
		if (typeof(images[currentImage]) == 'object'){
			var pic = $('#image');
			var browserWidth = $(window).width();
			var browserHeight = $(window).height();

			if (images[currentImage].ratio >= 1){
				pic.height(browserHeight);
				pic.width(browserHeight / images[currentImage].ratio);
				if (options.horizontal_center){
					$('#supersize').css('left', (browserWidth - pic.width())/2);
					$('#supersize').css('top', 0);
				}
			} else {
				pic.width(browserWidth);
				pic.height(browserWidth * images[currentImage].ratio);
				
				if (options.vertical_center){
					$('#supersize').css('top', (browserHeight - pic.height())/2);
					$('#supersize').css('left', 0);
				}
			}
		}
	};
	
	$.fn.switchSlideshow = function(){
		if (options.slideshow){
			options.slideshow = 0;
			$('#switchSlideshow').text('Start Slideshow');
			clearInterval(slideshowInterval);
		} else {
			options.slideshow = 1;
			$('#switchSlideshow').text('Stop Slideshow');
			slideshowInterval = setInterval("$(this).slide()", options.slide_interval);
		}
	};
	
	$.fn.slide = function(){
		//clearInterval(slideshowInterval);
		currentImage = currentImage + 1;
		if (currentImage >= maxImage ){
			currentImage = 0;
		}
		
		$(this).goToImage(currentImage);
	};
	
	$.fn.goToImage = function(imageId){
		if (typeof(images[imageId]) == 'object'){
			currentImage = imageId;
			
			$('#image').attr("src", images[imageId].src);
			if (images[imageId].setImageSize(imagePreloader[imageId])){
				$(this).redraw();
			}
		}
	};
	
	$.fn.next = function(){
		currentImage = currentImage + 1;
		if (currentImage >= maxImage ){
			currentImage = 0;
		}
		$(this).afterMove();
	};
	
	$.fn.previous = function(){
		currentImage = currentImage - 1;
		if (currentImage < 0 ){
			currentImage = maxImage;
		}
		$(this).afterMove();
	};
	
	$.fn.afterMove = function(){
		if (options.slideshow){
			clearInterval(slideshowInterval);
			slideshowInterval = setInterval("$(this).slide()", options.slide_interval);
		}
		$(this).goToImage(currentImage);
	};
	
	$.fn.fullslide.defaults = {
			vertical_center: 1,
			horizontal_center: 1,
			slideshow: 1,
			slide_interval: 5000
	};
})(jQuery);

function imageDetails(imageSrc, id){
	this.src=imageSrc;
	this.id=id;
	this.height=0;
	this.width=0;
	this.ratio=0;
	this.isSet=false;
	
	this.setImageSize = function(image){
		if (this.isSet){
			return true;
		}
		
		if (!this.isSet && image.height != 0){
			this.height = image.height;
			this.width = image.width;
			this.ratio=this.height/this.width;
			this.isSet = true;
			
			return true;
		}

		return false;
	};
}