// JavaScript Document
browseDiv = {
    currentDiv: 1,
    project: "project1",
    transitionSpeed: "slow",
    containerId: "#images",
		//post_file: 'typo3conf/ext/ce_studioolympia/media/post.php',	// Post Handler
		post_file: 'index.php',	// Post Handler
	  wait_note:'<div class="loading"><img src="fileadmin/templates/gfx/loading.jpg" /></div>', // wait message
		zero_note: 'Sorry, No items match the options'	// no item message
  };
  
  browseDiv.init = function(project){
  this.project = project;
  this.loadItems(0);
	
	$("#current_div").html('<img src="fileadmin/templates/gfx/'+browseDiv.currentDiv+'.jpg" />'); // 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;
	}else{
    //hier dann zum naechsten projekt wechseln
    num = this.project.substr(7); //nummer des akteullen projekts
    next = parseInt(num)+parseInt(number);
    //alert(totalNumberOfProjects);
    //alert(num);
    if(next < totalNumberOfProjects && next >= 0){
      this.project = 'project'+next;
      this.currentDiv = 1;
      $("#text").fadeOut("slow");
      this.loadItems(0);
    }
  }
	
	//$(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('<img src="fileadmin/templates/gfx/'+browseDiv.currentDiv+'.jpg" />'); // nummer aktuelles div
//	});
  };
  
  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);
	 category = $("#category").html();
	 pid = $("#pid").html();
   //alert('hier');
	 $.post(this.post_file, { eID: 'tx_cestudioolympia_pi1', project: this.project, category: category, pid: pid},
   function(data){
			var imgs = "";
			//alert(data.length);
			totalNumberOfProjects = data.length;
			if(data.length){
		//	 size = data.length++;
				for(i=0;i<data.length;i++) {
				  
				 // alert(number);
					imgs += '<div id="img_' + data[i].id + '" text-align="center"><img src="uploads/tx_cestudioolympia/' + data[i].name + '" /></div>';
				}
				text = '<p>'+data[0].headline+'<br />'+data[0].description+'</p>';
			}
			else{imgs ='<div id="">'+zero_note+'</div>';}
			
			$(browseDiv.containerId).html(imgs);
			$("#text").html(text).fadeIn("slow");
			$("#images > div").hide();
			$(".project-bg").css("background","#f3f3f4");
			imgsTotal = $(browseDiv.containerId).children(); 
	    $("#all_div").html('<img src="fileadmin/templates/gfx/'+imgsTotal.length+'.jpg" />'); // zaehler
	    $("#images div#img_" + browseDiv.currentDiv + "").fadeIn("slow");
	}
	,'json');
	}
  
  
  $(document).ready(function(){
    /*********** projekt-detail ansicht *****/
    //browseDiv.init();
    $("#browse").hide();
    $("#projects").hide();
    category = $("#category").html();
    pid = $("#pid").html();
    
	
    var project = 'project0';
                
    //browse initialisieren
    browseDiv.init(project);
    $("#browse").fadeIn("slow"); 
    
    
  });
