// JavaScript Document
browseDiv = {
    currentDiv: 1,
    currentProject: 1,
    transitionSpeed: "slow",
    containerId: "#images",
		post_file: 'post.php',	// Post Handler
	  wait_note:'<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Loading...', // wait message
		zero_note: 'Sorry, No items match the options'	// no item message
  };
  
  browseDiv.init = function(number){
  this.loadItems(0);
	
	$("#current_div").html(browseDiv.currentDiv); // nummer aktuelles div

	//this.first();
  };
  
  browseDiv.go = function(number){
  $("#images div#img_" + this.currentDiv + "").fadeOut("slow"); 
	if(this.currentDiv+number <= imgsTotal.length && this.currentDiv+number > 0){
		this.currentDiv = this.currentDiv+number;
	}
	
	//$(this.containerId).fadeOut(this.transitionSpeed, function(){
	  $("#images div#img_" + this.currentDiv + "").fadeIn("slow"); 
		//$(browseDiv.containerId).html(imgsTotal[browseDiv.currentDiv-1]).fadeIn(this.transitionSpeed);
		$("#current_div").html(browseDiv.currentDiv);
//	});
  };
  
  browseDiv.first = function(){
    $("#images div#img_" + this.currentDiv + "").fadeIn("slow"); 
  };
  
  browseDiv.last = function(){
	 this.go(slides.length-this.currentDiv);
  }
  
  // load items based on selected parent
	browseDiv.loadItems = function(parent){			 
				$(this.containerId).html(this.wait_note);

				$.post(this.post_file, { a: 'item', p: parent },
					function(data){
							var imgs = "";
							if(data.length){
								for(i=0;i<data.length;i++) {
									imgs += '<div id="img_' + data[i].id + '"><img src="' + data[i].name + '" /></div>';
								}
							}
							else
							{
								imgs ='<div id="">'+zero_note+'</div>';
							}
							$(browseDiv.containerId).html(imgs);
							$("#images > div").hide();
								imgsTotal = $(browseDiv.containerId).children(); 
	$("#all_div").html(imgsTotal.length); // zaehler
	$("#images div#img_" + browseDiv.currentDiv + "").fadeIn("slow");
						}
					,'json');
					
					
			}
  
  
  $(document).ready(function(){
    browseDiv.init();
  });