var search_val;
$(window).load(function() {
	search_val = $('#search').val();
	$('#search').focus(function() {
		if($(this).val() == search_val) {
			$(this).addClass('black');
			$(this).val('');
		}
	});
	$('#search').blur(function() {
		if($(this).val() == '') {
			$(this).val(search_val);
			$(this).removeClass('black');
		}
	});
	$('img').each(function() {
		if($(this).attr('title') && $(this).attr('title') != '') {
			var obj = $(this);
			obj.css('float','none');
			obj.wrap('<div class="wrap" />');
			obj.parent().width(obj.outerWidth(true));
			obj.after('<div class="caption">'+$(this).attr('title')+'</div>');
			obj.next().width(obj.outerWidth()-16);
		}
	});
	// Set column heights to height of tallest column
	var a = $('#col-left');
	var b = $('#col-center');
	var c = $('#col-right');
	var diff = 109;
	
	// If the left column is highest
	if(a.height() > b.height() && a.height() > c.height() + diff) {
		b.height(a.height());		
		c.height(a.height() - diff );
	}
	
	//If the center column is highest
	else if(b.height() > a.height() && b.height() > c.height() + diff) {
		a.height(b.height());
		c.height(b.height() - diff);
	}
	
	//If the right column is highest
	else if(c.height() + diff > a.height() && c.height() + diff > b.height()) {
		a.height(c.height() + diff);
		b.height(c.height() + diff);
	}
	
	//set window height so that footer sticks to bottom of page
	if(window.innerHeight > $('.page-inner').height()) {
		console.log('here');
		$('.page-inner').css({'position':'relative', 'height':window.innerHeight });
		$('.footer').css({'position':'absolute', 'bottom':'0'});
	}
});

$(function() {
	
	//if mouse enters menu area hide home slide and caption, when mouse leaves menu area, bring back home slide and caption
	$('#nav').mouseenter(function() {
		var easing = 'easeInOutBounce';
		$('#slides .home')
			.removeClass('current')
			.animate({ left:'730px', duration:1000 })
			.css({ opacity:'0'})
			.animate({left:'-730px', duration:0});
		$('.caption .home')
			.removeClass('current')
			.animate({ top:'-250px', duration:1000 })
			.css({ opacity:'0'})
			.animate({top:'250px', duration:0});	
	}).mouseleave(function() {
		var easing = 'easeInOutBounce';
		$('#slides li.current:not(.home)')
			.removeClass('current')
			.animate({left:'730px', duration:1000 })
			.css({ opacity:'0'})
			.animate({left:'-730px', duration:0});
		$('.caption li.current:not(.home)')
			.removeClass('current')
			.animate({ top:'-250px', duration:1000 })
			.css({ opacity:'0'})
			.animate({top:'250px', duration:0});
		$('#slides .home').addClass('current').css({opacity:'1'}).animate({ left:'5px', duration:1000 });
		$('.caption .home').addClass('current').css({opacity:'1'}).animate({ top:'0', duration:1000 });
	});
	
	//if mouse moves between menu items
	$("#nav>ul>li>a").hoverIntent( function() {
		var easing = 'easeInOutBounce';
		$('#slides .'+ $(this).attr('id')).addClass('current').css({opacity:'1'}).animate({ left:'5px', duration:1000 });
		$('.caption .'+ $(this).attr('id')).addClass('current').css({opacity:'1'}).animate({ top:'0', duration:1000 });	
	},
	function(){
		var easing = 'easeInOutBounce';

		$('#main').mouseenter(function() {
			$('#slides li.current:not(.home)')
				.removeClass('current')
				.animate({left:'730px', duration:1000 })
				.css({ opacity:'0'})
				.animate({left:'-730px', duration:0});
			$('.caption li.current:not(.home)')
				.removeClass('current')
				.animate({ top:'-250px', duration:1000 })
				.css({ opacity:'0'})
				.animate({top:'250px', duration:0});
		});
			
	});
	$('#member-services').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#member-services+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});	
	$('#scholarships').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#scholarships+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});
	$('#sponsor-nahn').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#sponsor-nahn+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});
	$('#nahn-national').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#nahn-national+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});
	$('#see-us-in-action').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#see-us-in-action+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});
	$('#contact-us').mouseenter(function() {
		$(this).siblings().addClass('hover');
	}).mouseleave(function() {
		if (!$('#contact-us+ul.dropdown').mouseenter()) {
			$('.hover').removeClass('hover');
		}
	});
});


