
// -------------------------------------------------------------------------------
// Name: Gallery foto (gallery.js, JQuery, HTML)
// Author: Altea Software S.r.l.
// Version: 1.1.0
// Description: Crea una gallery di immagini dove si può premere sulla miniatura per visualizzare la foto grande
//              inoltre è possibile muoversi tra le foto con il tasto di avanti e indietro, ad ogni foto è legata
//				una didascalia, funziona per più gallery nel sito
// Required: La corretta attivazione dei controlli richiede: Jquery 1.26, HTML.
//			 I link sulle miniature devono avere un link direttamente alla foto grande.
//			 Le miniature devono avere un title che verrà visualizzato come didascalia.
//
// Devel Date: 03/07/2008
// Last Modify: 24/07/2008
// CacheLog:
//		1.0.1 - 
//
// -------------------------------------------------------------------------------

// -------------------------------------------------------------------------------
// CONFIG

// thumb: 			Id del box che contiene le thumbnail
// gal_forw:		Id del a che manda avanti le foto
// gal_back:		Id del a che manda indietro le foto
// main_foto:		Id della foto grande, dove verranno visualizzate le piccole
// gallery_text:	Id del blocco dove verrà visualizata la didascalia 

// -------------------------------------------------------------------------------


$(document).ready(function() {
						   
	if ($("#thumb")) {
		var listLink = $("#thumb a");
		for(i=0;i<=listLink.length;i++){
			var linkCur = listLink[i];	
			if($(linkCur).attr('href')){
				$(listLink[i]).click(function(){
					var imgBig = $(this).attr('href');
					$('#main_foto').attr({ src: imgBig });
					var imgTitle = $(this).children().attr('title');
					$('#gallery_text').text(imgTitle);
					return false;
				});
			}
		}
	}	
	
	$("#gal_forw").click(function(){
		slideImages(1);
	});
	
	$("#gal_back").click(function(){
		slideImages(-1);
	});	
	
	function slideImages(move) {
		var curImgHref = $('#main_foto').attr('src');
		if ($("#thumb")) {
			var listLink = $("#thumb a");
			for(i=0;i<=listLink.length;i++){
				var linkCur = listLink[i];	 		
				var linkCurHref = $(linkCur).attr('href');	
				if (linkCurHref == curImgHref){
					var nextLink; 
					var linkBack;
					if (move == -1) {
						nextLink = $(linkCur).prev();
						linkBack = listLink[listLink.length-1];
					}
					else {
						nextLink = $(linkCur).next();
						linkBack = listLink[0];
					}
					var nextLinkHref = $(nextLink).attr('href');
					if (nextLinkHref){										
				  		$('#main_foto').attr({ src: nextLinkHref });
				  		var imgTitle = $(nextLink).children().attr('title');
				  		$('#gallery_text').text(imgTitle);
					} else {
						var linkBackHref = $(linkBack).attr('href');
						$('#main_foto').attr({ src: linkBackHref });
						var imgTitle = $(linkBack).children().attr('title');
						$('#gallery_text').text(imgTitle);				 
					}
					break;
				}
			}
		}		 	
	}
});

