jQuery.fn.jmorphGallery=function(settings){return this.each(function(){settings=jQuery.extend({timeout:1000},settings);var parent=$(this);var images=new Array;var currentImageNr=0;var preloadImage=new Image();$(".band li a",parent).each(function(i){images.push($(this).attr('href'))});preloadImage.src=images[currentImageNr];$(preloadImage).bind('load',function(){$('.nextImg',parent).css('background-image','url('+images[currentImageNr]+')').width(preloadImage.width).height(preloadImage.height).css('opacity','0');$('.currentImg',parent).animate({width:preloadImage.width,height:preloadImage.height},settings.timeout,function(e){$('.currentImg',parent).css('background-image','url('+images[currentImageNr]+')');$('.nextImg',parent).css('opacity','1')});$('.nextImg',parent).animate({opacity:'1'},settings.timeout)});function loadImage(){preloadImage.src=images[currentImageNr];var current=$('ul li',parent).removeClass('selected').eq(currentImageNr).addClass('selected');var band=$('.band',parent);band.animate({marginLeft:(-current.position().left+band.offset().left)+"px"})}$(".previous",parent).click(function(e){currentImageNr<=0?0:currentImageNr--;loadImage()});$(".next,.nextImg",parent).click(function(e){currentImageNr>=images.length-1?images.length-1:currentImageNr++;loadImage()});$("div ul li",parent).click(function(e){e.preventDefault();currentImageNr=$('li',this.parentNode).index(this);loadImage()})})};

$(document).ready(function (){
	replaceImages();
});
i=0;
function replaceImages(){
	source = $("#hg").find('li').eq(i).find("img").attr('src');
	//alert("S = "+source);
	$(".hgallery").css({opacity:0.1});
	$(".hgallery").css('background',"url('"+source+"') left top no-repeat").animate({opacity:1},'fast');
	//alert("Len: "+$("#hg").find('li').length);
	if($("#hg").find('li').length-1>i){
		i++;
	} else { i=0;}
	setTimeout('replaceImages()',5000);
}