$(document).ready(function() {
	
	$(".subnav").parent().find("a:first").wrap("<span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
  
    $(".topnav li span").mouseover(function() { //When trigger is rolled over...  
  
        //Following events are applied to the subnav itself (moving subnav up and down)  
        $(this).parent().find(".subnav").show(); //Drop down the subnav on click 
		
        $('#indicator').hide();
  
        $(this).parent().hover(function() {  
        }, function(){
			$('#indicator').show();
            $(this).parent().find(".subnav").hide(); //When the mouse hovers out of the subnav, move it back up  
        });  
  
        //Following events are applied to the trigger (Hover events for the trigger)  
        }).hover(function() {
            $(this).addClass("subhover"); //On hover over, add class "subhover"  
        }, function(){  //On Hover Out  
            $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });
	
	$("#search-box").css( "cursor", "pointer" );
	$("#search-box").click( function() {
		window.location = "/about-us/SearchForm?Search=" + $("#Search").val() + "&action_results=Go";
	}).find( '.text' ).click( function( event ) { event.stopPropagation(); window.event.cancelBubble = true; return false; } );
	
		
	// home panel setup
	$("div.homepanel").each( function() {
		$(this).wrap('<div class="dialog"><div class="bd">'+
		'<div class="c"><div class="s"></div></div></div></div>');
	});
	
	$('div.dialog').each( function() {
		$(this).prepend('<div class="hd">'+
			'<div class="c"></div></div>')
		.append('<div class="ft">'+
			'<div class="c"></div></div>');
	
		$(this).css('background', 'bottom left no-repeat url('+$(this).find('div.homepanel').attr('img')+')');
	});
	
	$('a.pdf-link').each( function() {
		$(this).wrap('<span class="pdf-block"></span>');
	});

	$('.homepanel').each( function() {
		var rel = $(this).attr('rel');
		$(this).parent().parent().click( function() {
			window.location = rel;
			return false;
		});
	});

	$('#Search').keypress( function(e) {
		if (e.keyCode == 13) {
			window.location = "/about-us/SearchForm?Search=" + $(this).val() + "&action_results=Go";
		}
	});
});
