var sliderPosition = +0;

var elementsCount = +0;
var action = false;

//var toggleAnimation = true;
var animationTimer;

var againStartTimer;

var msieFlag = false;

if ($.browser.msie&&$.browser.version<=7)
    msieFlag = true;


$(document.body).ready(function () {

	  
	  $(".wheel").fadeIn(1000);
	  $(".wheel").css("position","relative");
	  
	  elementsCount = $(".wheel > li").length;
	  
	  
	  //$(".wheel > div").eq(0).appendTo($(".wheel"));
	  //$(".wheel > div").eq(0).empty();
	  
        animationTimer = setInterval('elementMove(+1)',7000);
	  
	  //$(".wheel > *").eq(1).replaceWith($(".wheel > *:first").html()) ;
	  //var elementWidth = $(".element:first").width();
	  
	  //$(".wheel").css("left","-"+elementWidth*3+"px");
	  
	  //$(document.body).click(alert("123")); 

        $(".num a").click(moveOnClick);

		
	});
	
	function moveOnClick(){
		
            clearTimeout(animationTimer);
            clearTimeout(againStartTimer);
            againStartTimer = setTimeout(startAgain,10000);
            var dPosition=parseInt($(this).attr("rel"));
            if (isNaN(dPosition)) dPosition=1;
            elementMove (dPosition);
	}

    
	function startAgain(){
		animationTimer = setInterval('elementMove(+1)',4000);
	}
	
	 function elementMove (dPosition){
	  
		if (action) return;
		//if (isNull(dPosition)) alert("123123");		
		//$(".wheel").animate({left:sliderPosition*100+"px"}, 500);

		if (dPosition>0){
		     
			var elemWidth = $(".wheel > li:first").width()+24;
			action = true;
   $(".wheel > li:first").fadeOut(1000);
   $(".wheel > li:first").fadeIn(1);
			
			$(".other:first > li:last").fadeOut(1);    
			
			$(".other:first > li:last").appendTo($(".wheel"));
			
			
   $(".wheel > li:last").fadeIn(1000);			
			
			
			$(".wheel").animate({left:"-="+elemWidth+"px"}, {duration:1000,complete:function (){
				$(".wheel > li:first").prependTo($(".other:first"));
				$(".wheel").css("left","0");
				action = false;
			}});
			
			//$(".wheel > li").eq(0).appendTo($(".wheel"));
		
		} else {
		  
			action = true;
			
			$(".wheel > li:last").fadeOut(1000);
			$(".wheel > li:last").fadeIn(1);
			
			var elemWidth = $(".other:first > li:first").width()+24;
			
			
			$(".other:first > li:first").fadeOut(1);
			$(".other:first > li:first").prependTo($(".wheel"));
            $(".wheel").css("left","-"+elemWidth+"px");
            
			$(".wheel > li:first").fadeIn(1000);	
			
			
			
			$(".wheel").animate({left:"0"}, {duration:1000,complete:function (){
				$(".wheel > li:last").appendTo($(".other:first"));
				action = false;
			}});
			//$(".wheel > li").eq(elementsCount-1).prependTo($(".wheel"));
		
		}

	  }
      

