/**
 * Created by IntelliJ IDEA.
 * User: admitriev
 * Date: 01.07.2011
 * Time: 13:32:37
 * To change this template use File | Settings | File Templates.
 */
(function($) {
    $(document).ready(function() {
        if (document.getElementById('paginator')) {
            $('#paginator').paginator();
        }

        $("table.head_menu td").mouseenter(function(){
            $(this).find(".pop").each(function() {
              $this = $(this);
              $this.show();
              if ($(window).width() - ($this.offset().left + $this.width()) < 0){
                $this.css("left", "auto").css("right", 0);
              }                  
            });
        });
        $("table.head_menu td").mouseleave(function(){
            $(this).find(".pop").hide();
        });

        $(".prog input:radio").change(function(){
                $(".std").toggle();
                $(".add").toggle();
        });
        
        $('.center .main_photo div').height($('.center .left').height() - 2 + 'px');
        $('.center .right').height($('.center .left').height() - 2 + 'px');

        $('a.lightbox').lightBox();
    });

    $.fn.paginator = function() {
        var wrapper = $('.pages-wrapper', this), pad = $('.pages-pad', this);
        var maxMargin = wrapper.width() - pad.width();
        var timer;
        function setMargin(newMargin) {
            pad.css('margin-left', Math.min(Math.max(newMargin, maxMargin), 0) + 'px');
        }
        function scrollStart() {
            scrollStop();
            var delta = $(this).attr('id') == 'page-prev' ? +4 : -4;
            timer = setInterval(function() {
                setMargin(parseInt(pad.css('margin-left')) + delta);
            }, 15);
        }
        function scrollStop() {
            if (timer) { clearTimeout(timer); timer = undefined; }
        }
        $('#page-prev, #page-next', this).mouseover(scrollStart).mouseout(scrollStop);
        setMargin(pad.position().left - $('.disabled', pad).position().left + wrapper.width() / 2);
    };
})(jQuery);

