 $(document).ready(function(){
	jQuery.easing.def = "easeInOutExpo";
	// animate scrolling to internal links
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
				|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				if ($(this).attr('href') == "#top")
					$('html,body').animate({scrollTop: 0}, {duration: 2000, easing: jQuery.easing.def});
				else
					$('html,body').animate({scrollTop: targetOffset}, {duration: 2000, easing: jQuery.easing.def});
				return false;
			}
		}
	});
});

$(document).ready(function () {
	// Don't know why but this is needed for IE7 to show the navbar
	$("#left").width();
});

$(document).ready(function ()	{
	// Set up leader bio colorbox
	$('#leadership .image-grid li').each(function () {
		if($('.leader-bio',$(this)).length > 0)	{
			$(this).colorbox({inline:true, href:$(".leader-bio",$(this)), width:"590px", height: "420px", rel:"nofollow",initialHeight:"50%"});
		}
	});
});

$(document).ready(function ()	{
	// Set up media video colorbox
	$('#video-section .image-grid li').each(function () {
		if($('.media-video',$(this)).length > 0)	{
			$(this).colorbox({inline:true, href:$(".media-video",$(this)), width:"610px", height: "480px", rel:"videos",initialHeight:"50%"});
		}
	});
});
	
$(document).ready(function() {
	// force section divs downwards out of viewport if current div height is less than viewport height
	var viewHeight = $(window).height();
	
	$('.section').each(function () {
		var section = $(this);
		var sectionHeight = parseInt(section.css('height').substring(0,section.css('height').length-2));
		
		if (sectionHeight < viewHeight) {
			section.css('margin-bottom',viewHeight + 100);
		}
		else {
			section.css('margin-bottom',viewHeight);
		}	
	});
	
	//$('.section:last-child').css('margin-bottom','200px');
	
});

// $(document).ready(function () {
	// // Mailchimp sign up form
	// // Load in colorbox instead of popup
	// $('#mc-embedded-subscribe-form')[0].submit(function () {
		
	// });
// });

	

	
$(document).ready(function() {
	// Flickr feed

	$('#photostream-houston').jflickrfeed({
			limit: 20,
			qstrings: {
			id: '67609497@N03',
			tags: "houston",
			tagmode: "all"
			},
		itemTemplate: '<li><a rel="houston" href="{{image_b}}" title="{{title}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
		}, function (data)	{
			$('#photostream-houston li a[rel="houston"]').colorbox();
		});
	
	$('#photostream-florida').jflickrfeed({
			limit: 20,
			qstrings: {
			id: '67609497@N03',
			tags: "florida",
			tagmode: "all"
		},
		itemTemplate: '<li><a rel="florida" href="{{image_b}}" title="{{title}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
		}, function (data)	{
			$('#photostream-florida a[rel="florida"]').colorbox();
		});
		

	$('#photostream-conference').jflickrfeed({
			limit: 20,
			qstrings: {
			id: '67609497@N03',
			tags: "2010-conference",
			tagmode: "all"
		},
		itemTemplate: '<li><a rel="conference" href="{{image_b}}" title="{{title}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
		}, function (data)	{
			$('#photostream-conference a[rel="conference"]').colorbox();
		});
	
	$('#photostream-washington').jflickrfeed({
			limit: 20,
			qstrings: {
			id: '67609497@N03',
			tags: "washington",
			tagmode: "all"
		},
		itemTemplate: '<li><a rel="washington" href="{{image_b}}" title="{{title}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
		}, function (data)	{
			$('#photostream-washington a[rel="washington"]').colorbox();
		});
		
	$('#photostream-austin').jflickrfeed({
			limit: 20,
			qstrings: {
			id: '67609497@N03',
			tags: "austin",
			tagmode: "all"
		},
		itemTemplate: '<li><a rel="austin" href="{{image_b}}" title="{{title}}"><img alt="{{title}}" src="{{image_s}}" /></a></li>'
		}, function (data)	{
			$('#photostream-austin a[rel="austin"]').colorbox();
		});
	

});		


		
$(document).ready(function(){
	// Hero rotator
	$('#features').jshowoff({
		animatePause: false,
		autoPlay: true,
		controls: false,
		effect: 'fade',
		hoverPause: true,
		links: true,
		speed: 6000,
		changeSpeed: 2500
		}); 

	// remove title text from rotator nav
	$('.jshowoff-slidelinks > a').each(function () {
		$(this).html("&nbsp;");
	});
});
	
jQuery(document).ready(function(){
	// set up accordions
	$('.accordion .head').live('click',function() {
		var head = $(this);
		head.next().animate({height: ['toggle','swing']}, {duration: 800, easing: jQuery.easing.jswing});
		if (head.hasClass('open'))
			head.removeClass('open');
		else 
			head.addClass('open');
		return false;
	}).next().hide();
});

// setup custom radio buttons for event/membership selection
function setupLabel() {
	if ($('.label_check input').length) {
		$('.label_check').each(function(){ 
			$(this).removeClass('c_on');
		});
		$('.label_check input:checked').each(function(){ 
			$(this).parent('label').addClass('c_on');
		});                
	};
	if ($('.label_radio input').length) {
		$('.label_radio').each(function(){ 
			$(this).removeClass('r_on');
		});
		$('.label_radio input:checked').each(function(){ 
			$(this).parent('label').addClass('r_on');
		});
	};
};

$(document).ready(function(){
	$('body').addClass('has-js');
	$('.label_check, .label_radio').click(function(){
		$(this).children('input').attr('checked','checked');
		setupLabel();
	});
	setupLabel(); 
});


$(document).ready(function(){

	var clearMePrevious = '';

	// clear input on focus
	$('.clearMeFocus').focus(function()	{
		if($(this).val()==$(this).attr('title'))	{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});

	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function()	{
		if($(this).val()=='')	{
			$(this).val(clearMePrevious);
		}
	});
});	

jQuery(document).ready(function(){
	
	$('#contactform').submit(function(){
		
		var action = $(this).attr('action');
		
		$("#errormessage").slideUp(750,function() {
		$('#errormessage').hide();
		
 		$('#contactimage')
			.before('<img src="images/ajax-loader.gif" class="loader" />');
		$.post(action, { 
			name: $('#contactname').val(),
            email: $('#contactemail').val(),
			comments: $('#contactcomments').val(),
			verify: $('#contactverify').val()
		},
			function(data){
				$('#errormessage').html(data);
				$('#errormessage').slideDown('slow');
				$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
				if(data.match('success') != null) $('#contactform').slideUp('slow');				
			}
		);
		
		});
		
		return false; 
	
	});
	
});

$(document).bind("ready",function () {
	// show page after js is complete
	$('#container').show();
	
	// adjust navlinks margin-top, must be down after show() above
	var wh = $(window).height();
	
	var nav = $('#NavLinks');
	
	var navHeight = nav.height() +
					parseInt(nav.css('margin-top').substring(0,2)) + 
					$('#MavPacLogo').height();

	if (wh < navHeight)	{
		if (parseInt(nav.css('margin-top').substring(0,2)) - (navHeight - wh) > 0)	{
			nav.css('margin-top',parseInt(nav.css('margin-top').substring(0,2)) - (navHeight - wh));
		}
		else	{
			nav.css('margin-top',0);
		}
	}
	
	// in-section  multi-column height correction
	$('.SectionColumns').each(function () {
		var maxHeight = 0;
		$('> div',this).each(function () {
			var h = $(this).height();
			if (h > maxHeight)
				maxHeight = h;
		});
		$(this).height(maxHeight);
	});
});

function submitEvent(eventID)	{
	var costList = $(eventID);
	
	if ($('input[value=2]',eventID).parent().hasClass('r_on'))	{ // chairman
		$('input[name="amount"]').val("1500.00");
		$('input[name="totalSteps"]').val("1");
		$('input[name="membership"]').val("3");
		$('input[name="quantity"]').val("0");
		costList.attr("action","join.php");
	}
	if ($('input[value=3]',eventID).parent().hasClass('r_on'))	{ // sustaining old: WW63MJN9D2K8E
		$('input[name="amount"]').val("300.00");
		$('input[name="totalSteps"]').val("1");
		$('input[name="membership"]').val("2");
		$('input[name="quantity"]').val("0");
		costList.attr("action","join.php");
	}
			
	eventID.submit();
}

function submitMembership(form)	{
	form.submit();
}

$(document).ready(function () {
	$('form').submit(function () {
		return false;
	});
});
