var counter = 0; 
var counter2 = 0;
var to;
var to2;
var count;
var count2;

function timer() {
        var element = $(".carousel .cright a:eq(" + counter + ")");
        var em;
        (function($) {
            if(counter==0) em = $(".carousel .cright a").eq(count-1);
            else em = $(element).prev();

            em.animate({left: "474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 700, "easeOutQuint" );
                if(counter == count) counter = 0;
                to = setTimeout("timer()",6000);    
            });
        })(jQuery)
        counter++;
}   
function timer2() {
        var element = $(".carousel .cleft a:eq(" + counter2 + ")");
        var em;
        (function($) {
            if(counter2==0) em = $(".carousel .cleft a").eq(count2-1);
            else em = $(element).prev();

            em.animate({left: "-474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 300, "easeOutQuint" );
                if(counter2 == count2) counter2 = 0;
                to2 = setTimeout("timer2()",6000);    
            });
        })(jQuery)
        counter2++;
}
function mtimerForward() {
        var element = $(".carousel .cright a:eq(" + counter + ")");
        var em;
        (function($) {
            if(counter==0) em = $(".carousel .cright a").eq(count-1);
            else em = $(element).prev();

            em.animate({left: "474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 700, "easeOutQuint" );
                if(counter == count) counter = 0;  
            });
        })(jQuery)
        counter++;
}
function mtimer2Forward() {
        var element = $(".carousel .cleft a:eq(" + counter2 + ")");
        var em;
        (function($) {
            if(counter2==0) em = $(".carousel .cleft a").eq(count2-1);
            else em = $(element).prev();

            em.animate({left: "-474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 300, "easeOutQuint" );
                if(counter2 == count2) counter2 = 0;   
            });
        })(jQuery)
        counter2++;
}
function mtimer() {
        if(counter == 0) var element = $(".carousel .cright a:eq(" + (count-1) + ")");
        else var element = $(".carousel .cright a:eq(" + (counter-1) + ")");
        var em;
        (function($) {
            em = $(".carousel .cright a").eq(counter);
            em.animate({left: "474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 700, "easeOutQuint" );  
            });
        })(jQuery)
}   
function mtimer2() {
        if(counter2 == 0) var element = $(".carousel .cleft a:eq(" + (count2-1) + ")");
        else var element = $(".carousel .cleft a:eq(" + (counter2-1) + ")");
        var em;
        (function($) {
            em = $(".carousel .cleft a").eq(counter2);
            em.animate({left: "-474px"}, 600, "easeInQuint", function() {
                $(element).animate({left: "0px"}, 300, "easeOutQuint" );  
            });
        })(jQuery)
}
(function($) {
$(document).ready(function () {
    count = $(".carousel .cright a").length;
    $(".carousel .cright a").eq(0).animate({left: "0px"}, 700, "easeOutQuint", function() {  
        timer();
    } );
    count2 = $(".carousel .cleft a").length;
    $(".carousel .cleft a").eq(0).animate({left: "0px"}, 700, "easeOutQuint", function() {   
        timer2();
    } );
    
    $(".cal").click(function() {
        clearTimeout(to);
        clearTimeout(to2);

        if($(".carousel a:animated").size() == 0) {   
            if(counter != 0) counter--;
            else counter = count-1;
            if(counter2 != 0) counter2--;
            else counter2 = count2-1;
            mtimer();
            mtimer2();
        }
    }); 
    $(".car").click(function() {
        clearTimeout(to);
        clearTimeout(to2);
        if($(".carousel a:animated").size() == 0) {  
            mtimerForward();
            mtimer2Forward();
        }
    });
});  
})(jQuery)
