if (typeof DD_roundies.addRule == 'function') {
    DD_roundies.addRule('#globalnav li.selected a', '10px');
    DD_roundies.addRule('#globalnav li ul li', '10px');
    DD_roundies.addRule('#globalnav li ul li a', '10px');
}

$(document).ready(function () {
    // Disable hashed hyperlinks
    $("a[href='#']").click(function (e) {
        e.preventDefault();
    });


    // Fancybox
    $(".gallery a").fancybox();


    // Login: Default input value hinting
    $("#login input[type=text]").focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            return $(this).val("");
        } else {
            $(this).select();
        };
    });

    $("#login input[type=text]").blur(function () {
        if ($(this).val() == "") {
            return $(this).val($(this).attr('title'));
        }
    });

    $("#login input[type=password]").focus(function () {
        $(this).val("");
    });


    // Faux pointer
    $("#services, #case-studies").css("cursor", "pointer");


    // Cycle: Banner
    $("#banner > div.fader").cycle({
        timeout: 1,
        continuous: 1,
        speed: 10000,
        sync: 0
    });


    var speed = 200;
    var opacity = 0.15;

    // Cycle: Services
    $("#banner > div.content").cycle({
        timeout: 0,
        cleartype: 1,
        pager: '#localnav ul',
        pagerClick: function () {
            $("#banner .fader").fadeTo(speed, opacity);
            $("#banner .content").fadeTo(speed, 1);
        },
        pagerAnchorBuilder: function (idx, slide) {
            var id = $(slide).attr('id').split('-')[1];
            return "#localnav li#page-" + id + " a";
        },
        fastOnEvent: 1
    });

    $("#localnav li a:not([href^=#])").click(function () {
        window.location.href = $(this).attr("href");
    });

    $("#localnav a").click(function () {
        $("#banner").fadeTo(speed, 1);
        $("#banner .content").fadeTo(speed, 1);
        $("#popup").fadeTo(speed, 0);
    });

    $("#container").mouseleave(function () {
        $("#banner").fadeTo(speed, 1);
        $("#banner .fader").fadeTo(speed, 1);
        $("#banner .content").fadeTo(speed, 0);
        $("#popup .content").cycle(0);
    });

    $("table#services tr").each(function (index) {
        $(this).children().each(function (subindex) {
            $(this).children().each(function () {
                if ($(this).is(':not([href])')) {
                    $(this).click(function () {
                        $("#banner > div").cycle(subindex);
                        $("#banner .fader").fadeTo(speed, opacity);
                        $("#banner .content").fadeTo(speed, 1);
                    });
                }
            });
        });
    });


    // Cycle: Case Studies
    $("#popup .content").cycle({
        timeout: 0,
        speed: speed,
        cleartype: 1
    });

    $("table#case-studies tr").each(function (index) {
        $(this).children().each(function (subindex) {
            $(this).children().each(function () {
                if ($(this).is(':not([href])')) {
                    $(this).click(function () {
                        $("#popup").fadeTo(speed, 1);
                        $("#popup .content").cycle(subindex + 1);
                        $("#banner").fadeTo(speed, 0);
                    });
                }
            });
        });
    });
});

