// remap jQuery to $
(function($){})(window.jQuery);


/* trigger when page is ready */
$(document).ready(function (){

	
	/* Contact Form UX enhancements */
	/*------------------------------*/
	
	// Set focus on the first name field
    $("#Name").focus().addClass('focus').siblings('label').addClass('focus');

    // Highlight active input
    $('form input, form select, form textarea, form input').bind("focus", function () {
        var field = $(this);
        field.addClass('focus').siblings('label').addClass('focus');
    }).bind("blur", function () {
       $('.focus').removeClass('focus');
    });
   
    // Display the Other box if the user selects other for their referral source
    $("#Found").bind("click", function () {
        var field = $(this);
        if (field.val() == "Other" || field.val() == "Referral") {
            $('#FoundNote').removeClass('hidden').show('fast').addClass('visible').addClass('focus').siblings('label').addClass('focus');
            $('#FoundNote').focus().addClass('focus');
        } else {
            $('#FoundNote').hide('fast').removeClass('visible');
        }
    });

    // Home page slide show
    $(".slidetabs").tabs(".home-image > div", {
        // enable "cross-fading" effect
        effect: 'fade',
        /*fadeOutSpeed: "slow",
        fadeInSpeed: "slow",*/
        fadeOutSpeed: 1000,
        fadeInSpeed: 2500,
        rotate: true       
        }).slideshow({autoplay: true,interval: 5000});

    // Home page slide show
    /*$(".slidetabs").tabs(".gallery > div", {
        // enable "cross-fading" effect
        effect: 'fade',
        
        fadeOutSpeed: 1000,
        fadeInSpeed: 2500,
        rotate: true       
        }).slideshow({autoplay: false});
    */
    // Gallery slidesh
    $('.gallery').scrollable();
    var oldImageHeight = 0;
    var api = $('.gallery').data("scrollable");
    if(api != null) 
{

    api.onSeek(function(){
        // inside callbacks the "this" variable is a reference to the API
        //console.info("current position is: " + this.getIndex() + " of " +  $('.gallery .items div').length);
        // Set the counter
        $('.gallery-count').html("Image " + (this.getIndex()+1) + " of " +  $('.gallery .items img').length);
        // Set the caption below the image
        $('.gallery-caption').html($('.image-desc:eq(' + this.getIndex() +')').html());

        // There are vertically and horizontally oriented images which have different heights. Based on this we need to move the y position of the .gallery-caption which is set to float above the image with absolute positioning because the gallery REQUIRES a set height to work with JQT
        // Get the height of the current image
        var currentImageHeight = $('.gallery img:eq(' + this.getIndex() +')').innerHeight();
        if (currentImageHeight!=oldImageHeight)
        {
            oldImageHeight = currentImageHeight;
            // Get the position of the image
            imageY = $('.gallery img:eq(' + this.getIndex() +')').position().top 
            $('.image-caption').css('top',imageY + currentImageHeight + 12);
        }

    });
}
});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/
