function Gallery(blockid){
    this.blockid = blockid;
    this.photos = new Array();
    this.path = "";
    this.count = 0;
    this.page = 0;
    this.next = 1;
    this.prev = 2;
}
 actionsGalery=0;
Gallery.prototype.draw = function(back){
    
    var html = "";
       
        Post('/index/galery',{page:this.page},function(json)
        {  
           Gallery.prototype.photos=json;
           html += 
    '<table cellpadding="0" cellspacing="0">\
    <tr>\
        <td colspan="5" class="photoBig"><div id="galleryPhotoBig" style="background: url('+json[0]['max']+') center no-repeat;">&nbsp;</div></td>\
    </tr>\
    <tr>\
        <td class="left" onclick="gallery.go(gallery.prev);" title="Предыдущая">&nbsp;</td>\
        <td class="photoMin"><div style="background: url('+json[0]['min']+') center no-repeat;" onclick="gallery.selectPhoto(0)">&nbsp;</div></td>\
        <td class="photoMin"><div style="background: url('+json[1]['min']+') center no-repeat;" onclick="gallery.selectPhoto(1)">&nbsp;</div></td>\
        <td class="photoMin"><div style="background: url('+json[2]['min']+') center no-repeat;" onclick="gallery.selectPhoto(2)">&nbsp;</div></td>\
        <td class="right" onclick="gallery.go(gallery.next);" title="Следующая">&nbsp;</td>\
    </tr>\
    </table>';        
            window.document.getElementById('galleryCB').innerHTML = html;

        },'json');    
    
    
};
Gallery.prototype.selectPhoto = function(id){
    
    window.document.getElementById("galleryPhotoBig").style.background =' url('+Gallery.prototype.photos[id]['max']+') center no-repeat';
};
Gallery.prototype.go =  function(type){
    if(type==1){
        
        this.page++;    
        this.draw();       
        return;
    }
    if(this.page > 0){
            this.page--;
            this.draw(1);
    }
};
Gallery.prototype.showPageFoto=function(id){
    
    if(id < 0)
        var foto=ThisPhotoArray[ThisPhotoActive];
    else
        var foto=ThisPhotoArray[id];
    var n=foto.split('+',3);
    window.document.getElementById('imgForNews').src=n[0];
    window.document.getElementById('nameThisFoto').innerHTML=n[1];
    window.document.getElementById('urlForPage').value="/photo/show/id/"+n[2];
    
    SocialData(n[0],n[1]);
    window.scroll(0,0); 
};
Gallery.prototype.showashki=function(){
    document.getElementById("sterl1").style.display = 'inline-block';
    document.getElementById("sterl2").style.display = 'inline-block';
};
Gallery.prototype.hideashki=function(){
   document.getElementById("sterl1").style.display = 'none';
   document.getElementById("sterl2").style.display = 'none';
};
Gallery.prototype.rotatestr=function(pages){
    
    if(pages=='left')
    {
        if(ThisPhotoActive==0)
           ThisPhotoActive=(ThisPhotoCount-1);
        else
           ThisPhotoActive=ThisPhotoActive-1;
    }
    else
    {
        if(ThisPhotoActive==(ThisPhotoCount-1))
           ThisPhotoActive=0;
        else
           ThisPhotoActive=ThisPhotoActive+1;
    }   
    Gallery.prototype.showPageFoto(ThisPhotoActive);
};
Gallery.prototype.Paging=function(){
    if(actionsGalery==0)
    {
        actionsGalery=1;
        ThisPhotoPage=ThisPhotoPage+1;
        var search=window.document.getElementById('search').value;
        Post('/photo/pages',{page:ThisPhotoPage,id:thisCat,search:search},function(json)
            { 
              var n=json['data'].length;
              if(n>0)
              {
                   var html = "";
                   for(var i=0;i<n;i++)
                  {
                      var newId=ThisPhotoCount+i;
                      ThisPhotoArray[newId]=json['fotoParh']+'imgshow.php?src='+json['data'][i]['foto_path']+'&object=foto&model=default+'+json['data'][i]['name']+'+'+json['data'][i]['id'];
                      html +='<div  class="div_podl">\
           <img  onClick="gallery.showPageFoto('+newId+');" class="image"  src="'+json['fotoParh']+'imgshow.php?src='+json['data'][i]['foto_path']+'&model=sml&object=foto" />\
           <span class="litle_car">'+json['data'][i]['name']+'</span>\
       </div> '; 

                  }
                  html+='<div class="clear"></div>';
                  ThisPhotoCount=ThisPhotoCount+n;
                  window.document.getElementById('photoBlock').innerHTML+= html;
                  if(json['nextPage']==0)
                    window.document.getElementById('morePhoto').style.display='none'; 
                
                 actionsGalery=0;
              }
              else
                  window.document.getElementById('morePhoto').style.display='none'; 


            },'json');
    }
    
    
};
Gallery.prototype.puchCat=function()
{
    for(var a=0;a<catArray.length;a++)
    {
        window.document.getElementById('cat_'+catArray[a]+'_in').style.display='none';
    }
}
Gallery.prototype.showCategory=function(id){
    
    var htmlId=window.document.getElementById('cat_'+id+'_in').innerHTML;
    
    
    if(getElementComputedStyle('cat_'+id+'_in', 'display')==='none')
    {
        Gallery.prototype.puchCat();
        if(htmlId=='')
        {
            if(actionsGalery==0)
            {
                actionsGalery=1;
                Post('/photo/categories',{id:id},function(json){
                   var ss=json.length;
                  // alert(ss);
                   if(ss>0)
                   {
                      var html = "";
                      for(var i=0;i<ss;i++) 
                      {
                         html +='<a class="model" href="/photo/index/category/'+json[i]['id']+'">'+json[i]['name']+'</a>'; 
                      }
                      window.document.getElementById('cat_'+id+'_in').innerHTML=html;
                      window.document.getElementById('cat_'+id+'_in').style.display='block';
                      actionsGalery=0;
                   }
                },'json');
            }    
        }
        else
            window.document.getElementById('cat_'+id+'_in').style.display='block';
    }
    else
        window.document.getElementById('cat_'+id+'_in').style.display='none';
    
};

Gallery.prototype.showCategoryPager=function(id){ 
    
       
            if(actionsGalery==0)
            {
                
                pageCat=pageCat+1;
                actionsGalery=1;
                Post('/photo/categoriespager',{page:pageCat},function(json){
                   var ss=json['data'].length;
                  
                   if(ss>0)
                   {
                      var html = "";
                      for(var i=0;i<ss;i++) 
                      {
                         html +='<div class="MainCar">\
                            <img class="LogoCar" src="http://img.gai.ua/models/'+str_replace(' ','',json['data'][i]['name'])+'.jpg">\
                            </div>\
                            <a id="'+json['data'][i]['id']+'" class="SubCar" onclick="gallery.showCategory(this.id);" href="javascript:void(0);">'+json['data'][i]['name']+'</a>\
                            <div class="clear"></div>\
                            <div id="cat_'+json['data'][i]['id']+'_in" style="display: none;"></div>'; 
                            catArray[catArray.length]=json['data'][i]['id'];
                      }
                      
                      window.document.getElementById('photoCategorys').innerHTML+= html;
                      if(json['nextPage']==0)
                        window.document.getElementById('moreCat').style.display='none'; 
                      
                      actionsGalery=0;
                   }
                   else
                       window.document.getElementById('moreCat').style.display='none'; 
                },'json');
            }    
        
   
    
};


var gallery = new Gallery("galleryCB");
