(function(){var h= document.getElementsByTagName('html')[0]; h.className = h.className.replace('no-js','js');})();

$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

$(document).ready(function () {

    var $jumpNav = $('.jump-nav');
    var imgArray = new Array();

    $jumpNav.find('li').each(function () {
        imgArray.push($(this).data('big-image'));
    });

    $(imgArray).preload();

    /* jumpnav stuff*/
    $jumpNav.find('li').css({ backgroundPosition: "0px 0px" });
    $jumpNav.find('li:first-child').addClass('active').css({ paddingTop: '10px', backgroundPosition: '0px -80px', color: '#ffffff' });
    $jumpNav.find('li').mouseenter(
		function () {
		    var $me = $(this), $img = $('#headerBackground');
		    if (!$me.hasClass('active')) {
		        $me.toggleClass('active').stop().animate({ paddingTop: '10px', backgroundPosition: '0px -80px', color: '#ffffff' }, 250);
		        $me.siblings('li').toggleClass('active').stop().animate({ paddingTop: '0px', backgroundPosition: '0px 0px', color: '#000000' }, 250);
		        $img.fadeOut(250, function () {
		            $img.attr('src', $me.data('big-image'));
		            $img.fadeIn(250);
		        });
		    }
		});

    /* contact form stuff*/

    // style stuff
    $('#contactForm').find('input').each(function () {
        var $me = $(this);
        if ($me.is('[type=checkbox]')) {
            var extraCheck = false;
            if ($me.parent('#requestList').size() > 0)
                extraCheck = true;
            $me.addClass('enabled');
            var $next = $me.next('label');
            if (this.checked) {
                $next.addClass('checked');
                if (extraCheck)
                    $('#atLeastOne').attr('checked', true);
            }
            $next.addClass('enabled').click(function () {
                var $check = $(this);
                if ($check.hasClass('checked')) {
                    $check.removeClass('checked');
                }
                else
                { $check.addClass('checked'); }
            });
            $next.hover(function () { $(this).addClass('hover'); }, function () { $(this).removeClass('hover'); });
        }
        else if ($me.is(':text')) {
            if (!$.support.leadingWhitespace) {
                $me.focus(function () { $(this).addClass('focused'); });
                $me.blur(function () { $(this).removeClass('focused'); });
            }
        }
    });

    $('#requestList').find('input:not([id="atLeastOne"])').each(function () {
        var $one = $('#atLeastOne'), $me = $(this);

        $me.change(function () {
            if ($me.prop("checked")) {
                $one.prop("checked", true);
                $('#requestList').find('label[for="atLeastOne"]').hide();
            }
            else {
                if (!$me.siblings('input:not([id="atLeastOne"]):checked').size() > 0) {
                    $one.prop("checked", false);
                    $('#requestList').find('label[for="atLeastOne"]').show();
                }
            }
        });

    });
});
