$(document).ready(function(){
    
    // Navigation and Subnavigation
	$("ul.subnav").parent().append("<span></span>");

	$("ul.topnav li span").click(function() {

		$(this).parent().find("ul.subnav").show();

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").hide();
		});

		}).hover(function() {
			$(this).addClass("subhover_active");
		}, function(){
			$(this).removeClass("subhover_active");
	});
	
	$("ul.topnav li").mouseover(function() {
	    $(this).find("span").addClass("subhover");
    }).mouseout(function(){
        $(this).find("span").removeClass("subhover");
    });
    
    // If needed, increase the sidebar height so left border extends to bottom of main div
    var main_div_height = $("#main").height();
    if ( $("#sidebar").height() < main_div_height ) {
        $("#sidebar").height( main_div_height );
    }
    
    // Modal Contact Form
    $('a.contact-a').addClass('gated-asset');
    gated = $('a.gated-asset');
    gated.attr('target','_blank');
    for (var i=0; i<gated.length; i++) {
        var a = $(gated[i]);
        a.attr('href', a.attr('href') + '?modal');
    }

    // Contact popup settings
    gated.nyroModal({
        height:680, 
        autoSizable: true,
        showBackground: function(elts, settings, callback) { callback();},
        showContent: function(elts, settings, callback) {
            elts.bg.css({opacity:0.75}).show();
            elts.loading
                .css({
                    opacity: 0,
                    width: settings.width+'px',
                    height: settings.height+'px',
                    marginTop: settings.marginTop+'px',
                    marginLeft: settings.marginLeft+'px'
                })
                .show()
                .animate({
                    opacity: 1
                }, {duration: 350, complete: function() {
                    elts.contentWrapper
                        .css({
                            width: settings.width+'px',
                            height: settings.height+'px',
                            marginTop: settings.marginTop+'px',
                            marginLeft: settings.marginLeft+'px'
                        })
                        .show();
                        elts.loading.fadeOut(200, callback);
                    }
                });
            },
        hideContent: function(elts, settings, callback) {
            elts.contentWrapper
                .animate({
                    opacity: 0
                }, {duration: 150, complete: function() {
                    elts.contentWrapper.hide();
                    callback();
                }});
        }
    });

});

