
//form to send forgotten email password
var forgotEmail = '<div id=\"alertforgotpassword\" class=\"form login\">\n                       <div>\n                          <input id=\"forgot-email\" type=\"text\" \/>\n                          <label for=\"forgot-email\">Email Address:<\/label>\n                          <p id=\"forgot-message\"><\/p>\n                        <\/div>\n                        <div class=\"submit\">\n                            <input type=\"submit\" class=\"forgot-submit\" value=\"SUBMIT\" \/>\n                        <\/div>\n                <\/div>';

$(document).ready(function () {

    //implement jQuery hint on the following forms
    hint(".hint .text");

    //Navigation
    $('#nav').superfish({
        pathClass: 'active'
    });

    //Cufon - font replacement
    Cufon.replace('#content h1');

    if ($('#caption ul').length > 0) {

        $('#caption ul').jcarousel({
            start: 1,
            scroll: 1,
            visible: 6,
            wrap: 'circular',
            buttonPrevHTML: '<div class=\'prev\'><a href=\'#\'>prev</a></div>',
            buttonNextHTML: '<div class=\'next\'><a href=\'#\'>next</a></div>',
            itemVisibleInCallback: VisibleInCallback
        });

        //hide carousel if less than 6 images
        if ($('#caption ul li').length <= 6) {
            $('.jcarousel-prev').hide();
            $('.jcarousel-next').hide();
            $('#caption .jcarousel-clip').css('left', '0');
        }
    }

    $('#caption ul.jcarousel-list li a').click(function () {
        //index item onClick
        $('ul.jcarousel-list li .active').removeClass('active');
        $(this).addClass('active');
        selectImage($(this));
        return false;
    });

    //meet the team (slide up/down) functionality
    $('a.view').click(function () {
        if ($(this).parent().next().length > 0 && $(this).attr('rel') == 'closed') {
            $(this).attr('rel', 'open');
            $(this).text('CLOSE');
            $(this).parent().addClass('visible');
            $(this).parent().next().slideDown('slow').addClass('extended');
        }
        else {
            $(this).attr('rel', 'closed');
            $(this).parent().next().slideUp('slow').removeClass('extended');
            $(this).parent().removeClass('visible');
            $(this).text('VIEW');
        }
        return false;
    });

    //handle tooltip popup on clients page
    if ($('.col-3 img').length > 0)
        $('.col-3 img').tooltip();


    //bind map to button (to show google map in lightbox window)
    if ($('#map-link').length > 0)
        $('#map-link').colorbox({ html: '<div id="map"></div>' });

    if ($('a.video-link').length > 0)
        $('a.video-link').colorbox({ iframe: true, innerWidth: 425, innerHeight: 344 });

});

$(window).load(function () {
    //make the clients divs equal height
    if ($('.col-3-container .col-3').length > 0)
        $('.col-3-container .col-3').equalHeight();

    //BEST practice - dynamically calculate padding for navigation based on li items
    var totalWidth = 0;
    var navWidth = $('#nav').outerWidth();
    var extraPadding = 0;
    $('#nav #best-practice-sub li').each(function () {
        totalWidth += 96; //width of li including margin
    });
    extraPadding = navWidth - (totalWidth - 17); //17 = last margin that is deducted
    $('#nav #best-practice-sub').css('padding-left', extraPadding + 'px');
});

//sets the main image from the carousel object thats parsed
function selectImage(obj) {
    $('#mainImage').attr('src', obj.attr('href'));
    $('#caption p').html(obj.attr('title'));
}

//tells us when the item is visible in the carousel
function VisibleInCallback(obj, ctrl, index, state) {

    if (state == 'next') {
        var nextItem = $('ul.jcarousel-list li .active').parent().next().children();
        $('ul.jcarousel-list li .active').removeClass('active');
        $(nextItem).addClass('active');
        selectImage(nextItem);
    }
    else if (state == 'prev') {
        var prevItem = $('ul.jcarousel-list li .active').parent().prev().children();
        $('ul.jcarousel-list li .active').removeClass('active');
        $(prevItem).addClass('active');
        selectImage(prevItem);
    }
}
