/*
    This file is part of JonDesign's SmoothGallery v2.1beta1.

	SmoothCategory v1.2beta
	This is a extension for SmoothGallery, it not works with original SmoothGallery,
	modified versione needed, not possibile to extend without it.

	This software ( SmoothCategory ) is not free to distribuite and/or modify it.
	It's not an open-source project for now.

    Main Developer: Fabio a.k.a. Nightmare (la_fabio@hotmail.com)

	06/07/2009
*/

var categorySet = new Class({
	Extends: gallery,
	initialize: function(element, options) {
		this.setOptions({
			manualSetData: [],
			gallerySelector: "div.galleryElement",
			galleryTitleSelector: "h2",
			textGallerySelector: 'Gallerie',
			textShowGallerySelector: 'Altre Gallerie',
			textShowCategory: 'Album',
			textGalleryInfo: '{0} ',
			startWithSelector: true,
			/* Changing default options */
			textShowCarousel: 'Foto',//'Foto {0} di {1}',
			carouselPreloader: false,
			/* Category */
			categoryMinimized: 36,
			categoryMaximizedOpacity: 0.8,
			categoryMinimizedOpacity: 0.6,
			/*** JUMPS WORLD ***/
			showCategory: false,
			showToolbar: true,
			showSearch: false,
			showSendUrl: false,
			showFullscreen: true,
			showSlideShow: true,
			showArrowsToolbar: true,
			showSelectPhoto: false,
			showRating: false,
			showDelete: false,
			showBanner: false,
			photos: 15,
			category_id: 636,
			photo: 0,
			mail: 0,
			position: 0,
			dir: "/",
			myjumps: 0,
			fullscreen: 0,
			segnalazione: 0,
			prov: '',
			id_user: 0
		});
		this.setOptions(options);
		this.searchTerm = "";
		this.categorySet = this.options.manualSetData;
		this.addEvent('OnCreateCategoryContainer', this.load_categories);
		this.addEvent('OnLoadCat', this.createCategoryTab);
		this.parent(element, this.options);

		if(this.options.showToolbar)
			this.createToolbar();

		if(this.options.showCategory)
			this.createCategoryContainer();

		if(this.options.showBanner)
			this.createBannerContainer();

//		if(this.options.showSearch)
//			this.createSearchField();

//		if(this.options.photo)
	//		this.goTo(this.options.photo);

		this.addDynamicCarousel();
	},
	populateData: function() {
		options = this.options;
		var data = $A(this.categorySet);
		this.populateFrom.getElements(options.gallerySelector).each(function (galEl) {
			currentGalArrayPlace = 0;
			galleryDict = {
				title: galEl.getElement(options.galleryTitleSelector).innerHTML,
				elements: []
			}
			galleryDict.elements.extend(this.populateGallery(galEl, 0));
			data.extend([galleryDict]);
			if (this.options.destroyAfterPopulate)
				galEl.dispose();
		}, this);
		this.categorySet = data;
		this.galleryData = data[0].elements;
		this.currentCategory = this.options.category_id;
		this.limit_from = 0;
/*		if(this.options.photo>0)
			this.goTo(this.options.photo);*/
	},
	createCategoryContainer: function() {
		var categoryElement;
		var categoryContainerElement = new Element('div').addClass('categoryContainer').injectInside(this.galleryElement);
		this.categoryContainer = new Fx.Morph(categoryContainerElement, {transition: Fx.Transitions.Expo.easeOut});
//		var categoryContainerTitle = new Element('h2').injectInside(this.categoryContainer.element);
		this.categoryContainer.normal = categoryContainerElement.offsetWidth;
		this.categoryContainer.set({'opacity': this.options.categoryMaximizedOpacity, 'left': this.options.categoryMinimized - this.categoryContainer.normal});

		categoryElement = new Element('div', {'id':'category'}).addClass('category').injectInside(categoryContainerElement);

		this.categoryBtn = new Element('a').addClass('categorySelectorBtn').setProperties({
			title: this.options.textShowCategory
		}).injectInside(categoryContainerElement);
		this.categoryBtn.addEvent(
			'click',
			function(){ this.toggleCategorySelector(true); }.bind(this)
		);

		this.fireEvent('OnCreateCategoryContainer');
	},
	createToolbar: function(){
		var self=this; // utilizzato perché non è possibile utilizzare .bind(this) all'interno degli nuovi elementi ( qui form )
		this.toolbarContainer = new Element('div').addClass('toolbarContainer').injectBefore(document.getElement('.carouselContainer'));

		this.floatSx = new Element('div').setStyle('float','left').injectInside(this.toolbarContainer);
		this.floatDelete = new Element('div').setStyle('float','right').injectInside(this.toolbarContainer);
		this.floatDx = new Element('div').setStyle('float','right').injectInside(this.toolbarContainer);

	// debug button to get 10 moar photo from current category w/ scrolling carousel
	// this.toolbarContainer.set('html', '<a href="#moar_photo">moar</a>').addEvent('click',function(){this.moar_photo(this.currentCategory,10)}.bind(this));

		if(this.options.showSearch){
			searchForm = new Element('form').setProperties({
												 action	: self.options.dir+'gallery_files/search_photos.php?segnalazione=' + this.options.segnalazione + '&prov=' + this.options.prov + '&id_user=' + this.options.id_user,
												 method	: 'post'
											   }).addClass('toolbarForm'
											   ).addEvent('submit',
													function(e){
														$('cat').value=self.currentCategory;
														e.stop();
														this.set('send', {
																 onComplete: function(response){
																	 	if(response!='false'){
																			//self.currentCategory=0; // remove comment to search without categories
																			self.searchResult(response);
																			self.searchTerm=$('search').value;
																			self.searchField.setProperty('readonly','readonly');
																			self.searchBtn.setStyle('display','none');
																			self.deleteSearchBtn.setStyle('display','inline');
																		}else
																			$('search').value='nessuna foto trovata';
																	 }
																 })
														this.send();
													}
												).injectInside(this.floatSx);

			this.searchField = new Element('input').addClass('formField').setProperties({
				type	: 'text',
				name	: 'search',
				id		: 'search',
				value	: 'Cerca'
			}).addEvents({
				'focus': function(){ if(!this.searchField.getProperty('readonly')) this.searchField.value=""; }.bind(this).bind(this)
			//	'blur' : function(){ this.searchField.value="Cerca con la tua email"; }.bind(this)			
			}).injectInside(searchForm);

			var searchFormCategoryIdField = new Element('input').addClass('formField').setProperties({
				type: 'hidden',
				name: 'cat',
				id	: 'cat'
			}).injectInside(searchForm);

			this.searchBtn = new Element('input'
										 ).addClass('formBtn'
										 ).setProperties({
											 type	: 'image',
											 src	: self.options.dir+'gallery_files/css/img/cerca.png'
											 }
										 ).injectInside(searchForm);

			this.deleteSearchBtn = new Element('img'
										 ).addClass('formBtn'
										 ).setStyles({
											'display':'none'
											}
										 ).setProperties({
											 type	: 'image',
											 src	: self.options.dir+'gallery_files/css/img/cancella.png'
											 }
										 ).addEvent('click',
											function(){
												this.searchField.value="";
												this.searchField.removeProperty('readonly','readonly');
												this.deleteSearchBtn.setStyle('display','none');
												this.searchBtn.setStyle('display','inline');
											}.bind(this)
										 ).injectInside(searchForm);
		}

		if(this.options.showSendUrl){
			var sendUrlForm = new Element('form').setProperties({
												 action	: self.options.dir+'gallery_files/send_mail.php',
												 method	: 'post',
												 name	: 'sendUrlForm',
												 id		: 'sendUrlForm'
											   }).addClass('toolbarForm'
											   ).injectInside(this.floatSx);

			// Check controllo email
			var formcheck = new FormCheck('sendUrlForm',
				{
				submitByAjax : true,
				display : {
					closeTipsButton : 0,
					flashTips : 1,
					fixPngForIe: 0,
					closeTipsButton:1,
					scrollToFirst: false
					},
				onAjaxRequest: function(){
					$('photo_id').set('value',self.galleryData[self.currentIter].description)
				},
				onAjaxSuccess : function(){
					this.sendUrlEmailField.value="Jump inviato";
				}.bind(this)
			})

			this.sendUrlEmailField = new Element('input').addClass('formField validate[\'required\',\'email\']').setProperties({
				type: 'text',
				name: 'email',
				value: 'Invia ad un amico',
				id:'email'
			}).addEvents({
				'focus': function(){ this.sendUrlEmailField.value=""; }.bind(this)
			//	'blur' : function(){ this.sendUrlEmailField.value="Invia ad un amico"; }.bind(this)			
			}).injectInside(sendUrlForm);

			formcheck.register($('email')); 

			this.sendUrlPhotoNumberField = new Element('input').addClass('formField').setProperties({
				type: 'hidden',
				name: 'photo_id',
				id	: 'photo_id'
			}).injectInside(sendUrlForm);

			this.sendUrlBtn = new Element('input'
										 ).addClass('formBtn'
										 ).setProperties({
											 type	: 'image',
											 src	: self.options.dir+'gallery_files/css/img/mail.png'
										 }).injectInside(sendUrlForm);
		}

		if(this.options.showFullscreen)
			var fullscreen = new Element('img'
										 ).setProperties({
											 src	: self.options.dir+'gallery_files/css/img/fullscreen.png',
											 title	: 'Fullscreen',
											 alt	: 'Fullscreen'
											 }
										 ).setStyles({'margin-left':'10px'}
//										 ).addEvent('click',function(){this.crosspop(this.options.timed, this.currentCategory, this.galleryData[this.currentIter].description, this.currentIter)}.bind(this)
										 ).addEvent('click',function(){
											if(this.options.showSearch)
												var searchValue=$('search').value;
											else
												var searchValue="";
										//	 var what=Base68.encode(this.options.myjumps+"javascript:void(0);"+searchValue+"javascript:void(0);"+this.currentCategory+"javascript:void(0);"+this.galleryData[this.currentIter].description+"javascript:void(0);"+this.options.mail+"javascript:void(0);"+this.currentIter+"javascript:void(0);"+this.options.timed);
												var what=Base68.encode(this.options.myjumps+"javascript:void(0);"+searchValue+"javascript:void(0);"+this.currentCategory+"javascript:void(0);"+this.galleryData[this.currentIter].description+"javascript:void(0);"+this.options.mail+"javascript:void(0);"+this.currentIter+"javascript:void(0);"+this.options.timed + "javascript:void(0);" + this.options.segnalazione + "javascript:void(0);" + this.options.id_user);
											 this.crosspop68(what)}.bind(this)
										 ).injectInside(this.floatSx);
		else
			var fullscreen = new Element('img'
										 ).setProperties({
											 src	: self.options.dir+'gallery_files/css/img/fullscreen_close.png',
											 title	: 'Chiudi Fullscreen',
											 alt	: 'Chiudi Fullscreen'
											 }
										 ).setStyles({'margin-left':'10px'}
										 ).addEvent('click',function(){window.close();window.opener.myCategorySet.goTo(self.currentIter-1)}
										 ).injectInside(this.floatSx);

		if(this.options.showSlideShow && this.galleryData.length>1){
			if(this.options.timed==true){
					var pausa_display='inline';
					var play_display='none';
			}else{
					var pausa_display='none';
					var play_display='inline';
			}
			var slideShow = new Element('img'
										 ).setProperties({
											 src	: self.options.dir+'gallery_files/css/img/pausa.png',
											 title	: 'Stop Slideshow',
											 alt	: 'Stop Slideshow',
											 id		: 'pausa'
											 }
										 ).setStyles({'margin-left':'10px', 'display':pausa_display}
										 ).addEvent('click',this.pause.bind(this)
										 ).injectInside(this.floatSx);

			var slideShow = new Element('img'
										 ).setProperties({
											 src	: self.options.dir+'gallery_files/css/img/play.png',
											 title	: 'Play Slideshow',
											 alt	: 'Play Slideshow',
											 id		: 'play'
											 }
										 ).setStyles({'margin-left':'10px', 'display':play_display}
										 ).addEvent('click',this.continue_after_pause.bind(this)
										 ).injectInside(this.floatSx);
		}

		if ((this.galleryData.length>1)&&(this.options.showArrowsToolbar))
		{
			var leftArrow = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/indietro.png',
												title	: 'Indietro',
												alt		: 'Indietro'
												}
											).setStyles({'margin-left':'10px'}
											).addClass('left').addEvent('click', this.prevItem.bind(this)
											).injectInside(this.floatSx);
			var rightArrow = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/avanti.png',
												title	: 'Avanti',
												alt		: 'Avanti'
												}
											).setStyle('margin-left','10px'
											).addClass('left').addEvent('click', this.nextItem.bind(this)
											).injectInside(this.floatSx);
		}

		if (this.options.showSelectPhoto)
		{
			/* invio foto e' presente sia in modalita' normale che fullscreen */
			/*
			if(!this.options.fullscreen){ 
			var selectPhoto = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/selfoto.png',
												title	: 'Seleziona foto',
												alt		: 'Seleziona foto'
												}
											).setStyle('margin-right','10px'
											).addEvent('click', function(){
																	$('id_photo_selected').value=this.galleryData[this.currentIter].description;
																	if(this.options.myjumps){
																		ajaxAddPic();
																	}
																}.bind(this)
											).injectInside(this.floatSx);
			}
			*/
			/*
			else{
			var selectPhoto = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/inviafoto.png',
												title	: 'Invia ad un amico',
												alt		: 'Invia ad un amico'
												}
											).setStyle('margin-left','10px'
											).addEvent('click', function(){
																apriPopup(this.galleryData[this.currentIter].description);
																}.bind(this)
											).injectInside(this.floatSx);
			}
			*/
			var selectPhoto = new Element('img').setProperties({
												//src		: self.options.dir+'gallery_files/css/img/inviafoto.png',
												src		: self.options.dir+'gallery_files/css/img/inviafoto.png',
												title	: 'Invia ad un amico',
												alt		: 'Invia ad un amico'
												}
											).setStyle('margin-left','10px'
											).addEvent('click', function(){
																apriPopup(this.galleryData[this.currentIter].description);
																}.bind(this)
											).injectInside(this.floatSx);
			
		}

			// icona help
			if(!this.options.fullscreen){ 
			var selectPhoto = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/help.png',
												title	: 'Come utilizzare la Gallery',
												alt		: 'Come utilizzare la Gallery'
												}
											).setStyle('margin-left','10px'
											).addEvent('click', function(){
																	SqueezeBox.fromElement($('modalWindowLink'));
																}.bind(this)
											).injectInside(this.floatSx);
			}

		if (this.options.showDelete)
		{
			var selectPhoto = new Element('img').setProperties({
												src		: self.options.dir+'gallery_files/css/img/secchio.png',
												title	: 'Elimina foto',
												alt		: 'Elimina foto'
												}
											).setStyle('margin-right','10px'
											).addEvent('click', function(){
																var elimina = confirm('Vuoi eliminare le foto selezionate?');
																if(elimina){
																	req_delete.send('id='+this.galleryData[this.currentIter].description);
																	cancellaFoto();
																}
																}.bind(this)
											).injectInside(this.floatDelete);
		}

		if (this.options.showRating)
		{
			var rating = new Element('div').setProperties({
												id	: 'rating'
												}
											).setStyle('margin-right','10px'
											).injectInside(this.floatDx);
			$('rating').set('html','<div class="rabidRating" id="rabidRating-'+this.galleryData[0].description+'-'+this.galleryData[0].rating+'_100"><div class="wrapper"><span style="width: 0px; background-color:#ff0000;" class="ratingFill"><span class="ratingStars"/></span></div></div>');
			var rating = new RabidRatings();
		}
	},
	createCategorySelectorTab: function() {
		this.categorySelectorBtn = new Element('a').addClass('categorySelectorBtn').setProperties({
			title: this.options.textShowGallerySelector
		}).set('html', this.options.textShowGallerySelector).addEvent(
			'click',
			function () {
//				this.carouselContainer.cancel();
				this.toggleCategorySelector();}
		).injectInside(this.galleryElement);
//		this.addEvent('onShowCarousel', function(){this.gallerySelectorBtn.setStyle('zIndex', 10)}.bind(this));
	//	this.addEvent('onCarouselHidden', function(){this.gallerySelectorBtn.setStyle('zIndex', 15)}.bind(this));
	},
	toggleCategorySelector: function() {
		if (this.categoryActive)
			this.hideCategory();
		else
			this.showCategory();
	},
	showCategory: function () {
		this.categoryActive = true;
		this.categoryContainer.start({
			'opacity': this.options.categoryMaximizedOpacity,
			'left': 0
		})
	},
	hideCategory: function () {
		this.categoryActive = false;
		//this.fireEvent('onHideCarousel');
		var targetLeft = this.options.categoryMinimized - this.categoryContainer.normal;
		this.categoryContainer.start({
			'opacity': this.options.categoryMinimizedOpacity,
			'left': targetLeft
		})
	},
	createCategoryTab: function() {
		$each(this.categories, function(id, title){
				this.button = new Element('a', {
				'html':title,
				'href':'javascript:void(0);'
				}
			).addClass('category_tab'
			).setProperty('title', title
			).addEvent('click', function(){
				this.changeCategory(id);
				}.bind(this)
			).injectInside($('category')
			);
		}.bind(this));
	},
	changeCategory: function(category_id){
		var data=[];
		this.searchTerm="";
		if (category_id!=this.currentCategory)
		{
			var resp=req_photo.send('cat='+category_id+'&limit_from=0&limit_to=' + this.options.photos + '&segnalazione=' + this.options.segnalazione + '&prov=' + this.options.prov + '&id_user=' + this.options.id_user);
			var html=req_photo.processHTML(resp.response.html);

			this.flushCarousel();
			this.flushGallery();

			html.getElements('div.galleryElement').each(function (galEl) {
				galleryDict = {
					title: galEl.getElement('h2').innerHTML,
					elements: []
				}
				galleryDict.elements.extend(this.populateCategory(galEl, 0));
				data=galleryDict;
				if (this.options.destroyAfterPopulate)
					galEl.dispose();
			}, this);
			this.categorySet = [data];
			this.galleryData = data.elements;
			this.changeData(data.elements);
			this.maxIter = this.galleryData.length;
			this.currentCategory = category_id;
			this.preloadImage(0);
			this.addDynamicCarousel();
		}
		this.toggleCategorySelector();
		if(this.options.showBanner)
			this.loadBanner.delay(3000, this);
	},
	populateCategory: function(element, startNumber) {
		var data = [];
		options = this.options;
		currentArrayPlace = startNumber;
		element.getElements(options.elementSelector).each(function(el) {
			elementDict = $H({
				image: el.getElement(options.imageSelector).getProperty('src'),
				number: currentArrayPlace,
				transition: this.options.defaultTransition
			});
			if (options.showRating)
				elementDict.extend({
					rating: el.getElement('p.rating').innerHTML
				});
			if ((options.showInfopane) | (options.showCarousel))
				elementDict.extend({
					title: el.getElement(options.titleSelector).innerHTML,
					description: el.getElement(options.subtitleSelector).innerHTML
				});
/*			if ((options.embedLinks) | (options.useReMooz))
				elementDict.extend({
					link: el.getElement(options.linkSelector).href||false,
					linkTitle: el.getElement(options.linkSelector).title||false,
					linkTarget: el.getElement(options.linkSelector).getProperty('target')||false
				});
*/			if ((!options.useThumbGenerator) && (options.showCarousel))
				elementDict.extend({
					thumbnail: el.getElement(options.thumbnailSelector).getProperty('src')
				});
/*			else if (options.useThumbGenerator)
				elementDict.extend({
					thumbnail: options.thumbGenerator + '?imgfile=' + elementDict.image + '&max_width=' + options.thumbWidth + '&max_height=' + options.thumbHeight
				});
	*/
			data.extend([elementDict]);

			currentArrayPlace++;
			if (this.options.destroyAfterPopulate)
				el.dispose();
		});
		return data;
	},
	createBannerContainer: function() {
		this.bannerElement = new Fx.Morph(new Element('div').addClass('bannerContainer').setProperty('id','bannerContainer').injectInside(this.galleryElement));
		this.loadBanner.delay(3000, this);
	},
	hideBanner: function(){
		this.bannerElement.start({'top': -60});
	},
	showBanner: function(){
		this.bannerElement.start({'top': 0});
	},
	loadBanner: function(){
		var image = this.req_banner().response.text;
		$('bannerContainer').set('html',image);
		if($('bannerContainer').getStyle('top')=='-60px')
			this.showBanner.delay(1000, this);
	},
	searchResult: function(search_result){
		var data=[];

		var html=req_photo.processHTML(search_result);

		this.flushCarousel();
		this.flushGallery();

		html.getElements('div.galleryElement').each(function (galEl) {
			galleryDict = {
				title: galEl.getElement('h2').innerHTML,
				elements: []
			}
			galleryDict.elements.extend(this.populateCategory(galEl, 0));
			data=galleryDict;
			if (this.options.destroyAfterPopulate)
				galEl.dispose();
		}, this);
		this.categorySet = [data];
		this.galleryData = data.elements;
		this.changeData(data.elements);
		this.maxIter = this.galleryData.length;
		//this.currentCategory = 0; remove comment to search without categories
	},
	addDynamicCarousel: function(){
		var scroll=(document.getElement('.carouselInner').getScrollSize());
		// TODO numero foto per calcolare il moar_photo
//		var carousel_trigger = scroll.x - (12 * (this.options.thumbWidth + this.options.thumbSpacing + 2))+this.options.thumbSpacing;

		var carousel_trigger = scroll.x - (8 * (this.options.thumbWidth + this.options.thumbSpacing + 2 + this.options.thumbSpacing));

// DEBUG
//		var x=((this.options.thumbWidth + this.options.thumbSpacing + 2 + this.options.thumbSpacing)*10);
//		this.log('f: '+this.options.fullscreen+' photos: '+(this.options.photos)+' screen: '+screen.width+' scroll x: '+scroll.x+' trigger: '+carousel_trigger+ ' thumb x: '+x);
		if(carousel_trigger>0){
			var ss = new ScrollSpy({
				min: carousel_trigger,
				max: scroll.x,
				mode: 'horizontal',
				fullscreen: this.options.fullscreen,
				onEnter: function(position,enters) {
					this.moar_photo(this.currentCategory, this.options.photos);
//					this.options.photos+=this.options.photos;
				}.bind(this),
				/*onLeave: function(position,leaves) { 
					if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); } 
				},*/
				/*onTick: function(position,state,enters,leaves) { 
					this.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y);
				}.bind(this),*/
				container: document.getElement('.carouselWrapper')//carouselInner
			});
		}else
			return;
	},
	moar_photo: function(category_id, limit_to){
		this.limit_from=this.galleryElements.length;
		var data = $A(this.categorySet);

		var resp=req_photo.send('cat='+category_id+'&search='+this.searchTerm+'&limit_from='+this.limit_from+"&limit_to="+limit_to + '&segnalazione=' + this.options.segnalazione + '&prov=' + this.options.prov + '&id_user=' + this.options.id_user);
		if(resp.response.text!="false"){
			var html=req_photo.processHTML(resp.response.html);

			html.getElements('div.galleryElement').each(function (galEl) {
			galleryDict = {
				title: galEl.getElement('h2').innerHTML,
				elements: []
			}	
			galleryDict.elements.extend(this.populateCategory(galEl, document.getElements('.thumbnail').length));
			data[0].elements.extend(galleryDict.elements);
	
			if (this.options.destroyAfterPopulate)
					galEl.dispose();
			}, this);
			this.categorySet = data;
			this.maxIterMoar = this.categorySet[0].elements.length;
			this.moarData(galleryDict.elements);
			this.addDynamicCarousel();
		}
	},
	moarData: function(data) {
		this.galleryData = data;
		this.constructElements(document.getElements('.thumbnail').length);// FABIO , hack per il bug della numerazione delle foto , click sulle thumb , da risolvere
		if (this.options.showCarousel) this.expandCarousel();
		if (this.options.showInfopane) this.hideInfoSlideShow();
	},
	expandCarousel: function() {
		this.constructThumbnails(document.getElements('.thumbnail').length);// FABIO , hack per il bug della numerazione delle foto , click sulle thumb , da risolvere
		this.carouselInner.normalWidth = ((this.maxIterMoar * (this.options.thumbWidth + this.options.thumbSpacing + 2))+this.options.thumbSpacing) + "px";
		if (this.options.carouselHorizontal)
			this.carouselInner.style.width = this.carouselInner.normalWidth;
		this.maxIter = this.maxIterMoar;
		this.galleryData = this.categorySet[0].elements;
	},
	flushCarousel: function(){
		document.getElements('.thumbnail').each(function(el) {
			el.dispose();
			el = null;
		});
		this.thumbnailElements = [];
	},
	flushGallery: function(){
		document.getElements('.slideElement').each(function(el) {
			el.dispose();
			el = null;
		});
		this.galleryElements = [];
	},

	load_categories: function(){
		this.resp=this.req_cat();
		this.categories=JSON.decode(this.resp.response.text);
		this.createCategoryTab();
	},

	createSearchField: function(){
		// Serchfield sopra il carousel
		this.searchField = new Element('input').addClass('searchField').setProperties({
			type: 'text',
			value: 'Cerca...'
		})//.injectInside(this.carouselContainerElement);
		this.searchField.inject(document.getElement('.carouselContainer'));
		this.searchField.addEvents({
			'focus': function(){ this.searchField.value=""; }.bind(this),
			'blur' : function(){ this.searchField.value="Cerca..."; }.bind(this)			
		});
	},

	crosspop: function(slide, category_id, photo, position){
		var scrW = window.document.body.clientWidth;
		var w = screen.width;
		var scrH = window.document.body.clientHeight;
		var h = screen.height;
		var popUpWin;
		popUpWin = window.open(this.options.dir+'gallery_files/fullscreen.php?f=1&myjumps='+this.options.myjumps+'&cat='+category_id+'&photo='+photo+'&position='+position+'&slide='+slide,"oNewWin",'left=0,top=0,width='+w+',height='+h+',scrollbars=no,status=no,scrolling=no,fullscreen=yes')
	},

	crosspop68: function(wat){
		var scrW = window.document.body.clientWidth;
		var w = screen.width;
		var scrH = window.document.body.clientHeight;
		var h = screen.height;
		var popUpWin;
		popUpWin = window.open(this.options.dir+'gallery_files/fullscreen.php?f=1&wat='+wat,"oNewWin",'left=0,top=0,width='+w+',height='+h+',scrollbars=no,status=no,scrolling=no,fullscreen=yes')
	},

	req_cat: function(){
		var ajax = new Request.JSON({async: false, url:this.options.dir+'gallery_files/load_categories.php?segnalazione=' + this.options.segnalazione + '&prov=' + this.options.prov + '&id_user=' + this.options.id_user,
									//onComplete: function(response){
								//	},
									onSuccess: function(response) {
										return response;
									},
									onFailure: function() {
										alert('Connessione Fallita');
									}
					})
		return ajax.send();
	},
	req_banner: function(){
		var ajax = new Request({async: false, url:this.options.dir+'gallery_files/load_banner.php',
									//onComplete: function(response){
								//	},
									onSuccess: function(responseText){
										return responseText;
									},
									onFailure: function() {
										alert('Connessione Fallita');
									}
					})
		return ajax.send('id='+this.galleryData[this.currentIter].description);
	}
/*	// BUG , funzione non utilizzata perché all'interno della classe viene usata una funzione mootools di "Request", request.processHTML che ritorna un object
	// forse è possibile utilizzare questa funzione all'interno della chiamata ajax prima di fare il "return" 
	req_photo: function(){
		var ajax = new Request.HTML({async: false, url:this.options.dir+'gallery_files/load_photos.php',
								//	onComplete: function(response){
								//	},
									onSuccess: function(responseHTML) {
										return responseHTML;
									},
									onFailure: function() {
										alert('Connessione Fallita');
									}
					});
		return ajax.send();
	}
*/
});

// Quello di seguito andrebbe spostato all'interno della classe
var req_photo = new Request.HTML({async: false, url:'/gallery_files/load_photos.php',
//	onComplete: function(response){
//	},
	onSuccess: function(responseHTML) {
		return responseHTML;
	},
	onFailure: function() {
		alert('Connessione Fallita');
	}
});

var req_delete = new Request({async: false, url:'/gallery_files/load_photos.php',
							//onComplete: function(response){
						//	},
							onSuccess: function(response) {
								return response;
							},
							onFailure: function() {
								alert('Connessione Fallita');
							}
			});