/****************************************************************************
 *  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'],
		'width':info[count]['width'],
		'height':info[count]['height'],
		'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");
		links.click(function(){
			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({
				"width":	size[0],
				"height":	size[1],
				"alt":		thumb.attr("alt"),
				"src":	src
			});
			link.attr("href",src.replace("-m.","."))
			
			desc.html($(this).attr("title"));
			return false;
		});
	});
}



