//ő
function icPager(divid,itemwidth,input_loop){
	var width=itemwidth;
	var timer=null; 
	var speed=4000;
	var current=1;
	var anim_run=false;
	var anim_timer=null;
	var anim_current_step=0;
	var anim_speed=100;
	var anim_steps=[30,60,80,90,94,98,99,99.6,100];
	var anim_steps_anim=new Array();
	var anim_loop=input_loop;
	var divname=divid;
	var pages=document.getElementById(divname).offsetWidth/itemwidth;

	function stop(){
	 	clearTimeout(timer);
	};

	function pager_switch(x){
		if(current!=x){
			if(anim_run==false){
				anim_start(x);
				current=x;
			}
		}
	};
	
	function pager_next(){
		if(current==pages){
			if(anim_loop==true){
				current=1;
				document.getElementById(divname).style.left=0;
				pager_switch(2);
			} else {
				pager_switch(1);
			}
		}
		else pager_switch(current+1);
	};
	
	function previos(){
		if(current==1)pager_switch(pages);
		else pager_switch(current-1);
	};
	
	
	function anim_start(x){
		anim_run=true;
		clearTimeout(timer);
		clearTimeout(anim_timer);
		
		//poziciok
		honnan=(current-1)*width;
		hova=(x-1)*width;
		tavolsag=Math.abs(honnan-hova);
		anim_steps_anim=new Array();
		for(i=0;i<anim_steps.length;i++){
			if(current<x)anim_steps_anim[i]=-(honnan+Math.round(tavolsag*(anim_steps[i]/100)));
			else anim_steps_anim[i]=-(honnan-Math.round(tavolsag*(anim_steps[i]/100)));
		}
	
	/*	
		alert(honnan+' x '+hova+' x '+tavolsag);
		alert(anim_steps_anim);
	*/
	 	anim_timer=setTimeout(anim_stepping,anim_speed);
	};
	
	function anim_stop(){
		anim_run=false;
		anim_current_step=0;
		clearTimeout(anim_timer);
		pager_start();
	};
	
	function anim_stepping(){
		if(anim_current_step==anim_steps.length){
			anim_stop();
		} else {
			clearTimeout(anim_timer);
			document.getElementById(divname).style.left=anim_steps_anim[anim_current_step]+'px';
			anim_current_step++;
		 	anim_timer=setTimeout(anim_stepping,anim_speed);
		}
	};
	
	function pager_start(){
		if(anim_run==false){
			clearTimeout(timer);
		 	timer=setTimeout(pager_next,speed);
		}
    };

	pager_start();
}

