/* récupération des photos */
/* récupération des photos */
/* récupération des photos */

var currentCheck = null;
var dragTimer = null;
var dragTimer2 = null;

function getNew(){
  var deb = $(".photos").length;
  getContentPage(deb);
};
function getContentPage(deb){

  if(deb===undefined){ load=true; deb=0; }else load=false;
  var rand = Math.round(Math.random()*1000000000); if(load) loadingPage();
  $.post('get.pages.php?'+rand,{start:deb,limit:500,CatID:CatID},function(e){
			try{ e=eval("("+e+")"); }catch(e){ alert("Désolé.. l'album n'a pas pu être chargée"); showContent(); return false; } 
      data=e.data; if(load){ $("#ContentPhoto").html(''); NbResult=data.length; nbLoadAjax=NbResult; }
			for(i=0;i<data.length;i++){
				var mydat=data[i];
				var Title = mydat['Titre'];
				if(mydat['DatePriseVue']!='') Title+='\nPrise le : '+mydat['DatePriseVue'];
				html='<div class="photos" rev="'+mydat['ID']+'">';
				html+='<a href="photos/'+mydat['Photo']+'_G.jpg" title="'+Title+'" style="text-decoration:none" class="albox" rel="myGallery" target="_blank">';
				html+='<img src="photos/'+mydat['Photo']+'_V.jpg" alt="'+mydat['Titre']+'" border="0" onload="updateLoad(this)" /><br />';
				html+='<strong>'+mydat['Titre']+'</strong>';
				html+='</a>';
				html+='</div>';
				$("#ContentPhoto").append(html);
			}
			var title = $( $("#Cat"+CatID+" > a")[0] ).html();
      $("#TitleCat > strong").html(title);

		preloadStart=0;
			if( !load ){ 
        if(ADMIN){ 
          $(".adminCheck").remove();
        	$("div.photos").each(function(){
        	  var el = $(this), ID = el.attr('rev');
			  el.append('<div class="adminCheck AdminZone"><label for="check'+ID+'">&nbsp;</label><span><input type="checkbox" id="check'+ID+'" class="delete" name="Photo[]" value="'+ID+'" /></span></div>');
        	});
      	}
        startBox();
        if(ADMIN && !MODEADMIN){ 
          SwitchMode2(); 
          SwitchMode2(); 
        }
      }
      
      if( $("#Cat"+CatID).is('.souscat') ) $(".AddGalerie").hide();
      else $(".AddGalerie").show();
      
			if(data.length==0 && load ){
			  $("#ContentPhoto").html('<div id="NoPhotoInCat" align="center">Aucune photo dans cette album...</div><br class="clear" />');
				animateText('LoadBarPourcent',75,100,1000,'','%'); 
			}
			var arianne = e.arianne;
			$("#MyArianne").html(arianne);
			
			if( isVignette ){ isVignette=false; switchVignette(); }
			
			if(ADMIN){
  			$("#ContentPhoto").sortable({
          placeholder : 'sortable-highlight',
          start: startMovePhoto,
          stop: stopMovePhoto,
          delay: 150
        });
      }
			
	});
	
};
function startMovePhoto(e,f){

  clearTimeout(dragTimer); clearTimeout(dragTimer2);
  var el = $( f.item[0] ); el.addClass('moving'); currentCheck = el.find('input').is(':checked')
  var margin = el.css('margin-right'), margin2 = el.css('margin-left'), height = el.css('height');
  $("#ContentPhoto .sortable-highlight").css({'margin-right':margin,'margin-left':margin, height:height})
  .html('<div class="bord" style="height:'+(Number(height.substring(0,height.length-2))-10)+'px">&nbsp;</div>');
  
};
function stopMovePhoto(e,f){

  var el = $( f.item[0] ); dragTimer2=setTimeout(function(){ el.removeClass('moving').find('input').attr('checked',currentCheck); },1); 
  var List = new Array(); $("div.photos").each(function(){ List[List.length] = $(this).attr('rev'); }); List = List.join("|");
  var myCat=CatID; dragTimer = setTimeout(function(){ $.post('ax.reorder.php',{CatID:myCat, List:List}); },5000);
  
};
function Menu(){

  var el=$(this), ID = el.attr('rel'), resp=true;
  if(CatID==ID) var resp = confirm("Vous êtes actuellement sur cette categorie.. Souhaitez-vous la recharger ?");
  if(resp){ 
    CatID = ID;
    reloadCat();
    $("#MenuLeft li").removeClass('select');
    el.parent().addClass('select');
  }
  return false;
    	
};
function reloadCat(){
  var url = window.location.href;
  var pos = url.indexOf('#');
  if( pos>0 ) url=url.substring(0,pos);
  window.location.href = url+"#"+CatID;
  waitList=0;
  currentLoad=0;
  startLoad=false;
  CurrentPourcent=0; 
  $("#LoadBar2").css({width:'0px'});
  $("#LoadBarPourcent").html('0%');
  $("#LoadBarElem").html('');
  getContentPage();
};

/* récupération des photos */
/* récupération des photos */
/* récupération des photos */