$(function () {

// animated menu (jQuery Blend 1.3 - http://colorpowered.com/blend/)
(function(e){e.fn.blend=function(p){if(e.browser.mozilla&&parseFloat(e.browser.version)<1.9)return this;var c=e.extend({},e.fn.blend.settings,p);e(this).each(function(){function l(m){j&&f.fadeTo(c.speed,m,function(){l(m===g?h:g)})}var n=e(this),b=e(c.target?c.target:this),f,o=[],a,k,d={},j=false,g=0,h=c.opacity,i=["background-color","background-image","background-repeat","background-attachment","background-position","background-position-x","background-position-y"];k=i.length;b[0].style.position!== "absolute"&&b.css({position:"relative"});b.hasClass("hover")||b.wrapInner('<div style="position:relative" />');for(a=0;a<k;a++)o[a]=b.css(i[a]);b.addClass("hover");d={};d.position="absolute";d.top=0;d.left=0;d.width=b.width();d.height=b.height();for(a=0;a<k;a++)d[i[a]]=b.css(i[a]);if(b.find(".jsblend").length===0){f=e('<div class="jsblend" />').css(d);c.top?f.appendTo(b):f.prependTo(b)}else f=b.find(".jsblend");d={};for(a=0;a<k;a++)d[i[a]]=o[a];b.css(d);if(c.reverse){g=c.opacity;h=0}f.css({opacity:g}); if(c.pulse&&c.active){j=true;l(h)}else c.pulse?n.hover(function(){j=true;l(h)},function(){j=false;f.stop(true).fadeTo(c.speed,g)}):n.hover(function(){f.stop().fadeTo(c.speed,h)},function(){f.stop().fadeTo(c.speed,g)})});return this};e.fn.blend.settings={speed:500,opacity:1,target:false,reverse:false,pulse:false,active:false,top:false}})(jQuery);

if (!$.browser.msie) { 
$('#header ul a').blend({speed:500});
}

// "Grants"
$('#grants #content dl:last').css({border:0});
$('#grants #content dl:first').css({'margin-top':20});

// make entire list item clickable
	$("#header ol li").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});

// animate secondary menu
$("#header ol li").css("cursor","pointer").hover(function() {
            $(this).stop().animate({paddingLeft:"5px"}, 250).find("a:not(.active)").css("color","#9a9374");
        }, function() {
            $(this).stop().animate({paddingLeft:"0"}, 250).find("a:not(.active)").css("color","#bf4e37");
        });
        
$("#about_us ul.tabs a").hover(function() {
            $(this).stop().animate({paddingLeft:"5px"}, 250);
        }, function() {
            $(this).stop().animate({paddingLeft:"0"}, 250);
        });
        
// back to top   
$('a.top').click(function(){
     $('html, body').animate({scrollTop: '0px'}, 1500);
     return false;
});
 
// Text hint for seach input field (CoolInput Plugin 1.5 - http://www.alexweber.com.br/jquery/coolinput/)
;(function($){$.fn.coolinput=function(b){var c={hint:null,source:"title",blurClass:"blur",iconClass:false,clearOnSubmit:true,clearOnFocus:true,persistent:true};if(b&&typeof b=="object") $.extend(c,b);else c.hint=b;return this.each(function(){var d=$(this);var e=c.hint||d.attr(c.source);var f=c.blurClass;function g(){if(d.val()=="")
d.val(e).addClass(f)} function h(){if(d.val()==e&&d.hasClass(f)) d.val("").removeClass(f)} if(e){if(c.persistent) d.blur(g);if(c.clearOnFocus) d.focus(h);if(c.clearOnSubmit) d.parents("form:first").submit(h);if(c.iconClass) d.addClass(c.iconClass);g()}})}})(jQuery);

$('#calendar #email').coolinput().addClass('field-hint');
$('#newsletter-form #email').coolinput().addClass('field-hint');


// Pager for calendar's sidebar events (http://rikrikrik.com/jquery/pager/)
$.fn.pager=function(clas,options){var settings={navId:'nav',navClass:'nav',navAttach:'append',highlightClass:'highlight',prevText:'&laquo;',nextText:'&raquo;',linkText:null,linkWrap:null,height:null}
if(options)$.extend(settings,options);return this.each(function(){var me=$(this);var size;var i=0;var navid='#'+settings.navId;function init(){size=$(clas,me).not(navid).size();if(settings.height==null){settings.height=getHighest();}
if(size>1){makeNav();show();highlight();}
sizePanel();if(settings.linkWrap!=null){linkWrap();}}
function makeNav(){var str='<ul id="'+settings.navId+'" class="'+settings.navClass+'">';str+='<li><a href="#" rel="prev">'+settings.prevText+'</a></li>';for(var i=0;i<size;i++){var j=i+1;str+='<li><a href="#" rel="'+j+'">';str+=(settings.linkText==null)?j:settings.linkText[j-1];str+='</a></li>';}
str+='<li><a href="#" rel="next">'+settings.nextText+'</a></li>';str+='</div>';switch(settings.navAttach){case'before':$(me).before(str);break;case'after':$(me).after(str);break;case'prepend':$(me).prepend(str);break;default:$(me).append(str);break;}}
function show(){$(me).find(clas).not(navid).hide();var show=$(me).find(clas).not(navid).get(i);$(show).show();}
function highlight(){$(me).find(navid).find('a').removeClass(settings.highlightClass);var show=$(me).find(navid).find('a').get(i+1);$(show).addClass(settings.highlightClass);}
function sizePanel(){if($.browser.msie){$(me).find(clas).not(navid).css({height:settings.height});}else{$(me).find(clas).not(navid).css({minHeight:settings.height});}}
function getHighest(){var highest=0;$(me).find(clas).not(navid).each(function(){if(this.offsetHeight>highest){highest=this.offsetHeight;}});highest=highest+"px";return highest;}
function getNavHeight(){var nav=$(navid).get(0);return nav.offsetHeight;}
function linkWrap(){$(me).find(navid).find("a").wrap(settings.linkWrap);}
init();$(this).find(navid).find("a").click(function(){if($(this).attr('rel')=='next'){if(i+1<size){i=i+1;}}else if($(this).attr('rel')=='prev'){if(i>0){i=i-1;}}else{var j=$(this).attr('rel');i=j-1;}
show();highlight();return false;});});}

$('#calendar #sidebar .col').pager('dl');


// filter by city
	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		// regular expression to remove white space and punctuation (Washington, D.C. >> washingtondc)
		var filterVal = $(this).text().toLowerCase().replace(/ /g,'').replace(/[^\w-]+/g,'');
		if(filterVal == 'allcities') {
			$('#eventwrapper').fadeOut('fast',function(){
			$('#eventwrapper .hidden').removeClass('hidden');
			$('#eventwrapper').fadeIn('slow');
			});
		} else {
			$('#eventwrapper').fadeOut('normal',function(){
				$('div.event').each(function() {
					if(!$(this).hasClass(filterVal)) {
						$(this).addClass('hidden');
					}
					else{
						$(this).removeClass('hidden');
					}
					$('#eventwrapper').fadeIn('normal');
				}); 	});		}
		return false;
	});
	
	
/* Tabs */
 $('.tabs').each(function () {
    var $links = $(this).find('a'),
      panelIds = $links.map(function() { return this.hash; }).get().join(","),
      $panels = $(panelIds),
      $panelwrapper = $panels.filter(':first').parent(),
      delay = 500,
      heightOffset = 5;
      
    $panels.hide();
    $('ul.tabs li:first-child').click();
    
    $links.click(function () {
     
      var link = this, 
        $link = $(this);
        
      // ignore if already visible
      if ($link.is('.active')) {
        return false;
      }
      
      $links.removeClass('active');
      $link.addClass('active');
 
      $panelwrapper.stop().animate({
        height: 0
      }, delay, function () {
        var height = $panels.hide().filter(link.hash).show().height() + heightOffset;
        
        $panelwrapper.animate({
          height: height
        }, delay);
      });
    });
 
$links.filter(window.location.hash ? '[hash=' + window.location.hash + ']' : ':first').click();
});

$("#newsletter-form").validationEngine();
$("#contact-form").validationEngine();

// close jquery document ready function
}); 