
function mkGallery(hand,data){
   this.dom = {};
   this.img = [];
   this.count = 0;
   this.actual = -1;
   this.temp = [];
   this.btn = [];
   this.init(hand,data);
}
mkGallery.prototype = {
   init : function(hand, data){
      
      this.dom.shell = DIV({'class':'gShell'});
      var img = IMG({src:URL+'img/gBorder.gif',alt:'border'});
      this.dom.shell.appendChild(img);
      this.dom.count = DIV({'class':'gCount'});
      this.dom.shell.appendChild(this.dom.count);
      var div = DIV({'class':'gNav'});
      this.dom.nav = DIV({'class':'gNavCont'});
      
      div.appendChild(this.dom.nav);
      div.appendChild(DIV({'style':'clear:both'}));
      
      hand.appendChild(this.dom.shell);
      hand.appendChild(div);
      for(var i = 0;i < data.length;i++){
         data[i] = URL+data[i];
         this.temp[i] = document.createElement('IMG');
         this.img[i] = data[i];
         this.addImgButton(i);
	 addEvent(this.temp[i],'load',this.addImg.bind(this,i));
		 
         this.temp[i].src = data[i];
	 
      }
      
      
      //this.dom.nav.style.width = 30*this.img.length +'px';  
   },

   addImg:function(nr){
      this.count++;
      this.setCount(0);
      //var div = DIV();
      //this.dom.nav.appendChild(div);
      //this.btn[nr] = div;
      if(nr == 0){
         this.showImg(0);
      }
	  this.btn[nr].style.display = 'block';
      //addEvent(div,'click',this.showImg.bind(this,nr));
     // addEvent(div,'mouseover',this.showImg.bind(this,nr));
      //addEvent(div,'mouseover',this.btnOver.bind(this,nr));
     // addEvent(div,'mouseout',this.btnOut.bind(this,nr));

   },
   addImgButton:function(nr){
      //this.count++;
      //this.setCount(0);
      var div = DIV();
      this.dom.nav.appendChild(div);
      this.btn[nr] = div;
      //if(nr == 0){
     //    this.showImg(0);
     // }
      //addEvent(div,'click',this.loadData.bind(this,nr));
      addEvent(div,'mouseover',this.showImg.bind(this,nr));
      //addEvent(div,'mouseover',this.btnOver.bind(this,nr));
      addEvent(div,'mouseout',this.btnOut.bind(this,nr));
	  div.style.display = 'none';
   },
	loadData:function(nr) {
	   	path = this.img[nr];
	   	location.href = URL+'order?path='+path;
		//alert(nr);
	},
   btnOver:function(nr){
      this.btn[nr].style.borderColor = '#ED962E';
   },
   btnOut:function(nr){
      if(nr != this.actual)
      this.btn[nr].style.borderColor = '#fff';
   },
   showImg:function(nr){
      this.btnOver(nr);

      var t = this.actual;
      this.actual = nr;
      this.btnOver(nr);
      this.btnOut(t);
      this.setCount(nr);
      var url="url('"+ this.img[nr] +"')";
      
      goGet('getDescr.php?img='+this.img[nr], 'gDescr');
      this.dom.shell.style.backgroundImage = '';
      this.dom.shell.style.backgroundImage = url;
      this.dom.shell.style.backgroundPosition = '5px 5px';
      //addEvent(this.dom.shell,'click',this.loadData.bind(this,nr));
   },

   setCount:function(act){
      this.actual = act;
      act++;
      this.dom.count.innerHTML =  act+'/'+ this.count;
   }
};
addEvent(window,'load',function(){
   var hands = getChildren(document,'className','galleryCont');
   for(var i = 0;i< hands.length;i++){		      
      new mkGallery(hands[i],FILES[i]);
   }
});
