/****************************************************************************
 *  slideshow_gallery
 ****************************************************************************/
 /* =Slideshow
-----------------------------------------------------------------------------*/
function doSlideshow(info,count){
	if(count==undefined){
		count = 1;
		// Load all Images
		$.each(info,function(){
			$("<img>").attr("src",this['Path']);
		});	
	}
	//if(info.repeat == undefined) {info.repeat = 3;}
	if(count == info.length){
		count = 0;
		//info.repeat --;
		//if(info.repeat == 0) return false;
	}
	setTimeout(function(){changeSlide(info,count);},5000);
};
function changeSlide(info,count){
	var show = $("body .SlideshowArea img:first").parent();
	var img  = show.find("img:first");
	var nImg = $("<img>").attr({
		'src':info[count]['Path'],
		'height':'300',
		'alt':info[count]['Name']
	}).prependTo(show).hide();
	img.fadeOut(500,function(){$(this).remove(); nImg.fadeIn(500);});
	show.find('.description').html(info[count]['Description']);
	count++;
	doSlideshow(info,count);
};

/* =Image change on gallery thumb click
-----------------------------------------------------------------------------*/
function galleryClicks(){
	$("body .ImageGalleryArea").each(function(){
		var gallery = $(this);
		var image		= gallery.find("img:first");
		var link		= gallery.find("a.lightbox");
		var desc		= gallery.find(".description");
		var links		= gallery.find("ul.galleryThumbs li a");
		var timer		= false;
		var loaded		= [];
		links.click(function(){
			clearTimeout(timer);
			var thumb = $(this).find("img:first");
			if(thumb.length==0){
				thumb = $(this).find("span:first");
				var src = thumb.attr("rel");
			}else{
				var src = thumb.attr("src").replace("-t.","-m.");
			}
			var size = $(this).attr("rel").split(',');
			image.attr({
				"height":	'320',
				"alt":		thumb.attr("alt"),
				"src":		src
			}).hide();
			link.attr("href",src.replace("-m.","."));
			if($.inArray(src,loaded)<0)
			{
				timer = setTimeout(function(){image.fadeIn(); loaded.push(src);},500);
				var ld_img = new Image();
				var img_loaded = function(){loaded.push(src); image.fadeIn(); clearTimeout(timer);};
				ld_img.src = src;
				ld_img.onload = img_loaded;
			}
			else
				{ image.fadeIn(); }
			desc.html($(this).attr("title"));
			return false;
		});
	});
}




