function gallery(data, div) {
  jQuery('#' + div).html("<div id=loader style=height:180px;></div>");
  jQuery('#' + div).slideDown('slow');
  loadgallery(data, div);
}

function loadgallery(data) {
    loadgallery1(data);
    loadgallery2(data,1);
    
}

function loadgallery1(data, div) {
	url = "includes/gallery.template.php?file=" + data;
	 new Ajax.Request(url,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  onSuccess = responsegallery(response, div);
		},
		onFailure: function(){ errorHandler }
	  });
}

function loadgallery2(data, start) {
	url = "includes/gallery.modul.php?file=" + data + "&start=" + start;
	 new Ajax.Request(url,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  onSuccess = successHandler2(response);
		   jQuery("div.scrollable").scrollable({
		        size: 3, 
       		 clickable: false,
			 easing: "swing"
			});
		},
		onFailure: function(){ errorHandler }
	  });
}

function responsegallery(txt , div) {
       document.getElementById('loader').innerHTML=txt;
}

function page_index(n, start, data) {
jQuery("#gallery_index").empty();
    var code = "";
    pages = Math.ceil(n/6);
    aktuell = (start-1)/6;
    for (var i = 1; i <= pages; i++) {
        if (i != aktuell) {
               var neu = (i * 6) - 5;
               code = code + "&nbsp;<a href=javascript:loadgallery2('" + data + "'," + neu + ");>" + i + "</a>&nbsp;";
            } else {
               code = code + "&nbsp;<b>" + i + "</b>&nbsp;";
            }
    }
if (pages != 1) {
    setTimeout(function() { jQuery("#gallery_index").html(code)}, 100);
}
}


function gallerypic(url, file, div, data) {
          jQuery('#' + div).addClass('gallery_pic_loading').empty();
       file = "" + file;

	// when the DOM is ready
	jQuery(function () {
	  var img = new Image();
	  // wrap our new image in jQuery, then:
	  jQuery(img)
		
		// once the image has loaded, execute this code
		.load(function () {
		  // set the image hidden by default    
		  jQuery(this).hide();
		
		
		  // with the holding div #loader, apply:
		  jQuery('#' + div)
			// remove the loading class (so no background spinner), 
			.removeClass('gallery_pic_loading')
			// then insert our image
			.append(this);

		  // fade our image in to create a nice effect
		  jQuery(this).fadeIn();
                
                jQuery('#' + div).wrapInner('<a href="includes/image.php?file=' + data + url + '" class="lightbox" title="'+'" rel="lightbox[gallery]"></a>'); 


		})
		
		// if there was an error loading the image, react accordingly
		.error(function () {
		  // notify the user that the image could not be loaded
                jQuery('#' + div).text("Error loading " + file);
		})
		
		// *finally*, set the src attribute of the new image to our image
		.attr({ 
			  src: file,
			  title: "dasweb Picture",
			  alt: "dasweb Picture",
			  width: "100",
                       class: "lightbox",
                       id: url
			});

		
	});

}

function galleryempty(div) {
   jQuery('#' + div).empty();
}

