$.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;
		}
	});


	
	/** 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 */
    
    
    	
	  
	  /* 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(); 
		}
	});

    
    // all items below added from INSTALL MI document.js file
    //'images/layout/nav_faq_over.gif',
					//'images/layout/nav_new_over.gif',
					
	$.preloadimages('images/layout/nav_home_over.gif', 
					'images/layout/nav_contact_over.gif',
					'images/layout/nav_find_over.gif',
					'images/layout/nav_specifiers_over.gif',
					'images/layout/nav_training_over.gif'
					);
	
    $('.navbutton').swapit('_over');
	
    if ($('#enlarge').length) {
    	$('#enlarge').css('cursor', 'pointer');
    	$('#enlarge').click(function() { 
			var url = $('#enlarge').attr('src').replace('preview', 'fullsize');
			window.open(url, 1, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600');
		});
    }
    
    if ($('div#symposiumForm').length) {
    	$('input#submitbtn').click(function(){
    	
    		var _error = false;
    		$('div#symposiumForm input').each(function(){
    			if ($(this).hasClass('required')) {
    				if ($(this).val().length == 0) { _error = true; }
    			}
    		});
    		if (_error) {
    			alert('Error: All fields are required unless otherwise noted');
    			return false;
    		}
    		
    		if ($('input[name="08_emailverify"]').val() != $('input[name="07_email"]').val()) {
    			alert("Erorr: your email address does not match your verified email address");
    			return false;
    		}
    		return true;
    	});
    }

    
});