 $(document).ready(function(){

	//menu
	//hide all of the sub uls
	$('#menu li.parent ul').hide();
	//show any that have a class of open
	$('#menu li.parent.start_open ul').show();
	
	var menu_timer;
	var open;
	$('#menu li.parent').not('.start_open').hover(
		function(){
			//remove animate_closed just in case
			//short delay incase of accidental rollover
			$(this)
				.stop()
				.removeClass('animate_closed')
				.animate({opacity: 1.0}, 300, "swing", function(){
					$(this).addClass('open').children("ul").slideDown("fast");
				});
				
		},
		function(){
			$('#menu li.parent:animated').not('.animate_closed').stop();
			$(this).addClass('animate_closed');
			$(this).animate({opacity: 1.0}, 200, "swing", function(){
				$(this).removeClass('open').removeClass('animate_closed').children('ul').slideUp('fast');
			})
		}
	)
	//add the height of the hidden menus to the menu holder so it doesn't sway
	var hidden_height = 0;
	$('#menu li.parent ul:hidden').each(function(){
		hidden_height = hidden_height>=$(this).height() ? hidden_height : $(this).height();
	});
	$("#menu>ul").css("height",hidden_height + $("#menu>ul").height());

	//round elements with a class name of round ie. menu, news...
	//$('.round').corner("round");
	$('.round').each(function(){
		$(this).append('<img class="r_tl" src="layout_imgs/tl.png" alt="" /><img class="r_tr" src="layout_imgs/tr.png" alt="" /><img class="r_bl" src="layout_imgs/bl.png" alt="" /><img class="r_br" src="layout_imgs/br.png" alt="" />');
	});

	//QUICK JUMPS
	$(".jump").hover(
		function(){
			
			var width = $(this).attr('id')=="nba" ? "270px" : "200px";

			$(this).animate({opacity:1.0}, 300, "swing", function(){
				$(this).children('.qj_body_holder').animate({'width':width},"slow");
			});
		},
		function(){
			$(this).stop().children('.qj_body_holder').animate({width:"0px"},"slow");
		}
	).click(function(){
		var project_id = $(this).attr('class').split(" ")[1];
		
		if(project_id!=1)
			window.location = 'projects.php?project_id='+project_id;
		else
			window.location = 'index.php';
		
	});



	//slideshow on homepages
	$('#homepage_photo').innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: 8000,
		type: 'random_start',
		containerheight: '250px'
	});
	
	// jquery odd/even table row background change
	//$('table.striped > tr:odd').css('background', '#999999');
	
	//PROGRAMS
	$('p.read_full a').toggle(
		function(){
			$(this).parent('.read_full').prev('.full_description').slideDown('fast');
			$(this).attr('title','hide full description').html('hide full description');
		},
		function(){
			$(this).parent('.read_full').prev('.full_description').slideUp('fast');
			$(this).attr('title','read full description').html('read full description');
		}
	);

	// LOTS OF ADS ON A PROGRAM PAGE GOES BEHIND FTR SO MAKE THE MIN-HEIGHT OF THE CONTENT THE AD SIZE
	$('#content:has(#ads)').css('min-height',$('#ads').height()+25);

	//FAQ
	$('dl.faq').find('dd').hide().end().find('dt').click(function() {
         var answer = $(this).next();
         if (answer.is(':visible')) {
             answer.slideUp();
         } else {
             answer.slideDown();
         }
     });

	 $('#expand_all').toggle(
		function(){
			$(this).text("collapse all");
			$('.expand_section').text('collapse section');
			$('dl.faq dd').slideDown();
		},
		function(){
			$(this).text("expand all");
			$('.expand_section').text('expand section');
			$('dl.faq dd').slideUp();
		}
	 );

	
	//setup facebox
	$('a[rel*=facebox]').facebox({extra_setup: faceboxSetup });
	
	//set class for links to external sites and other document types
	setLinkIcons();


	// new news feed
	$('#news_jump a').click(function(){
		$(this).find('img.loading').show();
		// ajax in the data
		$.get($(this).attr('href'), function(rsp){
			var next_offset = $(rsp).find('#next_offset').text();
			var $new_items = $(rsp).find('.news_item_container').hide();

			$('#news_jump').before($new_items);
			$new_items.slideDown('fast', function(){
				$.scrollTo($('.news_item_container:last'), 800, {easing:'swing', margin:true});	
			});


			console.log(next_offset);
			// handle the link
			if(next_offset == "x"){
				$('p#news_jump').replaceWith($('<p class="note"><strong>no older news items</strong></p>'));

			} else {
				$('p#news_jump a').attr('href','news2.php?offset='+next_offset).children('img').hide();
			}
		});

		return false;
	});





});//end document onload

function faceboxSetup(){
	$('#facebox .round').append('<img class="r_tl" src="layout_imgs/tl.png" alt="" /><img class="r_tr" src="layout_imgs/tr.png" alt="" /><img class="r_bl" src="layout_imgs/bl.png" alt="" /><img class="r_br" src="layout_imgs/br.png" alt="" />');
	setLinkIcons();
}

function reloadCalendar(url){
	$.get(url, function(data){
	  $("#calendar_area").html(data);
	});
}

//set class for links to external sites and other document types
function setLinkIcons(){
	$('a[href^="http"]').attr('target', '_blank');
	$('#main a[href$=".pdf"]').addClass('pdf').attr('target','_blank');
	$('#main a[href$=".ppt"]').addClass('powerpoint').attr('target','_blank');
	$('#main a[href$=".doc"]').addClass('word').attr('target','_blank');
	$('#main a[href$=".docx"]').addClass('word').attr('target','_blank');
	$('#main a[href$=".xls"]').addClass('excel').attr('target','_blank');
	$('#main a[href$=".csv"]').addClass('excel').attr('target','_blank');
}


//menu functions
function menuOpen(el){
	//alert(el.length);
	el.children('ul').slideDown('fast');
	el.addClass('open');
}

//CATCH CONSOLE.LOG FOR NO-FIREBUG
if (typeof console == 'undefined' || typeof console.log == 'undefined') { console = { log : function (text) { return false; } } }
