jQuery.noConflict();

function form_input_classes(){
    jQuery('input[type="text"]').addClass('text');
    jQuery('input[type="email"]').addClass('text');
    jQuery('input[type="tel"]').addClass('text');
    jQuery('input[type="password"]').addClass('text');
    jQuery('input[type="checkbox"]').addClass('checkbox');
    jQuery('input[type="radio"]').addClass('radiobutton');
    jQuery('input[type="submit"]').addClass('submit');
    jQuery('input[type="image"]').addClass('buttonImage');
}

function superfish(){
    jQuery('ul.superfish').superfish({ 
        delay:       500,                            // delay on mouseout 
        dropShadows: false,
        autoArrows:  false
    });
}
function mobile_nav(){
    jQuery("#nav-wrap").css('display', 'none');
    jQuery("#skip").click(function () {
        if ( !jQuery('#nav-wrap').is(':animated') ) {
            jQuery("#nav-wrap").toggle();
            return false;
        }
    });
}
function mobile_subnav(){
    jQuery("#page-header span").click(function () {
        if ( !jQuery('#page-header + nav.nav-list').is(':animated') ) {
            jQuery("#page-header").toggleClass('subnav-open');
            jQuery("#page-header + nav.nav-list").toggle();
            jQuery("#page-header.subnav-open span").html("&#x25B4;");
            jQuery("#page-header:not(.subnav-open) span").html("&#x25BE;");
            return false;
        }
    });
}
function form_labelize(){  jQuery(".labelize input:text").clearingInput(); }   

function media_queries() {

    enquire.register("screen and (max-width: 959px)", {
        match : function() {
            jQuery('#main').append(jQuery('.basics-side'));
            jQuery('#main').append(jQuery('#landing-side-touts'));
            jQuery('nav.nav-list a').addClass('right ss-directright ss-standard');
            jQuery('.interior footer nav.nav-list').clone().css('display', 'none').insertAfter(jQuery('h1#page-header'));
            jQuery('.apply-prev').each(function() {
                var title = jQuery(this).attr("title");
                var href = jQuery(this).attr("href");
                jQuery(this).after('<a href="' + href + '" class="apply-nav-label">' + title + '</a>');
            });
            jQuery('.apply-next').each(function() {
                var title = jQuery(this).attr("title");
                var href = jQuery(this).attr("href");
                jQuery(this).after('<a href="' + href + '" class="apply-nav-label">' + title + '</a>');
            });
        },

        unmatch : function() {
            jQuery('aside').append(jQuery('.basics-side'));
            jQuery('aside').append(jQuery('#landing-side-touts'));
            jQuery('nav.nav-list a').removeClass('right ss-directright ss-standard');
            jQuery('h1#page-header+nav.nav-list').remove();
            jQuery('.apply-nav-label').remove();
        }
    }).register("screen and (max-width: 721px)", {
        match : function() {
            jQuery('table.responsive td').each(function() {
                var th = jQuery(this).closest('table').find('th').eq( this.cellIndex ).html();
                if (th != null) {
                    jQuery(this).prepend('<span>' + th + '</span>');
                }
            });
        },

        unmatch : function() {
            jQuery('table.responsive td span:first-child').remove();
        }
    }).register("screen and (max-width: 563px)", {
        match : function() {
            jQuery('.apply-nav-label').hide();
            jQuery('#main-nav').hide().delay(20).queue( function() { 
                jQuery(this).show();
                jQuery(this).dequeue();
            } ); // fix chrome bug by forcing repaint

        },

        unmatch : function() {jQuery('.apply-nav-label').show();}
    }).listen(50);  

}

jQuery(document).ready(function() {
    form_input_classes();
//ipad and iphone fix -- a bit hacky. Switch to Modernizr or mdetect?
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    jQuery("#main-nav ul").remove();
} else {superfish();}
    media_queries();
    jQuery("#main").fitVids();
    /* hide nav on mobile at first except on homepage */
    if (jQuery("#home").length == 0) {mobile_nav();}
    mobile_subnav();
});