/****************************************************************************
 *  Gallery/Slideshow
 ****************************************************************************/
jQuery(document).ready(function(){
	galleryClicks();
});
/* =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 = $("#main .type_Slideshow");
	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(){
	$(".pageImage .imgGal").each(function(){
		var gallery = $(this).parent(".pageImage");
		var image = $(this).find("img:first");
		var desc = $(this).find(".description");
		var links = gallery.find(".galthumbs li a");
		links.click(function(){
			var thumb = $(this).find("img:first");
			var size = $(this).attr("rel").split(',');
			var src = thumb.attr("src").replace("-t.","-m.");
			image.attr({
				"width":	size[0],
				"height":	size[1],
				"alt":		thumb.attr("alt"),
				"src":		src
			});
			desc.html($(this).attr("title"));
			return false;
		});
	});
}


