$.fn.hoverClass = function(c) {
   return this.each(function(){
      $(this).hover( 
         function() { $(this).fadeIn('slow'); },
         function() { $(this).fadeOut('slow');  }
      );
   });
};

$(document).ready(function(){
	
	$('a#go').click(function(){
		if ($('input#search-site').val() != '') {
			window.location = '?module=Search&keywords='+$('input#search-site').val();
			return false;
		}
	});

	/*
    $.preloadimages('images/nav/mainNav-Blog_over.gif', 
					'images/right-arrow_over.gif'
                    );
	*/
	
	/** If search is in focus, blank it out, if it blurs and has nothing in it, put it back to "Search" **/
	$('input#search-site').focus(function() {
		$(this).val('');
	}).blur(function() { if ($(this).val() == '') { $(this).val('Search'); } });
	
	
    $('.changemo').swapit('_over');
    
    /**
	 * Menu Dropdowns for Navigation
	 */
	if (document.all) {
		
		$("ul#dropdownMenu > li > ul").fadeOut("slow");
		$("ul#dropdownMenu li").hover(
			
			function(){ $(this).find("ul:first").fadeIn("slow"); }, 
			function(){ $(this).find("ul:first").fadeOut("slow"); } 
		);
	} else {
		$("ul#dropdownMenu li").hover(
			function(){ $(this).find("ul:first").fadeIn("slow"); }, 
			function(){ $(this).find("ul:first").fadeOut("slow"); } 
		);
		//$("ul#dropdownMenu li").hoverClass("sfHover");
	}
	
	$("ul#dropdownMenu li > ul").fadeOut('fast');

    /* SIDEBAR TABS */
    
	    /* news & events tabs */
	    var newsTabContainers = $('div#newsEventsTab > div'); /* var = all divs within #newsEventsTab */
	    	newsTabContainers.hide().filter(':first').show();/* hide the divs, except for the first one */
	    $('div#newsEventsTab ul.sideTabs a img').filter(':first').addClass('selected-over').mouseout();
	    $('div#newsEventsTab ul.sideTabs a').click(function () {
	    	newsTabContainers.hide(); /* hide all divs */
	    	$('div#newsEventsTab ul.sideTabs a img').removeClass('selected-over');
	    	$(this).children('img').addClass('selected-over');
	    	$('div#newsEventsTab ul.sideTabs a img').mouseout();
	    	newsTabContainers.filter(this.hash).show();
	    	return false; /* stops browser from scrolling down to #whatever */
	    });
	    
	    /* blog & twitter tabs */
	    var blogTabContainers = $('div#twitterBlogTab > div');
	   		blogTabContainers.hide().filter(':first').show();
	   	$('div#twitterBlogTab ul.sideTabs a img').filter(':first').addClass('selected-over').mouseout();
	    $('div#twitterBlogTab ul.sideTabs a').click(function () {
	    	blogTabContainers.hide(); 
	    	$('div#twitterBlogTab ul.sideTabs a img').removeClass('selected-over');
	    	$(this).children('img').addClass('selected-over');
	    	$('div#twitterBlogTab ul.sideTabs a img').mouseout();
	    	blogTabContainers.filter(this.hash).show(); 
	    	return false; 
	    });
	    
	/* END SIDEBAR TABS */
    
    
    	
	/* More Services Links */
	
	var nonCityContainer = $('div#nonCityLinks > div');
	nonCityContainer.hide().filter(':first').show();
	var ncDisplay = 'default';
	
	$('a#ncHospitalsLink').mouseover(function() {
	    if (ncDisplay != 'hospitals') { // if ncDisplay isn't set to hospitals, this event triggers
    		ncDisplay = 'hospitals'; // set ncDisplay to hospitals
    		nonCityContainer.hide(); // hide all divs within nonCityLinks
    		$('#ncHospitals').show(); // show hospitals div
		}
	  });
	  
	  $('a#ncLibraryLink').mouseover(function() {
	    if (ncDisplay != 'library') {
    		ncDisplay = 'library'; 
    		nonCityContainer.hide();
    		$('#ncLibrary').show(); 
		}
	  });
	  
	  $('a#ncSchoolsLink').mouseover(function() {
	    if (ncDisplay != 'schools') {
    		ncDisplay = 'schools'; 
    		nonCityContainer.hide();
    		$('#ncSchools').show(); 
		}
	  });
	  
	  $('a#ncEmsLink').mouseover(function() {
	    if (ncDisplay != 'ems') {
    		ncDisplay = 'ems'; 
    		nonCityContainer.hide();
    		$('#ncEms').show(); 
		}
	  });
	  
	  
	  /* Videos Links */
	  
	var videoContainer = $('div#video > div');
	videoContainer.hide().filter(':first').show();
	var videoDisplay = 'default';
	
	$('a#vidWelcomeLink').mouseover(function() {
		if (videoDisplay != 'welcome') {
			videoDisplay = 'welcome'; 
			videoContainer.hide();
			$('#vidWelcome').show(); 
		}
	});
	
	$('a#vidBusinessLink').mouseover(function() {
		if (videoDisplay != 'business') {
			videoDisplay = 'business'; 
			videoContainer.hide();
			$('#vidBusiness').show(); 
		}
	});
	
	$('a#vidSchoolsLink').mouseover(function() {
		if (videoDisplay != 'schools') {
			videoDisplay = 'schools'; 
			videoContainer.hide();
			$('#vidSchools').show(); 
		}
	});
	
	$('a#vidDowntownLink').mouseover(function() {
		if (videoDisplay != 'downtown') {
			videoDisplay = 'downtown'; 
			videoContainer.hide();
			$('#vidDowntown').show(); 
		}
	});

	$('a#vidQualityLink').mouseover(function() {
		if (videoDisplay != 'quality') {
			videoDisplay = 'quality'; 
			videoContainer.hide();
			$('#vidQuality').show(); 
		}
	});

	$('a#vidMovingLink').mouseover(function() {
		if (videoDisplay != 'moving') {
			videoDisplay = 'moving'; 
			videoContainer.hide();
			$('#vidMoving').show(); 
		}
	});

    
    
});