﻿function cufonFun() {
    Cufon.replace(['#top-nav ul li a:not(#top-nav ul li ul li a)'], { hover: true });
    Cufon.replace(['#header a.contact-arrow']);
}

function homeCoolness() {
    if ($("#chained").length > 0) {
        var api = $("#chained").scrollable({ size: 1, speed: 0, clickable:false }).circular().navigator({ navi: '#navigator ul' }).autoscroll({ api: true, interval:5000 }); ;

        var totalPages = api.getPageAmount();
        var randomPageIndex = Math.floor(Math.random() * totalPages);
        var firstTime = true;

        api.onSeek(function() {
            if (firstTime) {
                this.getConf().speed = 400;
                firstTime = false;
            }
        });
        
        api.setPage(randomPageIndex);
    }
}

function overlayMe() {
    if ($("button.modalInput").length > 0) {
        var triggers = $("button.modalInput").overlay({

            // some expose tweaks suitable for modal dialogs 
            expose: {
                color: '#333',
                loadSpeed: 200,
                opacity: 0.9
            },

            closeOnClick: false
        });

        $("#prompt btnEnquire").submit(function(e) {

            // close the overlay 
            triggers.eq(1).overlay().close();

            // get user input 
            var input = $("input", this).val();

            // do something with the answer 
            triggers.eq(1).html(input);

            // do not submit the form 
            return e.preventDefault();
        });
    }
}

function hideModals() {
    $(".modal").hide();
    $(".modal .close").show();
}

$(document).ready(function() {
    hideModals();
    cufonFun();
    overlayMe();
    homeCoolness();
});