﻿function cufonMe() {
    //Cufon Replacement
    Cufon.replace('#top-nav ul li a', { hover: true });
    Cufon.replace('#home-left h2');
    Cufon.replace('ul.tabs li a', { hover: true });
    //Cufon.replace('.pagination-wrap ul li.previous');
    Cufon.replace('.pagination-wrap ul li.previous a');
    //Cufon.replace('.pagination-wrap ul li.next');
    Cufon.replace('.pagination-wrap ul li.next a');
    //Cufon.replace('.pagination-wrap ul li.showall');
    Cufon.replace('.pagination-wrap ul li.showall a');
    Cufon.replace('.pagination-wrap p.resultsTotals');
}

$(document).ready(function() {
    //Hide Overlays
    $("#buy-overlay").hide();
    $("#bookmark-overlay").hide();

    // setup ul.tabs to work as tabs for each div directly under div.panes
    $("ul.tabs").tabs("div.panes > div");

    //Buy Overlay
    $(".btn-buy-this-book").tooltip({ tip: '#buy-overlay', position: 'bottom center', offset: [-25, 90],
        events: {
            def: "mouseover, mouseout",                    // default show/hide events for an element
            input: "focus,blur",                        // for all input elements
            widget: "focus mouseover,blur mouseout",    // select, checkbox, radio, button
            tooltip: "mouseover,click mouseout"            // the tooltip element
        }
    });

    //Bookmark Overlay
    $(".btn-add-to-shelf").tooltip({ tip: '#bookmark-overlay', position: 'bottom center', offset: [-25, 90],
        events: {
            def: "mouseover, mouseout",                    // default show/hide events for an element
            input: "focus,blur",                        // for all input elements
            widget: "focus mouseover,blur mouseout",    // select, checkbox, radio, button
            tooltip: "mouseover,click mouseout"            // the tooltip element
        }
    });

    if ($("div.scrollable").length > 0) {
        var api = $("div.scrollable").scrollable({ size: 1, loop: true, clickable: false }).autoscroll({ autopause: true, interval: 5000, api: true });

        if ($(".youTubePlayer").length > 0)
            $("div.scrollable .item-wrap .youTubePlayer:not(.item-wrap:nth(0) .youTubePlayer)").hide();

        if ($(".flash").length > 0)
            $("div.scrollable .item-wrap .flash:not(.item-wrap:nth(0) .flash)").hide();


        api.onBeforeSeek(function() {
            if ($(".youTubePlayer").length > 0)
                $("div.scrollable .item-wrap:nth(" + this.getPageIndex() + ") .youTubePlayer").hide();
            if ($(".flash").length > 0)
                $("div.scrollable .item-wrap:nth(" + this.getPageIndex() + ") .flash").hide();
            cufonMe();
        });

        api.onSeek(function() {
            if ($(".youTubePlayer").length > 0)
                $("div.scrollable .item-wrap:nth(" + this.getPageIndex() + ") .youTubePlayer").show();
            if ($(".flash").length > 0)
                $("div.scrollable .item-wrap:nth(" + this.getPageIndex() + ") .flash").show();
        });
    }

});