var mevcut, toplam, baslat;
$(document).ready(function(){
    toplam = Math.ceil( ( $( '.ref_slide' ).length ) / 3 );
	mevcut = 0;
    
    $('.rs_navbut').click(function(event){
        event.preventDefault();
        clearInterval( baslat );
        
        var yeni_mevcut = $(this).attr('data-sayfa') - 2;
        if( yeni_mevcut < mevcut ) {
            mevcut = $(this).attr('data-sayfa');
            kaydir( false );
        } else {
            mevcut = $(this).attr('data-sayfa') - 2;
            kaydir();
        }
    });
    
    $('#rs_prev').click(function(event){
        event.preventDefault();
        clearInterval( baslat );
        
        kaydir(false);
    });
    
    $('#rs_next').click(function(event){
        event.preventDefault();
        clearInterval( baslat );
        
        kaydir();
    });
    
    as_toplam = $( '.as_content' ).length;
	as_mevcut = 0;
	as_baslat = setInterval( 'as_kaydir()', 4000 );
});

function kaydir( arttir ) {
    if( arttir == false ) {
        if( ( mevcut - 1 ) < 0 ) {
			mevcut = toplam - 1;
		} else if( mevcut < 0 ) { 
            mevcut = toplam - 1;
        } else {
			mevcut--;
		}
    } else {
		if( ( mevcut + 1 ) == toplam ) {
			mevcut = 0;
		} else if( mevcut < 0 ) { 
            mevcut = toplam - 1;
        } else {
			mevcut++;
		}
    }
    
    $('.active').removeClass('active');
    $('.rs_navbut').eq(mevcut).addClass('active');
	
	$('#rs_contents').animate( { marginLeft: '-'+ ( mevcut * 945 ) +'px' }, 1500 );
}

function as_kaydir( arttir ) {
    if( ( as_mevcut + 1 ) == as_toplam ) {
		as_mevcut = 0;
	} else {
		as_mevcut++;
	}

	$('#as_contents').animate( { marginLeft: '-'+ ( as_mevcut * 951 ) +'px' }, 1500 );
}
