/* Author: Nick DiMatteo
*/
$("document").ready(function(){

	var a=document.getElementsByTagName("a");
	for(var i=0;i<a.length;i++)
	{
	    a[i].onclick=function()
	    {
	        window.location=this.getAttribute("href");
	        return false
	    }
	}

	$("div.member:last-child").css({"border-bottom":"none"});
	
	$('.member-photo').mouseenter(function() {
    	$(this).children('img.goofy').fadeIn(200);
  	});
  	$('.member-photo').mouseleave(function() {
    	$(this).children('img.goofy').fadeOut(200);
	});
	
	$(".sets-nav").each(function(){
    var subnav = $(this).parent().parent().parent().find('.subnav');
    $(this).appendTo(subnav);
        subnav.replaceWith(
			subnav.html()
			// kill newlines in the HTML temporarily
			.replace(/\n/g,'')
			// take groups of 20 and throw ULs around it
			.replace(/((<li>(.*?)<\/li>){4})/g,'<ul>$1</ul>')
			// throw a UL around the last group of < 20 li's
			.replace(/(.*)<\/ul>(.*)/, '$1</ul><ul>$2</ul>')
			// optional adding back in whitespace
			.replace(/<\/ul>/g, '</ul>\n\n')
		);


	});
	
	$('.sets-nav').hide();
	
	$('.open .section-nav').live({
  mouseenter: function(e) {
  $(this).find(".sets-nav").slideDown({duration:300 , easing: 'easeInOutCubic'});
  },
  mouseleave: function(e) {
  $(this).find(".sets-nav").stop(true, true).slideUp({duration:300 , easing: 'easeInOutCubic'});
  }
 });
	    
	 

	$("#info").jAccordion();
	$('div.flexslider').flexslider({
		slideshow: false,
		start: function(slider) {
			var sets = slider.slides.filter('.set'),
      setsNav = slider.parent().parent().find('.sets-nav li');
			
			setsNav.click(function(){
				slider.flexAnimate(slider.slides.index(sets.eq(setsNav.index($(this)))));
			});
		}
	});
});
