$(document).ready(function(){
	
	$("#banner-fader").css({
		position:'relative',
		background: 'none'
	});
	
	$("#banner-navi").css({
		position:'absolute',
		right: 0,
		zIndex:400
	});
	
	var count = images.length;
	
	$("#banner-fader .image_holder").append("<img class='loader' style='position:absolute;' src='img/loader.gif'>");
	
	$.each(images, function(i){
		$("<img />")
			.attr('src', images[i])
			.css({'display':'none', zIndex: 100 - parseInt(i), position: 'absolute'})
			.load(function(){
				if( i == (parseInt(count) - 1) ){
					setup();
				}
			})
			.appendTo("#banner-fader .image_holder");
	});
	
	setup = function(){
		$(".loader").remove();
		
		$("#banner-fader .image_holder").attr("current_image", 0);
		if(count != 1){
			$("#banner-fader .image_holder img:eq(0)").show();
			$("#banner-fader .image_holder").fadeIn();
			interval = setInterval("startFader()", 3000);
		}else{
			$("#banner-fader .image_holder").show();
			$("#banner-fader .image_holder img:eq(0)").show();
		}
	}
	
	startFader = function(){				
		current_image = parseInt($("#banner-fader .image_holder").attr("current_image"));
		if(current_image != (count-1)){
			next_image = current_image + 1;
			$("#banner-fader .image_holder").attr("current_image", next_image);
		}else{
			next_image = 0;
			$("#banner-fader .image_holder").attr("current_image", next_image);
		}
		$("#banner-fader .image_holder img:eq("+current_image+")").fadeOut(500);
		$("#banner-fader .image_holder img:eq("+next_image+")").fadeIn(500);
	}
	
	jumptoimage = function(image){
		clearInterval(interval);
		current_image = $("#banner-fader .image_holder").attr("current_image");
		next_image = image;
		if(current_image != (count-1)){
			$("#banner-fader .image_holder").attr("current_image", next_image);
		}else{
			$("#banner-fader .image_holder").attr("current_image", next_image);
		}
		$("#banner-fader .image_holder img:eq("+current_image+")").fadeOut(500);
		$("#banner-fader .image_holder img:eq("+next_image+")").fadeIn(500);
	};

	continueShow = function(){
		interval = setInterval("startFader()", 4000);
	}
	stopShow = function(){
		clearInterval(interval);
	}

	$(".jumptoimage").click(function(){
		image = $(this).attr("id").split("_")[1];
		jumptoimage(image);
	}).mouseover(function(){
		stopShow();
	}).
	mouseout(function(){		
		continueShow();
	});
		
});