$(document).ready(function(){



	// Adds a class of 'focus' to focused skip links
	$('ul#nav_access li a').focus(function(){
		$(this).addClass('focus');
	});
	$('ul#nav_access li a').blur(function(){
		$(this).removeClass('focus');
	});
	
	$('#upcoming_events .interactive').each( function() {
		
		$('#upcoming_events_body').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
	    	autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
	    	delay: 4000,                    // How long between slide transitions in AutoPlay mode
	    	startStopped: false,            // If autoPlay is on, this can force it to start stopped
	    	animationTime: 600,             // How long the slide transition takes
	    	hashTags: true,                 // Should links change the hashtag in the URL?
	    	buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Play cycle",             // Start text
	    	stopText: "Pause cycle"               // Stop text
		});
		
	});

	$('#events_gallery').addClass('interactive');
	
	$('p.close a').live('click', function(){
		$('#gallery_enlarged').remove();
		return false;
	})
	
	$('#events_gallery ul li a').live('click', function(){
		var photo = $(this);
		var id_attr = $(photo).attr('id').split('_');
		var entry_id = id_attr[1];
		var close_flag = id_attr[2];
		
		$.get('/events/_gallery_enlarged/'+entry_id+'/'+close_flag, '', function(data) { 
			$('#gallery_enlarged').remove(); // Remove the existing enlarged image if there is one
	          	$('#events_feature').append(data);
			//$('#gallery_enlarged').hide();
	        });
			$('#events_gallery ul li').removeClass('cur');
			$(this).parent().addClass('cur');
		return false;
	})
	
		$("#filter_current").effect("highlight", {}, 3000);
	

		$('#latest_companies').addClass('interactive');
	  
    nav_pri_hover();
    search_text_input();
    scroll_to();
    center_logo();
    center_div();
    static_subnav();
	equalHeight($("body.resources.main ul#featured_resources li"));

	// Add class to last table row of company directory
    $('table tbody tr:last').addClass('last');

    // Add class to last list item of ul#filter_subnav
    $('ul#filter_subnav li:last').addClass('last');

    $('.resources.browse div#content_sec ul li.selected').each(
        function(){
            $(this).prev('li').addClass('selected_previous');
        }
    );

	$('#date_filter').change( function() {
		      location.href = $(this).val();
		});
	
   $('#sector_filter').change( function() {
	      location.href = $(this).val();
	});
	
   $('#employee_filter').change( function() {
	      location.href = $(this).val();
	});
	
   $('#training_filter').change( function() {
	      location.href = $(this).val();
	});

	$('ul.print_friend').prepend("<li class=\"print\"><a href=\"javascript:window.print()\">Print this page</a></li>");
	
	$('.company_profile #navigation_sec').prepend("<li class=\"sub print\"><a href=\"javascript:window.print()\">Print this page</a></li>");
	
	/*$('#search_site, #resources_search, #content_sec form').submit(function() {
		if ($('.keywords').val() == "Keyword(s)") { 
			$('.keywords').val('');
		}
	});
	*/
    
});

	$('#team_filter a').click(function() {
		$('#team_filter li').each(function(){
	            $(this).removeClass('selected');
	        }
	    );
		
	});

    
    /**
        * NAVIGATION PRI
        * When a link is hovered over, the next <li> gets a class to remove it's BG image
        * ----
    */
    function nav_pri_hover() {
        $('div#navigation_pri ul li a').hover(
            function(){
                $(this).parent().next().addClass('hover_next');
            },
            function(){
                $(this).parent().next().removeClass('hover_next');
            }
        )
    }
    


     /**
         * SEARCH TEXT INPUT
         * On focus gets rid of "value" attr, and replaces if off focus
         * ----
     */
     function search_text_input() {
         // set the default text
         $('input.keywords').focus(function(){
     	    var value = this.value;
     		var title = this.title;
     		if (value == title) {
     			$(this).val("");
     		};
     	});

     	// if it's blank then reset back the title attribute
     	$('input.keywords').blur(function(){
     		if(!$(this).val().length){
     		    $(this).val(this.title);
     		}
     	});
     }


     /** 
         * SCROLL TO
         * Scrolls to #anchor
         * ----
     */
    function scroll_to() {
        $('ul#key_milestones li a').click(
            function(){
                var target = $(this).attr('href');                
                $.scrollTo( target, 500 );
                return false;
            }
        );

        $('ul#stepbystep li p.backtotop a').click(
            function(){
                var target = $(this).attr('href');                
                $.scrollTo( target, 500 );
                return false;
            }
        );
    }
     
 
    
    
    /**
        * EMPLOYER LOGOS
        * Vertically centering the logo within container
        * ----
    */
    function center_logo(){
    	$('img.logo').each(function(i){
    	
    		var margin_height = $(this).parent().height() - $(this).height();
        	var final_height = margin_height / 2;
        	
        	$(this).css({marginTop: final_height});
    	
    	});
    }

    /**
        * ERROR MESSAGE PAGES
        * Vertically centering message container with relation to the window height
        * ----
    */
    function center_div(){
        
        var margin_height = $(window).height() - $('div#message').height() -15;
        var final_height = margin_height / 2;
        
        $('div#message').css({marginTop: final_height});

    }
    
    
    
    /** 
        * STATIC & WORK WITH US SUBNAV
        * When a list item has a class of "cur", the previous <li> has a class to remove it's border
        * ----
    */
    function static_subnav() {
        $('.static div#content_sec ul li.cur').prev().addClass('cur_previous');
        $('.workwithus div#content_sec ul li.cur').prev().addClass('cur_previous');
    }



	// Equal height columns
	
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}
	
	







