var line_w = 0;
var img_w = 759; // 145
var line_w = total*img_w;
var l_s = 0;
var timer1 = null;
var speed = 300;

$(window).load(function () {
    $('#c_line').css('width', line_w);
});
$(document).keydown(function(e){
    if (e.which == 37) slide('l');
    if (e.which == 39) slide('r');
});

function slide(d){
    var l = $('#c_line').css('left').split('px');
    var left = parseInt(l[0]);

    if (total <= 1) return false;
    active(d);
    if ( !(left*(-1)%img_w) ){
        if (d == 'l'){
            if (left < 0)
                $('#c_line').animate({
                    left: left+img_w+"px"
                }, speed);
            else if(left == 0){
                $('#c_line').css('left', '-'+(line_w-img_w)+'px')
                slide('l');
            }
        }else if(d == 'r'){
            
            if (((left*(-1)) < (line_w-img_w)))
                $('#c_line').animate({
                    left: left-img_w+"px"
                }, speed);
            else if (left == -(line_w-img_w)){
                $('#c_line').css('left', '0px')
                slide('r');
            }
        }
    }

    return false;
}

function active(d){
    var left = 0;
    if (d != 'l') left = '-57';
    $('#'+d+'_but').css('backgroundPosition', left+'px -57px');
    timer1 = setTimeout('unactive("'+d+'");', speed);
}

function unactive(d){
    $('#'+d+'_but').attr('style', '');
}
