/**
 * Poggioleone
 * marco(dot)pegoraro(at)gmail(dot)com
 * 25/06/2010
 *
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!
 * !!! jQuery 1.3 required !!!
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!
 */

/**
 * Basic configuration:
 * 1. Cmf+F Cediss
 * 2. replace with project's name (variable string)
 * 3. fill your rules
 */


/* Start jQuery wrapper */
(function($){
	
	
	/**
	 * Project's Object
	 * Classe che contiene tutte le funzionalitö espresse dal progetto.
	 */
	var PoggioleoneClass = function( config ) {
		
		// Riferimento globale all'istanza medesima.                                               #
		// Utile all'interno dei metodi di callback utilizzati con jQuery.                         #
		var instance = this;
		
		// Project's Class main configuration rules goes here...
		var config = $.extend({foo:''
			
		},config);	
		
		/**
		 * Inizializzazione del componente.
		 */
		this.init = function() {
			
			instance.IEHacks();
			instance.imageGallery();
			
			$('.datepicker').datepicker({
				dateFormat: 'dd/mm/yy'
			});
			
			$('a.mto').mcrypt();
			
					
		} // EndOf: "init()" #######################################################################
		
		
		/**
		 * Workaround di stile da applicare al famoso browser IE!
		 */
		this.IEHacks = function() {
			
			$('ul').each(function(){
				$(this).find('li:first').addClass('first');
				$(this).find('li:last').addClass('last');
			});
				
		} // EndOf: "IEHacks()" ####################################################################
		
		
		
		this.imageGallery = function() {
			
			// Head Gallery
			$('#gallery').pslide();
			
			
			// Internal Gallery
			$('.imageGallery').each(function(){
				
				var gallery = $(this);
				var display = $(this).prev();
				
				// Creazione automatica del display per la galleria.
				if ( !display.hasClass('imageShow') && gallery.find('img').length>0 ) {
					gallery.before('<div class="imageShow"></div>');
					display = gallery.prev();
				}
				
				// Popolamento iniziale del display per la galleria.
				if ( !display.find('img').length ) {
					display.html( '<img src="'+gallery.find('a:first').attr('href')+'" />' );
				}
				
				// Gestione cambio immagine di galleria.
				gallery.find('a').bind('click',function(){
					display.html( '<img src="'+$(this).attr('href')+'" />' );
					return false;
				});
			
			});
			
		} // EndOf: "imageGallery()" ###############################################################
		
	
	} // EndOf: "Project's Class Object" --------------------------------------------------------- #

	
	
	/**
	 * Initialization Block
	 * Don't edit lines below!
	 */
	$(document).ready(function(){
		
		var tmp = new PoggioleoneClass({});
		tmp.init();
		
	});
	
	
		
	
/* End jQuery wrapper */
})(jQuery);
