$(function(){
    
    /*
     * Pretty forms
     */
    $('form.prettyform input[type*=radio]').css('border','none');
    $('form.prettyform input[type*=checkbox]').css('border','none');
    if($.browser.mozilla) { prettyform(); }
    
    /*
     * LI hover fix for IE6
     */
    $('#navigation ul li').each( function(){
        $(this).mouseover( function(){ $(this).addClass('hover'); } ).mouseout( function(){ $(this).removeClass('hover'); } );
    });
    
    /*
     * Blur on focus
     */
    $('a').focus(function() { this.blur(); });
    $('input[type*=submit]').focus(function() { this.blur(); });
    $('input[type=text], input[type=password]').addClass("input");
    $('.required').append(" <span>*</span>"); 
    
    /*
    $(".box").click(function(){
  	  window.location=$(this).find("a").attr("href"); return false;
  	});
  	*/
  	
  	$('input.search').click(function() {
  		$(this).val( ( $(this).val() == "Enter keyword..." ? "" : $(this).val() ) );
  	});
  	$('input.search').blur(function() {
  		$(this).val( ( $(this).val() == "" ? "Enter keyword..." : $(this).val() ) );
  	});
    
    $("#navigation ul").each( function(){
    	
    	if(  $(this).children().length == 0 ){
    		$(this).remove();
    	}
    });
    
    var keyselect = $('select#keydateselect option');
    if (keyselect.length > 0) {
        var month_names = new Array(
            "January",
            "February",
            "March", 
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December"
        );
        
        var d = new Date();
        var current_month = month_names[d.getMonth()];
        
        keyselect.each(
            function() {
                if ($(this).val() == current_month) {
                    $(this).attr('selected', 'selected');
                }
            }
        );
        
        changeMonth();
    }
    
    // img stuff
    $("div.gallery-image").hover(function() {
    	$(this).css({'z-index' : '10'});
    	$(this).find('img').addClass("hover").stop()
    		.animate({
    			marginTop: '-110px', 
    			marginLeft: '-110px', 
    			top: '50%', 
    			left: '50%', 
    			width: '174px', 
    			height: '154px',
    			padding: '20px' 
    		}, 200);
    	
    	} , function() {
    	$(this).css({'z-index' : '0'});
    	$(this).find('img').removeClass("hover").stop()
    		.animate({
    			marginTop: '0', 
    			marginLeft: '0',
    			top: '0', 
    			left: '0', 
    			width: '80px', 
    			height: '60px', 
    			padding: '5px'
    		}, 400);
    });
/*
    //Swap Image on Click
    	$("div.gallery-image a").click(function() {
    		
    		var mainImage = $(this).attr("rel"); //Find Image Name
    		$("#main_view img").attr({ src: mainImage });
    		return false;		
    	});
  */   
    
    $("ul#nav").superfish({
        autoArrows:  true,                           // disable generation of arrow mark-up 
        dropShadows: true                            // disable drop shadows 
    }); 
    
    if( $("#subNav4_node180 a").length ){
    	var txt = $("#subNav4_node180 a").text();
    	 $("#subNav4_node180 a").html( txt.replace(' ', '<br />') );
    }
    if( $("div.latestnews .item:last").length  ){
    	$("div.latestnews .item:last").css('border-bottom','none');
    }
   
});

function changeMonth() {
    var month = $('select#keydateselect option:selected').val();
    
    if (month.length > 0) {
        $('div.keymonth').css('display', 'none');
        $('div#key' + month.toLowerCase()).css('display', 'block');
    }
}
/*
 * Pretty forms
 */
function prettyform(){
  /*
   * Hide forms
   */
  $( 'form.prettyform' ).hide().end();
  /*
   * Label & list formatting
   */
  $( 'form.prettyform' ).find( 'label' ).not( '.noprettyform' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = '';
    this.appendChild( labelSpan );
  } ).end();
  
  /*
   * Show forms
   */
  $( 'form.prettyform' ).show().end();
}
