//~ $(function(){
	//~ $("#s .shadow").fadeTo(0, .85);
//~ 
	//~ $total_images=$("#s .panel").size()-2;
	//~ $current_image=1;
	//~ $("#s").css({ width:(($total_images+2)*1000)+"px"})
//~ 
	//~ $(".left-arrow").click(function(e){
		//~ e.preventDefault();
		//~ if($current_image>1)
		//~ {
			//~ $current_image--;
			//~ gotoImage($current_image);
		//~ }
	//~ });
//~ 
	//~ $(".right-arrow").click(function(e){
		//~ e.preventDefault();
		//~ if($current_image<$total_images)
		//~ {
			//~ $current_image++;
			//~ gotoImage($current_image);
		//~ }
	//~ });
//~ 
	//~ $("#slider").mouseenter(function(){
		//~ clearInterval($auto);
	//~ }).mouseleave(setAutoImage);
	//~ 
	//~ checkImageArrows();
	//~ setAutoImage()
//~ })
//~ 
//~ function setAutoImage()
//~ {
	//~ $auto=setInterval("gotoAutoImage()", 4000);
//~ }
//~ 
//~ function gotoAutoImage()
//~ {
	//~ if($current_image==$total_images)
	//~ {
		//~ $current_image=0;
		//~ $(".right-arrow").trigger("click");
	//~ }
	//~ else
	//~ {
		//~ if($current_image<$total_images)
			//~ $(".right-arrow").trigger("click");
	//~ }
//~ }
//~ 
//~ function gotoImage(i)
//~ {
	//~ $(".overlay-index").stop(true, true).animate({ bottom: 0 }, "normal");
	//~ $("#s .shadow").stop(true, true).fadeTo("normal", .85);
	//~ $("#s").stop(true, true).animate({ marginLeft:(-i*1000-500)+"px" }, checkImageArrows);
//~ }
//~ 
//~ function checkImageArrows()
//~ {
	//~ $current=$("#s .panel:eq("+($current_image)+")")
	//~ $current.addClass("active").find(".shadow").fadeTo("normal", 0);
	//~ $current.find(".overlay-index").stop(true, true).animate({ bottom: $current.find(".overlay-index").height() }, "normal");
//~ 
	//~ $(".right-arrow").fadeIn("normal");
	//~ $(".left-arrow").fadeIn("normal");
//~ 
	//~ if($current_image==$total_images)
		//~ $(".right-arrow").stop(true, true).fadeOut("normal");
//~ 
	//~ if($current_image==1)
		//~ $(".left-arrow").stop(true, true).fadeOut("normal");
//~ }


///////////////////////////////////////////////////////

function setAutoImage()
{
	$auto=setInterval("gotoAutoImage()", 4000);
}

function gotoAutoImage()
{
    $(".right-arrow").trigger("click");
}
function hideShadowShowDescr()
{
    $('#s>div.active').removeClass('active');
    
    $current=$("#s .panel:eq(2)");
    $current.addClass("active").find(".shadow").fadeTo("normal", 0);
    $current.find(".overlay-index").stop(true, true).animate({ bottom: $current.find(".overlay-index").height() }, "normal");
}
function moveMainScroller( direction )
{
         $(".overlay-index").stop(true, true).animate({ bottom: 0 }, "normal");
         $("#s .shadow").stop(true, true).fadeTo("normal", .85);
     
     if(direction=='right')
     {
        //$('#s>div:eq(2)').find(".shadow").css('opacity', 0.85);
        
        $('#s').stop(true, true).animate({"margin-left":"-3500px"}, "normal", function(){
                $firstElem = $('#s>div:eq(1)');
                
                $firstElem.insertBefore($('#s>div:last'));
                $('#s').css('margin-left', '-2500px');
               // console.log($('#s>div:last').prev().index()+"||"+$('#s>div:last').index()+"||");
            hideShadowShowDescr();
        });   
     }
     else if(direction=='left')
     {
        $lastElem = $('#s>div:last').prev();
        //
        
        $lastElem.insertAfter($('#s>div:first'));
        
        
        $('#s').css('margin-left', "-3500px");
        //$('#s>div:eq(1)').find(".shadow").css('opacity', 0.85);
        $('#s').stop(true, true).animate({"margin-left":"-2500px"}, "normal", function(){
            
            hideShadowShowDescr();
        });
        
     }
}
 

$(function(){
    $('#s>div').each(function(index, elem){
        //console.log( index );
        $(this).addClass('el'+index);
    })
    
	$("#s").css({ width:(($("#s .panel").size())*1000)+"px"})
    
    
    $("#s .shadow").fadeTo(0, .85);
  
    $(".left-arrow").click(function(e){
        e.preventDefault();
        moveMainScroller('left');
    });
    
    $(".right-arrow").click(function(e){
		e.preventDefault();
		moveMainScroller('right');
	});
    
    $current=$("#s .panel.active");
	$current.find(".shadow").fadeTo("normal", 0);
	$current.find(".overlay-index").stop(true, true).animate({ bottom: $current.find(".overlay-index").height() }, "normal");

	$(".right-arrow").fadeIn("normal");
	$(".left-arrow").fadeIn("normal");

    
    $("#slider").mouseenter(function(){
		clearInterval($auto);
	}).mouseleave(setAutoImage);
})

