﻿/* ------------------------------------------------------------
FADETOGGLE PLUGIN
- Adds native support, just like slideToggle()
------------------------------------------------------------ */

jQuery.fn.fadeToggle = function (speed, easing, callback) {
    return this.animate({ opacity: 'toggle' }, speed, easing, callback);
};

/* ------------------------------------------------------------
INITIALIZATION FUNCTION
- Sets up all the code that runs on page load
------------------------------------------------------------ */

$.init = function () {

    $.plugins();

    $('#page .form')
        .find('.input')
		.first()
		.find('input')
        .first()
        .css('border-color', '#434c58')
		.focus();

    $('#page .form')
        .find('div.submit input')
        .removeAttr('disabled');
}

/* ------------------------------------------------------------
PLUGINS
- Sets up each of the plugins
------------------------------------------------------------ */

$.plugins = function () {

    // Validate plugin
    $('.validate-form').validate({
        submitHandler: function (form) {
            $(form).find('div.submit input').attr('disabled', 'disabled');
            form.submit();
        }
    });

    // Slider plugin
    /*$('#mainSlider').bxSlider({
        auto: true,
        controls: false,
        mode: 'fade'
    });*/
}

/* ------------------------------------------------------------
 MAIN DOCUMENT READY FUNCTION
 - All the miscellaneous JS...
------------------------------------------------------------ */

$(function () {
    $.init();

    // Menu Hover //
    $('ul.topnav li').hover(function () {
        $(this).find("ul.subnav").slideDown('fast').show();
        $(this).children('a').addClass("subhover");
    }, function () {
        $(this).find("ul.subnav").slideUp('fast', function () { $(this).hide() });
        $(this).children('a').removeClass("subhover");
    });

    // Input Fields //
    $('.form form .input input, .form form .input textarea').focus(function () {
        $(this).css('border-color', '#434c58');
    }).blur(function () {
        $(this).css('border-color', '#b2bdcc');
    });

    // clickables //
    $('.clickable').hover(function () {
        $(this).addClass('clickableHover');
    }, function () {
        $(this).removeClass('clickableHover');
    });
    $('.clickable').click(function () {
        window.location.href = $(this).attr('id');
    });

    // sevice hovers //
    $('div.serviceGroup div.serviceItem').hover(function (event) {
        $(this).addClass('hovered');
        $(this).children('ul').css('left', (event.pageX + 30) + 'px')
                              .css('top', (event.pageY - 5) + 'px')
                              .show();
        $(this).bind('mousemove', function (event) {
            $(this).children('ul').css('left', (event.pageX + 30) + 'px')
                                  .css('top', (event.pageY - 5) + 'px');
        });
    }, function () {
        $(this).removeClass('hovered');
        $(this).children('ul').hide();
        $(this).unbind('mousemove');
    });
});
