var ani_count = 0;

var slide_width = 157;

var to_point = 0;


$(document).ready(function() {

    // Стартуем слайдшоу на главной

    $('#slide_win').cycle({
        fx:    'fade',
       // sync:   0,
        speed: 1000,
        delay: 0,
        timeout: 3000
//            next:   '#slideshow_next',
//            prev:   '#slideshow_prev',
//            pause:   1//,
/*            before: function(curr, next, opts) {
            opts.animOut.opacity = 0;
        }*/
    });

    // Стартуем фото скрол на главной

    ani_count = $('#in_scroll .scroll_item').length;

    $('#in_scroll').width(ani_count*(slide_width));
    $('#scroll_win').width(6*slide_width - 2);

    $('#scroll_prev').click(function () { anim(-1); return false; });
    $('#scroll_next').click(function () { anim(1); return false; });
    anim(0);

});

function anim(shifter) {
    var tp = to_point + shifter;

    if (tp <= 0) {
        tp = 0;
        $('#scroll_prev').hide();
    } else {
        $('#scroll_prev').show();
    }
    if (tp >= ani_count-6) {
        tp = ani_count-6;
        $('#scroll_next').hide();
    } else {
        $('#scroll_next').show();
    }

    to_point = tp;
    
    var npoz = -tp*slide_width;

    $('#in_scroll').stop();
    var po = parseInt($('#in_scroll').css('margin-left').split('px')[0]);

//    alert(to_point+'  '+po+'  '+npoz)

    if (po != npoz) {
//        var tot = npoz-po;
        $('#in_scroll').animate({
            marginLeft: npoz
        }, 500);

    }

}



