// JavaScript Document
// Play well with other libraries, use jQuery instead of $
jQuery.noConflict();

//topnav menu
jQuery(document).ready(function(){
								
	// rollovers
	PEPS.rollover.init();
	
	//top nav hover
    if (document.all) {
        jQuery("#navlinks li").hoverClass ("hover");
    }
	// set div links
	jQuery(".divlink").click( function(){
		window.location=jQuery(this).find("a").attr("href"); return false;
	});
	// external links
	jQuery("a[rel='external']").click( function() {
	window.open( jQuery(this).attr('href') );
	return false;
	});
	jQuery('#top_callout').flash({
    src: 'swf/slideshow4.swf',
    width: 606,
    height: 227
	});
	// min height for IE 6
	if((jQuery.browser.msie) && (jQuery.browser.version < 7)){
		if(jQuery('#right_col_sub').height() < 340){
			jQuery('#right_col_sub').css("height", "340px");
		}
		if(jQuery('#news').height() < 458){
			jQuery('#news').css("height", "458px");
		}
	}
	// directory print link
	jQuery("#print_button").click( function() {
		window.print();
		return false;
	});
	
	// Submit Event Form
	jQuery("#goto").find("select").change(function(){
		jQuery("goto").submit();										 
	});
	// Add end class to various lists
    jQuery('ul li:last-child, ol li:last-child').addClass('end');
	
});





//topnav hover function
jQuery.fn.hoverClass = function(c) {
    return this.each(function(){
        jQuery(this).hover( 
            function() { jQuery(this).addClass(c);
			if((jQuery.browser.msie) && (jQuery.browser.version < 7)){
				jQuery('select').addClass('invisible');							 
				}
			},
            function() { jQuery(this).removeClass(c);
			if((jQuery.browser.msie) && (jQuery.browser.version < 7)){
				jQuery('select').removeClass('invisible');
				}
			}
        );
    });
};

// Rollover images function
PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
      
      jQuery(".ro").hover(
         function () { jQuery(this).attr( 'src', PEPS.rollover.newimage(jQuery(this).attr('src')) ); },
         function () { jQuery(this).attr( 'src', PEPS.rollover.oldimage(jQuery(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      jQuery(window).bind('load', function() {
         jQuery('.ro').each( function( key, elm ) { jQuery('<img>').attr( 'src', PEPS.rollover.newimage( jQuery(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_o' + src.match(/(\.[a-z]+)/)[0];
   },
   
   oldimage: function( src )
   {
      return src.replace(/_o/, '');
   }
};

