	//PARAMS
	var obj_width=300;
	var min_margin=5;
	//sys
	var ttl_objs=false;
	var display_objs=false;
	var r_margin=0;
	var area=997;
	var cur_obj=1;
	var speed_pics=.2, base_pics=0, base_digits=0;
	var pics_obj=false, digits_obj=0, digits_pos=0;
	var digits_set=false;
	var inited=false;
	//timers
	var int_pics=false;
	
	function move_pics(){
		if(!pics_obj) pics_obj=document.getElementById('mover');
		if(!digits_obj) digits_obj=document.getElementById('digits_front');
		base_pics=parseInt(pics_obj.style.left.replace('px',''));
		var m_x=( -1 ) * (cur_obj-1) * ( obj_width+r_margin );
		
		digits_pos+=((20*(cur_obj-1))-digits_pos)*speed_pics;
		var dtt=digits_pos+display_objs*20;
		document.getElementById('digits_front').style.clip="rect(0px, "+dtt+"px, 24px,"+digits_pos+"px)";
		
		var dx=( m_x - base_pics ) * speed_pics;
		base_pics = parseInt(base_pics) + parseInt(dx);
		pics_obj.style.left = base_pics + 'px';
		if( Math.abs(dx) < 1 ){
			pics_obj.style.left = m_x + 'px';
			clearInterval(int_pics);
			int_pics=false;
			set_scroll();
		}
	}
	
	function move_to(to){
		if(to=='left'){
			cur_obj-=display_objs;
			if(cur_obj<1)cur_obj=1;
		}else if(to=='right'){
			cur_obj+=display_objs;
			if( cur_obj > ttl_objs-display_objs+1 ) cur_obj=ttl_objs-display_objs+1;
		}
		clearInterval(int_pics); int_pics=setInterval('move_pics()', 50);
	}
	
	function set_objects(objs){
		//DETECT other PARAMS
		//вычисляю остаток 75*2(px) + 15(%) + 10*5(px)
		area=document.body.clientWidth-40;
		//detect need margin
		if(!objs) display_objs=parseInt(area/(obj_width+min_margin));
		else display_objs=objs;
		var qtt=display_objs;
		if(objs==undefined) r_margin= (area-(obj_width*qtt))/(qtt-1);
		else r_margin=min_margin;
		var i=1;
		var obj=document.getElementById('d'+i);
		while(obj!=undefined){
			obj.style.position='absolute';
			obj.style.top='0px';
			obj.style.left=(i-1)*(obj_width+r_margin)+'px';
			i++;
			obj=document.getElementById('d'+i);
		}
		i--;
		if(i<display_objs) {set_objects(i); return true; }
		if(!ttl_objs) ttl_objs=i;
		//Поправляю тек объект, если справа дыра
		if((ttl_objs-cur_obj+1)<display_objs) cur_obj=(ttl_objs-display_objs+1);
		clearInterval(int_pics); int_pics=setInterval('move_pics()', 50);
		set_scroll();
		inited=true;
	}
	
	function set_scroll(){
		//Если нет необходимомти в скроле
		if(ttl_objs==display_objs){ document.getElementById('scroller').style.display='none'; return true;}
		else document.getElementById('scroller').style.display='';
		//Left arrow
		if(cur_obj==1)
				document.getElementById('s_l_arrow').innerHTML=document.getElementById('l_arrow').innerHTML;
		else	document.getElementById('s_l_arrow').innerHTML=document.getElementById('l_arrow_link').innerHTML;
		if(cur_obj==ttl_objs-display_objs+1)
				document.getElementById('s_r_arrow').innerHTML=document.getElementById('r_arrow').innerHTML;
		else	document.getElementById('s_r_arrow').innerHTML=document.getElementById('r_arrow_link').innerHTML;
		//Digits
		if(!digits_set){
			var db='', df='';
			for(var i=1; i<=ttl_objs; i++){
				db+=document.getElementById('digit_back').innerHTML.replace('{digit}',i);
				df+=document.getElementById('digit_front').innerHTML.replace('{digit}',i);
			}
			document.getElementById('digits_back').innerHTML=db;
			document.getElementById('digits_front').innerHTML=df;
			document.getElementById('digits_front').style.clip="rect(0px, "+display_objs*20+"px, 24px, 0px)";
			digits_set=true;
		}
		
	}

//---------------------------

	//SIZES
	var imgSizes={};
	var dSpeed=0.2;
	var dTimer=10;
	var dEM=.075;
	var maxEM=1.25;
	//SYS
	//var dWidth=1;
	//var dHeight=1;
	var imagesPath=new Array();
	var pimg=new Array();
	var sysTimer=false;
	var allLoaded=false;
	var process=false;
	var objCache=new Array();
	
	function objGo(num,a){
		if( objCache[ 'img_'+num ]==undefined){
			objCache[ 'img_'+num ]=document.getElementById('img_'+num);
			objCache[ 'img_'+num ].fsz=1;
			objCache[ 'img_'+num ].dscr=document.getElementById('dscr_'+num);
		}
		objCache[ 'img_'+num ].way=a?1:-1;
		if(!process) objResizes();
	}
	
	function objResizes(){
		if(!allLoaded) return;
		process=false;
		for(var i in objCache){
			if(objCache[ i ].way>0){
				var dw=Math.ceil((imgSizes.wb-objCache[ i ].width)*dSpeed);
				var dh=Math.ceil((imgSizes.hb-objCache[ i ].height)*dSpeed);
			}else if(objCache[ i ].way<0){
				var dw=Math.ceil((objCache[ i ].width-imgSizes.ws)*dSpeed);
				var dh=Math.ceil((objCache[ i ].height-imgSizes.hs)*dSpeed);
			}
			var h=parseInt(objCache[ i ].height), w=parseInt(objCache[ i ].width);
			objCache[ i ].width	=	w +objCache[ i ].way*dw;
			objCache[ i ].height=	h +objCache[ i ].way*dh;
			
			//objCache[ i ].fsz+=objCache[ i ].way*dEM;
			//if(objCache[ i ].fsz<1)objCache[ i ].fsz=1;
			//objCache[ i ].dscr.style.fontSize=objCache[ i ].fsz+'em';
			objCache[ i ].dscr.style.fontSize=((objCache[ i ].way>0)?maxEM:1)+'em';
			
			if(Math.ceil(imgSizes.wb-objCache[ i ].width)	<=1) 	objCache[ i ].width=imgSizes.wb;
			if(Math.ceil(objCache[ i ].width-imgSizes.ws)	<=1)	objCache[ i ].width=imgSizes.ws;
			if(Math.ceil(objCache[ i ].height-imgSizes.hs)	<=1)	objCache[ i ].height=imgSizes.hs;
			if(Math.ceil(imgSizes.hb-objCache[ i ].height)	<=1)	objCache[ i ].height=imgSizes.hb;

			if(objCache[ i ].width==imgSizes.wb && objCache[ i ].height==imgSizes.hb)	objCache[ i ].src=imagesPath[i][1];
			if(objCache[ i ].width==imgSizes.ws && objCache[ i ].height==imgSizes.hs)	objCache[ i ].src=imagesPath[i][0];
			var enlg=(objCache[ i ].way>0 && (objCache[ i ].width<imgSizes.wb || objCache[ i ].height<imgSizes.hb));
			var ensm=(objCache[ i ].way<0 && (objCache[ i ].width>imgSizes.ws || objCache[ i ].height>imgSizes.hs));
			process+=(enlg || ensm);
		}
		if(process){
			clearTimeout(sysTimer);
			sysTimer=setTimeout('objResizes()',dTimer);
		}
	}
	
	
	//INIT (Preloader func, detect dSize)
	function initMistery(){
		allLoaded=true;	for(var i=0,cnt=pimg.length; i<cnt; i++) allLoaded*=pimg[i].complete;
		clearTimeout(sysTimer);
		if(allLoaded){
			//find sizes
			imgSizes.ws = document.getElementById('img_'+1).width;
			imgSizes.hs = document.getElementById('img_'+1).height;
			imgSizes.wb = pimg[0].width;
			imgSizes.hb = pimg[0].height;
//debug(imgSizes.wb+'X'+imgSizes.hb+' '+imgSizes.ws+'X'+imgSizes.hs);
			//detect DSIZEs
			//dWidth=Math.ceil((imgSizes.wb-imgSizes.ws)/dSteps);
			//dHeight=Math.ceil((imgSizes.hb-imgSizes.hs)/dSteps);
//print_r(imgSizes);
//debug('BASE: width:'+imgSizes.ws+' height:'+imgSizes.hs);
		}else{
			sysTimer=setTimeout('initMistery()',500);
		}
	}
	//Makes preload queue
	function preloadIMG(imgpath){
		var img=new Image();
		img.src=imgpath;
		pimg.push(img);
	}
	
	function debug(txt){
		if(!this.dbg) this.dbg=document.getElementById('debug');
		this.dbg.innerHTML='<br>'+txt+this.dbg.innerHTML;
	}
