(function($){
	$.fn.slideshow = function(options){
		
		var defaults = {
			pauseSeconds: 5,
			fadeSpeed: 0.5,
			width: 385,
			height: 146
		};
		
		var options = $.extend(defaults, options);
		
		var target = this;
		var instance;
		var firstItem   = $(target).children("a:first");
		var lastItem    = $(target).children("a:last");
		
		var currentItem = firstItem;
		var makeSlideshow = function(){

			// show the current slide
			currentItem.fadeIn(options.fadeSpeed*1000, function(){
				$(target).children("a").hide();
				$(this).show().css("z-index", 1);
			});
			
			if (currentItem.children("img").attr("src") == lastItem.children("img").attr("src"))
			{
				currentItem = firstItem;
				currentItem.css("z-index", 2);
			}
			else
			{
				currentItem = currentItem.next();
			}
		};
		
		var startSlideshow = function(){
			clearInterval(instance);
			makeSlideshow();
			instance = setInterval(makeSlideshow, options.pauseSeconds*1000);
		};
		

		
		startSlideshow();
	};
})(jQuery);


$("document").ready(function()
							 {
								 	$("#img_header").slideshow();
							 });
$("document").ready(function()
							 {
								 	$("#img_header_en").slideshow();
							 });
