/*
* Copyright (c) 2008 John McMullen (http://www.smple.com)
* This is licensed under GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
*
*/

(function($){
	$.fn.photoGallery = function(options){
		var defaults = {
			w: 320,
			h: 240,
			holderDiv: '#gallery',
			src: 'rel',
			showTitle: true,
			showDescrizione: true,
			title: 'title',
			descrizione: 'descrizione',
			titleLoc: '#titologallery',
			descLoc: '#descrizionegallery'
		};
	
		var options = $.extend(defaults, options);
		
		var element = this;
		
		return this.each(function(){
			src = $(options.holderDiv).attr(options.src);
			title = $(options.holderDiv).attr(options.title);
			descrizione = $(options.holderDiv).attr(options.descrizione);

			if (options.showTitle === true){
				$(options.titleLoc).text(title)
			}
			if (options.showDescrizione=== true){
				$(options.descLoc).text(descrizione);
			}
			if ($(this).attr(options.src) == src) {
				$(options.holderDiv).html( '<div id="waterwheelCarousel">' + $(options.holderDiv).html() +'</div>');
			}
			
			$(this).click(function(){
				src = $(this).attr(options.src);
				title = $(this).attr(options.title);
				descrizione = $(this).attr(options.descrizione);
				
				$(options.holderDiv).html('<div id="waterwheelCarousel">' + $('div.gal[rel='+src+']').html() + '</div>');
				
				if (options.showTitle === true){
					$(options.titleLoc).text(title);
				}
				if (options.showDescrizione=== true){
					$(options.descLoc).text(descrizione);
				}
				$("#waterwheelCarousel").waterwheelCarousel("horizontal", {
					startingItem: 1,
					itemDecreaseFactor: .5,
					flankingItems: 2,
					opacityDecreaseFactor: .5,
					startingItemSeparation: 50,
					centerOffset: 60
					});
			})
		}); // end this.each
			
	}; // end fn.videoGallery
	
})(jQuery);
