$("document").ready(function(){ 
	
	//nav
	$('#nav>li').not("#nav_home").click(function(){
			$('#nav>li').removeClass('current');
			$(this).addClass('current');
			$('#header').css('height', '150');
		    $('#nav ul').hide();
            $heading = $(this);
			$dropdown = $heading.find('ul');
			if ($dropdown.is(':hidden')) {
					$dropdown.show();
				} 
			else {
					$dropdown.hide();
				}			
    });
	
	//subnav
	$('#subnav li li:has(ul)').addClass('subdropdown');
	$('#subnav .subdropdown').click(function(e){
			e.preventDefault();
            $subheading = $(this);
			$subdropdown = $subheading.find('ul');
			if ($subdropdown.is(':hidden')) {
					$subdropdown.show();
				} 
			else {
					$subdropdown.hide();
				}			
    }).children().find('li').click(function(e) {
		e.stopPropagation();
	});
	
	//rotator 
	$("#rotator a").each(function() {
				var href = $(this).attr("href");
				if(href == '') {
					$(this).replaceWith($(this).children()); 
				}
			});
      $('#rotator').cycle({ 
                 fx:     'fade', 
                 speed:  'slow', 
                 timeout: 4000, 
                 pager:  '#rotatorbtns' 
             });
			 
 	 //clear and restore search fields
	 $('#search input#search_term').val('Search');
	 $('#newsletter_submit').wrap('<p id="nls_wrap"></p>');
	 $('#search_term').removeClass('clearClick').addClass('clickClear');
	 $('#newsletter_text').removeClass('clearClick').addClass('clickClear');
	 $('.clickClear').focus(function() {
	    startText = $(this).val();
	    $(this).val('').addClass('focus');
	 });
	 $('input.clickClear').blur(function() {
	    blurText = $(this).val();
	    if (blurText == '') {
	       $(this).val(startText).removeClass('focus');
	    };
	 }); 
	  
	//colorbox
	$('.login .thickbox, #comments .thickbox, a[title=Log In].thickbox, #content #text a.thickbox').colorbox({iframe:true,width:400, height:300});
	$('.rsvp .thickbox, #subnav .thickbox').colorbox({iframe:true,width:450, height:600});
	$('#options .thickbox,.section .thickbox,  a[title=Donate].thickbox,').colorbox({iframe:true,width:500, height:600});
	$('.slideshow').colorbox({
		slideshow:true,
		photo:true,
		preloading:true,
		slideshowSpeed:5000,
		slideshowAuto:false
		});
	 
	//other
	if ($('ul#subnav li.current').length == 0){
		$('.subnav').remove();
	}
	
});
