var _auto=new auto_play();


function auto_play(){
	this.n;
	this.wait;
	this.run=false;
	this.wrap;
}

auto_play.prototype.ini=function(){
	$clear(this.wait);
	var ob=menu[menu.act];
	this.n=0;
	var w=$(ob.typ).getElement('.bd .wrap').getElements('.im')[ob.act];
	this.wrap=w.getElement('.wrap');
	
	if(this.wrap){
		this.wait=this._auto.periodical(4000,this);
		var phs=this.wrap.getElements('.ph');
		if((ob.typ=='shop' && phs.length==1) || (ob.typ!='shop' && !phs.length))this._auto.delay(1000,this);
	}
}

auto_play.prototype._auto = function(){
	if(this.n<this.wrap.els.length){
		this.wrap.move('right');
		this.n++;
	}else{
		$clear(this.wait);
	}
}

auto_play.prototype._reset = function(){
	$clear(this.wait);
}



function ldOb(ob,imgs,typ,item,ph){
    this.ob=ob;
    this.imgs=imgs;
    this.typ=typ;
    this.item=item;
    this.ph=ph;
    this.ld();
}


ldOb.prototype.ld=function(){
	var _lds = new Asset.images(this.imgs, {
	  'onComplete': function(){
		var ims=$(this.ob.typ).getElement('.bd .wrap').getElements('.im');
		_lds.each(function(img,n){
		    if(this.typ=='h'){
			  var cl=((this.ph[n].hasClass('l'))? 'l' : ((this.ph[n].hasClass('r'))? 'r':'' ));
			  img.replaces(this.ph[n]);
			  if(cl)img.addClass(cl);
		    }else{
			  switch(this.ob.typ){
				case 'about':
				case 'news':
				case 'proj':
				  img.addClass(((n)?'r' : 'l'));
				case 'shop':
				case 'prod':
				  img.replaces(ims[((this.typ=='1st')? this.ob.vLd : _ini.n)].getElement('.ph'));
				break;    
			  }
		    }
		    if(this.typ=='h' || this.typ=='1st'){
			  switch(this.ob.typ){
				case 'about':
				    
				    if(this.item.data.typ=='a_proj' && this.item.data.sub[((this.typ=='1st')? 0 : this.item._ld)]){
					  var r=((this.typ=='1st')?  this.item.data.sub[0].imgs[n]: this.item.data.sub[this.item._ld].imgs[n]);
					  if(r.l_src){
						var src={'src':path+'/media/a_proj/'+r.l_src,'w':r.l_src_w,'h':r.l_src_h}
						setZoom(img,src);
					  }
				    }    
				break;
				case 'news':
				    var p;
				    var l=((this.typ=='1st')? 0 : this.item._ld);
				    for(var i=0; i<2; i++){
					
					  p=((i)? n-(this.item.data.news[(l*2)].imgs.length) : n);
					  if(this.item.data.news[(l*2)+i]){
					  if(this.item.data.news[(l*2)+i].imgs[p]){
						var r=this.item.data.news[(l*2)+i].imgs[p];
						if(r.l_src){
						    var src={'src':path+'/media/news/'+r.l_src,'w':r.l_src_w,'h':r.l_src_h};
						    setZoom(img,src);
						}
					  }
					}
				    }
				break;
				case 'proj':
				    var r=((this.typ=='1st')?  this.item.data.imgs[(n%2)]: this.item.data.imgs[(this.item._ld*2)+(n%2)]);
				    if(r.l_src){
					  var src={'src':path+'/media/'+this.ob.typ+'/'+r.l_src,'w':r.l_src_w,'h':r.l_src_h}
					 setZoom(img,src);
				   }
				break;
				case 'prod':
				var r=((this.typ=='1st')?  this.item.data.imgs[0]: this.item.data.imgs[(this.item._ld)]);
				if(r.l_src){
				     var src={'src':path+'/media/'+this.ob.typ+'/'+r.l_src,'w':r.l_src_w,'h':r.l_src_h}
				    setZoom(img,src);
				}
				break;	
			  }
		    }
		    
		}.bind(this));
		switch(this.typ){
		    case '1st':
			  this.ob.vLd++;
			  vLd_1st();//item._ld++; ???
		    break;
		    case 'h':
			  this.item._ld++;
			  if(this.item==menu[menu.act].els[menu[menu.act].act]){
				cont_fillPh();
			  }
		    break;
		    case '0':
			 show1st(); 
		    break;	  
		}
	  }.bind(this)
    });
	
}
