// JavaScript Document
var ArtronRimage ={
	NowIndex:1,
	ImageData:['1.jpg','2.jpg','3.jpg'],
	Doing:false,
	C:null,
	Up:function()
	{
		ArtronRimage.Over();
		ArtronRimage.Out();
		if (ArtronRimage.Doing==true)
		{
			return ;
		}
		ArtronRimage.Doing=true;
		var NewLeft = ArtronRimage.GetNewLeft("up");
        $("#R_S").animate({
            left:NewLeft
        }, 600, "", function(){
			var NewIndex = ArtronRimage.NowIndex+1;
			if (NewIndex > ArtronRimage.ImageData.length )
			{
				NewIndex =1;
			}
			ArtronRimage.RandDiv(NewIndex,"up");
        });
	},
	Down:function()
	{
		if (ArtronRimage.Doing==true)
		{
			return ;
		}
		ArtronRimage.Doing= true;
		var NewLeft = ArtronRimage.GetNewLeft("down");
        $("#R_S").animate({
            left:NewLeft
        }, 600, "", function(){
			var NewIndex = ArtronRimage.NowIndex-1;
			if (NewIndex <=0 )
			{
				NewIndex = ArtronRimage.ImageData.length;
			}
			ArtronRimage.RandDiv(NewIndex,"down");
        });
    },
	RandDiv:function(Index,Type)
	{
		
		if (Index== ArtronRimage.ImageData.length)
		{
			var Left = ArtronRimage.ImageData.length* 840 ;
			document.getElementById("R_S").style.left="-"+Left+"px";
		}
		if (Index==1)
		{
			document.getElementById("R_S").style.left="-840px"
		}
		ArtronRimage.Doing=false;
		ArtronRimage.NowIndex=Index;
		
	},
	GetNewLeft:function(Type)
	{
		var LeftValue  = $("#R_S")[0].style.left;
		LeftValue = LeftValue.replace("px","");
		LeftValue=parseInt(LeftValue)
		if (Type=="up")
		{
			LeftValue=LeftValue-840;
		}
		else
		{
			LeftValue=LeftValue+840;
		}
		return LeftValue+"px";
	},
	Over:function(){
		if (ArtronRimage.C!=null)
		{
			window.clearInterval(ArtronRimage.C);
			ArtronRimage.C =null;
		}
	},
	Out:function(){
		if (ArtronRimage.C ==null)
		{
				ArtronRimage.C = window.setInterval(function(){
					ArtronRimage.Up();					   
				},4000)
		}

	}
}
$(document).ready(function(){
	ArtronRimage.C = window.setInterval(function(){
		ArtronRimage.Up();					   
	},4000)
});
