$(document).ready(function () {

    // initialize scrollable
    $("#new-items-container div.scrollable").scrollable({
        size: 1,
        items: '#new-items',
        hoverClass: 'hover'
    });
    $("#news-items-container div.scrollable").scrollable({
        size: 1,
        items: '#news-items',
        hoverClass: 'hover'
    });
    $("#exclusive-items-container div.scrollable").scrollable({
        size: 1,
        items: '#exclusive-items',
        hoverClass: 'hover'
    });
    if(($('.book-image-item').length>3))
    {
        $("#book-images-container div.scrollable").scrollable({
            size: 3,
            items: '#book-images',
            hoverClass: 'hover'
        });
        $('#book-images-container .next').show('slow');
        $('#book-images-container .prev').show('slow');
    }


    //        grayscale( $('.process-item img') );
    //        $('.process-item').hover(function(){grayscale.reset(this)},function(){grayscale(this)});


    $(".lb").lightbox({
        fitToScreen: true
    });
    $("ul.tabs").tabs("div.panes > div.service-description", {effect: 'slide' });
//    $("ul.process-list li a").before("<span>"+jQuery(this).attr('href')+"</span>");
    $("ul.process-list").tabs("div.panes > div.process-item", {effect: 'fade'}).history();
    //TODO: Tooltip!
    //$.ajax({
    //   type: "GET",
    //   cache: true,
    //   url: url+'?jax=1',
    //   success: function(msg){
    //     $('#JT_copy').html(msg);
    //     $('#JT').show();
    //
    //   }
    // });

    //         $('.page').hover(function () {
    //
    //        this.tooltip({
    //                position:  	['top', 'center'],
    //                tip: '#tooltipp'
    //            })
    //
    //        });


    //    $('.page').hover(function(){$(".pagination").append("<span id='tooltipp2'>Hello</span>")}).tooltip({
    //        position:  	['top', 'center'],
    //        tip: '#tooltipp'
    //
    //    })

    if($('#book-listing-all').length > 0)
    {
        var z = new Array('found');
        $('#local-search-form').hide();
        $('#book-listing-all .catalogue-item').quicksearch({
            position: 'append',
            attached: '#local-search',
            loaderText: 'Ищем…',
            labelText: '<p>'+$('#enter-author-text').text()+'</p>'
        });
    };

    //$(".search-form :input")


    $('.search-form').submit(function () {
        if($('#s').val().length>2) {
            location.href=this.action+'search/'+encodeURIComponent(this.s.value).replace(/%20/g, '+');
        }
        else {
            //                alert('Запрос должен содержать не меньше 3 символов');
            $('#s').after('<div class="tooltip">Введите имя автора или название книги. Не меньше 3 символов</div>');
            $('#s').tooltip({
                position: ['bottom', 'center'],
                //                    offset: [-2, 10],
                effect: 'toggle',
                opacity: 0.7
            });
            $('#s').focus();
        };
        return false;
    })

    if($('#YMapsID').length>0) {
        var map = new YMaps.Map(document.getElementById("YMapsID"));
        map.setCenter(new YMaps.GeoPoint(37.669217,55.74257), 14, YMaps.MapType.MAP);
        map.addControl(new YMaps.Zoom());
        map.addControl(new YMaps.ToolBar());
        map.addControl(new YMaps.TypeControl());
        var s = new YMaps.Style();
        s.iconStyle = new YMaps.IconStyle();
        s.iconStyle.offset = new YMaps.Point(-8,-27);
        s.iconStyle.href = "/static/i/map.png";
        s.iconStyle.size = new YMaps.Point(28,29);
        YMaps.Styles.add("wizard#lbmPoint", s);


        var placemark1 = new YMaps.Placemark(new YMaps.GeoPoint(37.671795,55.740649), {
            style: "wizard#lbmPoint",
            balloonOptions: {
                maxWidth: 350
            }
        });
        map.addOverlay(placemark1);
        placemark1.setBalloonContent("<img src='/static/i/logo.png' style='float: left; margin-right: 20px' /> <div style='font-family: georgia,serif; font-weight: bold; margin: 0 0 5px'><div style='font-size: 11px'>Творческая мастерская «Ламартис»</div><div style='font: 11px tahoma,sans-serif; color: #777'>Большая Андроньевская, д. 23</div>");
    }

});
