var AJAXGallery = gallery.extend( {
	initialize : function(element, options) {
		this.setOptions( {
			showArrows :true,
			embedLinks: false,
			showCarousel :false,
			showInfopane :false,

			timed :false,
			defaultTransition :"fade",
			fadeDuration: 100,

			galleryNavId :false,
			externalNavigation :true,
			getDataUrl :false
		}, options);

		var AJAX = new Ajax(this.options.getDataUrl, {
			method: 'get',
			onComplete: (function(content) {
        
                this.galleryObject.options.manualData = Json.evaluate(content);
        
                this.galleryObject.parent(element, this.galleryObject.options);
                
                //this.galleryObject.lightbox = Lightbox;
                //this.galleryObject.lightbox.init({resizeSpeed: 100, animate: true, overlayOpacity: 0.8, allowSave: false, slideshowAutoplay: false, slideshowInterval: 5000, slideshowAutoclose: true,lllImage: 'Bild', lllOf: 'von'});
                //console.log(Lightbox);
                        
                if (this.galleryObject.options.externalNavigation && $(this.galleryObject.options.galleryNavId)) {
                    var navigation = $(this.galleryObject.options.galleryNavId);
                    var navPrev = new Element('a').addClass('prev').setProperties( {
                        title :'prev'
                    }).addEvent('click', this.galleryObject.prevItem.bind(this.galleryObject)).injectInside(navigation);
                     // need to do this for Safari!
                    navPrev.setHTML('&nbsp;');
                    var navNext = new Element('a').addClass('next').setProperties( {
                        title :'next'
                    }).addEvent('click', this.galleryObject.nextItem.bind(this.galleryObject)).injectInside(navigation);
                     // need to do this for Safari!
                    navNext.setHTML('&nbsp;');
                    
                    var navCounter = new Element('div').addClass('projektcounter').injectAfter(navigation);
                    navCounter.setHTML('1 / '+this.galleryObject.maxIter);			
                    this.galleryObject.addEvent('onChanged', function(){navCounter.setHTML((this.currentIter + 1) + ' / ' + this.maxIter);});
                    
                    if ($(this.galleryObject.options.galleryNavId + 'desc')) {
                        var description = $(this.galleryObject.options.galleryNavId + 'desc');
                        var imageDesc = new Element('span').injectAfter(description);
                        imageDesc.setHTML(this.galleryObject.galleryData[0].description);			
                        this.galleryObject.addEvent('onChanged', function(){imageDesc.setHTML(this.galleryData[this.currentIter].description);});
                    }
                }
			  })
		});
        AJAX.galleryObject = this;
		AJAX.request();


	}/*,
    makeLink: function(num) {
		this.parent(num);
		this.currentLink.onclick = this.lightbox.click.pass(this.currentLink);
	}*/

});
