

Function.prototype.create = function(options) {

	var fn = this;
	options = $H({
		'bind': fn,
		'event': false,
		'arguments': null,
		'delay': false,
		'periodical': false,
		'attempt': false
	}).merge(options);

	if (options.get('arguments') != null && typeof options.get('arguments') != 'undefined' && !(options.get('arguments') instanceof Array))
		options.set('arguments',[options.get('arguments')]);
		/* not sure */
	return function(event){
		var args = options.get('arguments') || arguments;
		if (options.get('event')){
			event = (options.get('event') === true) ? event || window.event : new options.event(event);
			args = [event].concat(args);
		}
		var returns = function(){
			return fn.apply(options.get('bind'), args);
		};
		if (options.get('delay')) return setTimeout(returns, options.get('delay'));
		if (options.get('periodical')) return setInterval(returns, options.get('periodical'));
		if (options.get('attempt')){
			try {
				var result = returns();
			} catch(err){
				result = err;
			} finally {
				return result;
			}
		} else return returns();
	}
}

Function.prototype.delay = function(ms, bind, args) {
	return this.create({'delay': ms, 'bind': bind, 'arguments': args})();
}

var Scroller = Class.create();
Scroller.prototype = {

	initialize : function(owner,wrapper) {
		this.owner = owner;
		this.wrapper = wrapper;
		this.direction = 0;
		this.running = false;
		this.mousex = 0;
		this.mousey = 0;
		this.position = 0;
		this.element = this.wrapper.childNodes[0];
		this.speed = 0.006;

		this.timeoutdelay = 40;

		Event.observe(document,'mousemove', this.mousemove.bindAsEventListener(this));

		this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
   	this.originalTop  = parseFloat(this.element.getStyle('top')  || '0');

	},
	mousemove : function(e) {
		this.mousex = Event.pointerX(e);
		this.mousey = Event.pointerY(e);
	},
	start : function() {
		this.running = true;

		this.run();
	},
	stop : function() {
		this.running = false;
	},
	moveLeft : function() {
		this.direction = 1;
	},
	moveRight : function() {
		this.direction = -1;
	},
	run : function() {
    //alert('move');
		var p = this.mousex-Position.cumulativeOffset(this.wrapper)[0];
		var p1 = p/Element.getDimensions(this.wrapper).width;
   
		var p = this.mousey-Position.cumulativeOffset(this.wrapper)[1];
		var p2 = p/(Element.getDimensions(this.wrapper).height+20);
    
		if (p2 > 1.4 && this.owner.carouselContainer.style.top === "0px") {
		//	this.owner.toggleCarousel();
		//	this.stop();
		}
    
		if (p1 > 0.7 && this.position <= 1-this.speed && p2 >= 0 && p2 <= 1) {      //ci va solo quando mi posiziono sull'ultimo elemento
			
			this.position += this.speed;
		} else if (p1 < 0.2 && this.position >= this.speed && p2 >= 0 && p2 <= 1) {
			
			this.position -= this.speed;
		} else {
  
		}
		this.position = Math.round(this.position*100)/100;
   
		Element.setStyle(this.element,{
			  
	      left: Math.round((Element.getDimensions(this.element).width - Element.getDimensions(this.wrapper).width )  * -this.position + this.originalLeft) + 'px'
	    });

		if (!this.running) return;

		setTimeout(function(){ this.run() }.bind(this) , this.timeoutdelay);
	}

}


var Gallery = Class.create();

Gallery.prototype	= {

	initialize: function(element, options) {
		this.options = $H({
			showArrows: true,
			showCarousel: true,
			showInfopane: false,
			showControl: true,
			thumbHeight: 75,
			thumbWidth: 100,
			thumbSpacing: 10,
			embedLinks: true,
			fadeDuration: 0.5,
			timed: true,
			delay: 5000,
			preloader: true,
			manualData: [],
			populateData: true,
			elementSelector: "div.imageElement",
			gallerySelector: "div.galleryElement",
			titleSelector: "h3",
			subtitleSelector: "p",
			linkSelector: "a.open",
			imageSelector: "img.full",
			thumbnailSelector: "img.thumbnail",
			linkThumbnail: "img.open",
			slideInfoZoneOpacity: 0.7,
			slideControlOpacity: 0.7,
			carouselMinimizedOpacity: 0.4,
			carouselMinimizedHeight: 20,
			carouselMaximizedOpacity: 0.7,
			destroyAfterPopulate: true,
			baseClass: 'swGallery',
			withArrowsClass: 'withArrows',
			useThumbGenerator: false,
			thumbGenerator: 'resizer.php',
			maxiter: 2,
			lang : 'it'
        }).merge(options);

		this.msg_opener = $H({
		  'fr'	: 'Images',
		  'en'	: 'Overview',
		  'sp'	: 'Resumen',
		  'it'	: 'Galleria',
		  'de'	: '&Uuml;bersicht'
		 });

		this.currentIter = 0;
		this.lastIter = 0;
		this.maxIter = this.options.get('maxiter');
		this.maxThumb = 0;
		this.galleryElement = element;
		this.galleryData = this.options.get('manualData');
		this.galleryInit = 1;
		this.galleryElements = Array();
		this.thumbnailElements = Array();
		this.paused =0;
		this.moveSlide = false;
		
		Element.addClassName(this.galleryElement,this.options.get('baseClass'));

		if (this.options.get('populateData'))
			this.populateData();
		element.style.display="block";

		if (this.options.get('embedLinks')) {
			this.currentLink = Builder.node('a', { className : 'open' , href: '#' , title: '',rel: 'lightbox[camere]'});
			element.appendChild(this.currentLink);

			if ((!this.options.get('showArrows')) && (!this.options.get('showCarousel')))
				this.galleryElement = element = this.currentLink;
			else
				Element.setStyle(this.currentLink,{'display' : 'none'});
		}

		this.constructElements();
		if ((data.length>1) && (this.options.get('showArrows'))) {
			//var leftArrow = Builder.node('a',{className : 'left' });
			//element.appendChild(leftArrow);
			//Event.observe(leftArrow,'click', this.prevItem.bindAsEventListener(this), false);
      //
			//var rightArrow = Builder.node('a',{className : 'right' });
			//element.appendChild(rightArrow);
			//Event.observe(rightArrow,'click', this.nextItem.bindAsEventListener(this), false);

			Element.addClassName(this.galleryElement,this.options.get('withArrowsClass'));
		}
		this.loadingElement = Builder.node('div',{className : 'loadingElement' });
		element.appendChild(this.loadingElement);

		if (this.options.get('showInfopane')) this.initInfoSlideshow();
		if (this.options.get('showControl')) this.initControlSlideshow();
		if (this.options.get('showCarousel') && (!this.options.get('moveSlide'))) this.initCarousel();
		this.doSlideShow(1);
	},

	populateData: function() {
		currentArrayPlace = this.galleryData.length;
		options = this.options;
		data = this.galleryData;
		
		this.galleryElement.getElementsBySelector(options.get('elementSelector')).each(function(el) {
			elementDict = {
				image: (el.getElementsBySelector(options.get('imageSelector'))[0]).getAttribute('href'),
				number: currentArrayPlace
			};
			if ( (options.get('showInfopane')) | (options.get('showCarousel')))
				Object.extend(elementDict, {
					title: el.getElementsBySelector(options.get('titleSelector'))[0].innerHTML,
					description: el.getElementsBySelector(options.get('subtitleSelector'))[0].innerHTML
				});
			if (options.get('embedLinks'))
				Object.extend(elementDict, {
					link: el.getElementsBySelector(options.get('linkSelector'))[0].href||false,
					linkTitle: el.getElementsBySelector(options.get('linkSelector'))[0].title||''
				});
			if ((!options.get('useThumbGenerator')) && (options.get('showCarousel')))
				Object.extend(elementDict, {
					thumbnail: el.getElementsBySelector(options.get('thumbnailSelector'))[0].src
				});
			else if (options.get('useThumbGenerator'))
				Object.extend(elementDict, {
					thumbnail: options.get('thumbGenerator')+'?imgfile=' + elementDict.image + '&max_width=' + options.get('thumbWidth') + '&max_height=' + options.get('thumbHeight')
				});

      Object.extend(elementDict, {
					linkThumb: el.getElementsBySelector(options.get('linkSelector'))[0].href||false
				
				}); 
			
			data[currentArrayPlace] = elementDict;
			
			currentArrayPlace++;
			if (this.options.get('destroyAfterPopulate'))
				el.remove();
		});
		this.galleryData = data;
	},
	constructElements: function() {
		el = this.galleryElement;
		this.maxThumb = this.galleryData.length;
		//this.maxIter = 3;
		var currentImg;
		for(i=0;i<this.galleryData.length;i++) {
			var currentImg = Builder.node('div',{className : 'slideElement'});
			
			Element.setStyle(currentImg,{
					'position':'absolute',
					'left':'0px',
					'right':'0px',
					'margin':'0px',
					'padding':'0px',
					'backgroundImage':"url('" + this.galleryData[i].image + "')",
					'backgroundPosition':"center center",
					'opacity':'0'
				});
			el.appendChild(currentImg);
			this.galleryElements[parseInt(i)] = currentImg;
		}
	},
	goToPaused : function(num) {
		this.clearTimer();		
		if (this.options.get('embedLinks'))
			this.clearLink();
			
		this.changeItemPaused.delay(0, this, num);
		if (this.options.get('embedLinks'))
			this.makeLink(num);
		
	},
	goTo : function(num) {
		this.clearTimer();
		if (this.options.get('embedLinks'))
			this.clearLink();
		
		if (this.options.get('showInfopane') ) {
			this.changeItem(num);
		} else			
			this.changeItem.delay(500, this, num);
		if (this.options.get('embedLinks'))
			this.makeLink(num);
		this.prepareTimer();
	},
	startSlideShow : function() {
		this.loadingElement.style.display = "none";
		this.lastIter = this.maxIter - 1;
		this.currentIter = 0;
		this.galleryInit = 0;
		this.paused= 0;
		Element.setStyle(this.galleryElements[parseInt(this.currentIter)],{'opacity' : 100});
			if (this.options.get('moveSlide')) 
		{
			new Effect.Parallel([
  		new Effect.Move(this.galleryElements[parseInt(this.currentIter)], { sync: true, x: 0, y: -300, mode: 'relative' }), 
  		new Effect.Opacity(this.galleryElements[parseInt(this.currentIter)], { sync: true, from: 1, to: 0 }) 
		], { 
  	duration: 5.8,
  	delay: 0.5
	 });

			
			}	
		if (this.options.get('showInfopane') )
			this.showInfoSlideShow.delay(1000, this);
		if (this.options.get('showControl') )
			this.showControlShow.delay(1000, this);
	
		this.prepareTimer();
		if (this.options.get('embedLinks'))
			this.makeLink(this.currentIter);
	},
	  restartSlideShow : function() {			
		this.paused= 0;
		var slideControlPauseLink=Builder.node('a', { className : 'controlPauseBtn',id : 'controlPauseBtn' , href: '#' , title: '' });
		var slideControlPlayLink = document.getElementById("controlPlayBtn");
		var parentDiv = slideControlPlayLink.parentNode;		
    parentDiv.replaceChild(slideControlPauseLink, slideControlPlayLink);	
   
    var slideControlLeftLink = document.getElementById("left");
    var parentDiv = slideControlLeftLink.parentNode;    
    parentDiv.removeChild(slideControlLeftLink);
    
    var slideControlRightLink = document.getElementById("right");
    var parentDiv = slideControlRightLink.parentNode;		    
    parentDiv.removeChild(slideControlRightLink);
    
		Event.observe(slideControlPauseLink,'click', this.stopSlideShow.bindAsEventListener(this), false);
		this.nextItem();
		

	},	  
	  stopSlideShow : function() {			
		this.paused= 1;
		var slideControlPlayLink=Builder.node('a', { className : 'controlPlayBtn' , id : 'controlPlayBtn', href: '#' , title: '' });
		var slideControlPauseLink = document.getElementById("controlPauseBtn");
		var parentDiv = slideControlPauseLink.parentNode;		
    parentDiv.replaceChild(slideControlPlayLink, slideControlPauseLink);	
		Event.observe(slideControlPlayLink,'click', this.restartSlideShow.bindAsEventListener(this), false);
		
		var slideControlLeftArrow = Builder.node('a',{className : 'left' , id: 'left'});
		parentDiv.appendChild(slideControlLeftArrow);
		Event.observe(slideControlLeftArrow,'click', this.prevItem.bindAsEventListener(this), false);
		
		var slideControlRightArrow = Builder.node('a',{className : 'right' , id: 'right' });
		parentDiv.appendChild(slideControlRightArrow);
		Event.observe(slideControlRightArrow,'click', this.nextItemPaused.bindAsEventListener(this), false);



	},
	nextItemPaused: function() {
	   
			this.nextIter = this.currentIter+1;
			if (this.nextIter >= this.maxIter)
			this.nextIter = 0;
			this.galleryInit = 0;
		  this.goToPaused(this.nextIter);
	},
	nextItem: function() {
	  if (	this.paused == 1) {this.goToPaused(this.nextIter);}
	  else  {
			this.nextIter = this.currentIter+1;
			if (this.nextIter >= this.maxIter)
			this.nextIter = 0;
			this.galleryInit = 0;
		 this.goTo(this.nextIter);}
	},
	prevItem: function() {		
		this.nextIter = this.currentIter-1;
		if (this.nextIter <= -1)
			this.nextIter = this.maxIter - 1;
		this.galleryInit = 0;
		if (	this.paused == 1) {this.goToPaused(this.nextIter);} else {this.goTo(this.nextIter);}

		
	},
	changeItemPaused: function(num) {
	
		this.galleryInit = 0;
		if (this.currentIter != num) {
			for(i=0;i<this.maxIter;i++) {
				if ((i != this.currentIter)) Element.setStyle( this.galleryElements[i],{'opacity' : 0});
			}
			if (num > this.currentIter) {
				new Effect.Opacity(this.galleryElements[num], {duration: this.options.get('fadeDuration'), from:0, to: 1});
			}
			else {
				Element.setStyle( this.galleryElements[num] ,{'opacity' : 100});
				new Effect.Opacity(this.galleryElements[this.currentIter], {duration: this.options.get('fadeDuration'), from:1, to: 0});
			}
			this.currentIter = num;
		}
		this.doSlideShow.bind(this)();
	 
	},
	changeItem: function(num) {
		//Element.setStyle(this.galleryElements[parseInt(this.currentIter)],{'opacity' : 100});	
		if(this.paused == 0){
		this.galleryInit = 0;
		if (this.currentIter != num) {
			for(i=0;i<this.maxIter;i++) {
				//per tutti gli elementi della galleria tranne il corrente
				if ((i != this.currentIter)) 
				{
					Element.setStyle( this.galleryElements[i],{'opacity' : 0, 'top': 0 });
 			
				} 
			}   
			if (num > this.currentIter) {
						if (this.options.get('moveSlide')) 
							{
								new Effect.Parallel([
								new Effect.Opacity(this.galleryElements[num], {sync: true, duration: this.options.get('fadeDuration'), from:0, to: 1}),			
  							new Effect.Move(this.galleryElements[num], { sync: true, x: 0, y: -300, mode: 'relative' }),
  							new Effect.Opacity(this.galleryElements[num], { sync: true, from: 1, to: 0 }) 
							], { 
  						duration: 5.8,
  						delay: 0.5
						 });
						 
						}
						else
							{
								new Effect.Opacity(this.galleryElements[num], {duration: this.options.get('fadeDuration'), from:0, to: 1});
				             
								}
			}
			else {
				//restart ciclo
				if (this.options.get('moveSlide')) 
							{    
								  this.paused=1;
								
									Element.setStyle( this.galleryElements[num] ,{'opacity' : 0, 'top': '-150px'});
				          new Effect.Opacity(this.galleryElements[num], {delay:0.5,duration: this.options.get('fadeDuration'), from:0, to: 1});
		
						 if (this.options.get('showCarousel')) this.initCarousel();  
						}
						else
							{  
									Element.setStyle( this.galleryElements[num] ,{'opacity' : 100});
				          new Effect.Opacity(this.galleryElements[this.currentIter], {duration: this.options.get('fadeDuration'), from:1, to: 0});
		
								}
			}
			this.currentIter = num;
		}
		this.doSlideShow.bind(this)();
	  }
	},
	clearTimer: function() {
		if (this.options.get('timed'))
			/*$clear(this.timer);*/
			this.timer = 0 ;


	},
	prepareTimer: function() {
		if (this.options.get('timed'))
			this.timer = this.nextItem.delay(this.options.get('delay'), this);
	},
	doSlideShow: function(position) {
		
		if (this.galleryInit == 1) {
			imgPreloader = new Image();
			imgPreloader.onload=function(){
				this.startSlideShow();
			}.bind(this);
			imgPreloader.src = this.galleryData[0].image;
		} else {
			if (this.options.get('showInfopane') ) {
				this.showInfoSlideShow.delay((500 + this.options.get('fadeDuration')), this);
			}
			if (this.options.get('showControl') ) {
				this.showControlShow.delay((500 + this.options.get('fadeDuration')), this);
			}
		}
	
},
	initCarousel: function () {
		this.carouselContainer = Builder.node('div', {id : 'carouselContainer', className : 'carouselContainer'});
		//Element.setStyle(this.carouselContainer,{'opacity' : this.options.carouselMinimizedOpacity});


		this.galleryElement.appendChild(this.carouselContainer);
		this.carouselContainer.normalHeight = this.carouselContainer.offsetHeight;
		Element.setStyle(this.carouselContainer,{'top': (this.options.get('carouselMinimizedHeight') - this.carouselContainer.normalHeight)});

		this.carouselBtn = Builder.node('a', {className : 'carouselBtn', title: this.msg_opener.get([this.options.get('lang')])});
		this.carouselBtn.innerHTML = this.msg_opener.get([this.options.get('lang')]);
		this.carouselContainer.appendChild(this.carouselBtn);

		Event.observe(this.carouselBtn,'click', function () {
				this.toggleCarousel();
			}.bindAsEventListener(this), false);

		this.carouselActive = false;

		this.carousel = Builder.node('div', { className : 'carousel' } );
		this.carouselContainer.appendChild(this.carousel);

		this.carouselInner = Builder.node('div', { className : 'carouselInner' });
		this.carouselWrapper = Builder.node('div', { className : 'carouselWrapper' }, [ this.carouselInner ] );
		this.carouselLabel = Builder.node('p', { className : 'label' });
		this.carousel.appendChild(this.carouselLabel );
		this.carousel.appendChild(this.carouselWrapper );

		Element.setStyle(this.carouselContainer.id,{'top' : '-'+Element.getDimensions(this.carousel).height+'px'});

		Element.setStyle(this.carouselInner,{'overflow' : "hidden", "position" : "absolute"});

		this.scroller = new Scroller(this,this.carouselWrapper);

		this.constructThumbnails();

		this.carouselInner.style.width = ((this.maxThumb * (this.options.get('thumbWidth') + this.options.get('thumbSpacing'))) - this.options.get('thumbSpacing') + this.options.get('thumbWidth')) + "px";
	},
	toggleCarousel: function() {
		if (this.carouselActive)
			this.hideCarousel();
		else
			this.showCarousel();
	},
	showCarousel: function () {
		new Effect.Move(this.carouselContainer,{ x: 0, y: this.carousel.getDimensions().height, mode: 'relative'});
		this.carouselActive = true;
		this.scroller.start();
	},
	hideCarousel: function () {

		new Effect.Move(this.carouselContainer,{ x: 0, y: -this.carousel.getDimensions().height, mode: 'relative'});
		this.carouselActive = false;
		this.scroller.stop();
	},
	thumbnailMousOver : function(e,thumbnail) {
		//this.carouselLabel.innerHTML = '<span class="number">' + (thumbnail.relatedImage.number + 1) + "/" + this.maxIter + ":</span> " + thumbnail.relatedImage.title;
		new Effect.Opacity(thumbnail.id, {duration:0.5, from: this.options.get('carouselMinimizedOpacity'), to:1.0});
	},
	thumbnailMousOut : function(e,thumbnail) {
		this.carouselLabel.innerHTML = '';
		new Effect.Opacity(thumbnail.id, {duration:0.5, from: 1.0, to: this.options.get('carouselMinimizedOpacity')});
	},
	thumbnailClick : function(e,thumbnail) {

		//this.goTo(thumbnail.relatedImage.number);
		//this.paused=true;
	},
	constructThumbnails: function () {
		for(i=0;i<this.galleryData.length;i++) {
			var currentLink = Builder.node('a', {className: 'thumbnail',id: 'thumbnail_'+i, href:  this.galleryData[i].linkThumb   , title: '', rel: "lightbox[thumbnail_"+i+"]" });
      Element.setStyle(currentLink,{
					backgroundImage: "url('" + this.galleryData[i].thumbnail + "')",
					backgroundPosition: "center center",
					backgroundRepeat: 'no-repeat',
					marginLeft: this.options.get('thumbSpacing') + "px",
					left: (this.options.get('thumbWidth')*i)+this.options.get('thumbSpacing') + "px",
					width: this.options.get('thumbWidth') + "px",
					height: this.options.get('thumbHeight') + "px"
			});			
			Element.setStyle(currentLink,{'opacity' : this.options.get('carouselMinimizedOpacity')});
			//alert(this.galleryData[i].linkThumb);
			//Element.getElementsBySelector(options.get('linkSelector'))[0].href;
		

			this.carouselInner.appendChild(currentLink);
			
			

			
			

			Event.observe(currentLink,'mouseover', this.thumbnailMousOver.bindAsEventListener(this,currentLink));
			Event.observe(currentLink,'mouseout', this.thumbnailMousOut.bindAsEventListener(this,currentLink));
			//Event.observe(currentLink,'click', this.thumbnailClick.bindAsEventListener(this,currentLink));
     
 
			currentLink.relatedImage = this.galleryData[i];
			this.thumbnailElements[parseInt(i)] = currentLink;
		}
	},
	centerCarouselOn: function(num) {
		var carouselElement = this.thumbnailElements[num];
		var position = carouselElement.element.offsetLeft + (carouselElement.element.offsetWidth / 2);
		var carouselWidth = this.carouselWrapper.offsetWidth;
		var carouselInnerWidth = this.carouselInner.offsetWidth;
		var diffWidth = carouselWidth / 2;
		var scrollPos = position-diffWidth;

		this.carouselWrapper.elementScroller.scrollTo(scrollPos,0);
	},
	initInfoSlideshow: function() {
		if (this.slideInfoZone)
			this.slideInfoZone.remove();
		this.slideInfoZone = Builder.node('div', { className : 'slideInfoZone' } );
		this.galleryElement.appendChild(this.slideInfoZone);
		var slideInfoZoneTitle = Builder.node('h2', {} );
		this.slideInfoZone.appendChild(slideInfoZoneTitle);
		var slideInfoZoneDescription = Builder.node('p', {} );
		this.slideInfoZone.appendChild(slideInfoZoneDescription);
		this.slideInfoZone.normalHeight = this.slideInfoZone.offsetHeight;
		Element.setStyle(this.slideInfoZone,{'opacity' : 0});
	},
	changeInfoSlideShow: function() {
		this.hideInfoSlideShow.delay(10, this);
		this.showInfoSlideShow.delay(500, this);
	},
	showInfoSlideShow: function() {
		element = this.slideInfoZone;
		//element.getElementsBySelector('h2')[0].innerHTML = this.galleryData[this.currentIter].title;
		//element.getElementsBySelector('p')[0].innerHTML = this.galleryData[this.currentIter].description;
		Effect.Appear(element,{'to' : this.options.get('slideInfoZoneOpacity')});
		return this.slideInfoZone;
	},
	hideInfoSlideShow: function() {
		this.slideInfoZone.custom({'opacity': 0, 'height': 0});
		return this.slideInfoZone;
	},
	initControlSlideshow: function() {
		if (this.slideControl)
			this.slideControl.remove();
		this.slideControl = Builder.node('div', { className : 'slideControl' , id : 'slideControl'} );
		this.galleryElement.appendChild(this.slideControl);
		var slideControlPauseLink=Builder.node('a', { className : 'controlPauseBtn' , id: 'controlPauseBtn', href: '#' , title: '' });
		this.slideControl.appendChild(slideControlPauseLink);
		Event.observe(slideControlPauseLink,'click', this.stopSlideShow.bindAsEventListener(this), false);
			var slideControlDescription = Builder.node('p', {}, 'slideshow' );
		this.slideControl.appendChild(slideControlDescription);
		var slideControlSlideNumber = Builder.node('div', {className : 'slide', id: 'slide',opacity: 100}, '1/' + this.maxIter  );
		this.slideControl.appendChild(slideControlSlideNumber);
		
	},
	changeControlShow: function() {
		this.hideControlShow.delay(10, this);
		this.showControlShow.delay(500, this);
	},
	showControlShow: function() {
		element = this.slideControl;
		//element.getElementsBySelector('h2')[0].innerHTML = this.galleryData[this.currentIter].title;
		//alert(element.getElementsBySelector('p')[0].innerHTML)
		var corrente=this.nextIter+1;
		if (!corrente) 
		  corrente=1;
		//alert(element.getElementsById('slide'));
		//element.getElementsById('slide')[0].innerHTML =  (corrente) +'/'  + this.maxIter ;
		
    document.getElementById("slide").firstChild.nodeValue=(corrente) +'/'  + this.maxIter ;


   
		Effect.Appear(element,{'to' : this.options.get('slideControlOpacity')});
		return this.slideControl;
	},
	hideControlShow: function() {
		this.slideControl.custom({'opacity': 0, 'height': 0});
		return this.slideControl;
	},
	makeLink: function(num) {
		this.currentLink.setAttribute('href', this.galleryData[num].link);
		this.currentLink.setAttribute('title', this.galleryData[num].linkTitle);

		if (!((this.options.get('embedLinks')) && (!this.options.get('showArrows')) && (!this.options.get('showCarousel'))))
			Element.setStyle(this.currentLink,{ 'display' : 'block'});
	},
	clearLink: function() {
		this.currentLink.setAttribute('href', '');
		this.currentLink.setAttribute('title', '');
		if (!((this.options.get('embedLinks')) && (!this.options.get('showArrows')) && (!this.options.get('showCarousel'))))
			Element.setStyle(this.currentLink,{ 'display' : 'none'});
	}
};
