$(document).ready(function() {

	// pal accordian for the why.php  page

	$('.answers').hide();

	$('.palAccordian').each(function() {
		$(this).children('dd').hide();
		var expand = false;
		
		$(this).children('dt').bind('click', function() {
		    $('.answers').fadeOut('fast');
		    $('.palAccordian').find('dt').removeClass('selected');
		    $(this).addClass('selected');
		    $('.palAccordian dd').slideUp('slow');
			if(expand == false) {
				this.expand = true;
				$(this).siblings('dd').slideDown('slow');
		    } else {
				this.expand = false;
				$(this).siblings('dd').slideUp('slow');
		    }
		    return false;
		    
		});
		
	});

// the red box bit

	$('.palAccordian p a').bind('click', function(){	
		// return false;	
	});
	
	$('.palAccordian p').bind('click', function() {
	
		// alert('fire');
		$('.answers').hide();
		$(this).siblings('ul.answers').fadeIn('slow');
		var href = $(this).find('a').attr('href');
		//return false;
		if(href == '#') {
			return false;
		}
		
	});

  // contact div
  $('div.contact'). hide();
  $('div.contact:eq(0)').show();


  $('#names ul li').each(function(i) {
    $(this).find('a').bind('click', function() {
      $('#names ul li a').removeClass('selected');
      $(this).addClass('selected');
      //alert(i);
      $('div.contact').hide();
      $('div.contact').eq(i).fadeIn('slow');
      return false;
    });

  });

// email hider

$('p').defuscate();

});

jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true
    }, settings);
    var regex = /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi;
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            // If it's an <a> element, defuscate the href attribute
            $(this).attr('href', $(this).attr('href').replace(regex, '$1@$2'));
            // Make sure that the element's contents is not made into a link
            var is_link = true;
            //alert($(this).attr('href'));
        }
        // Defuscate the element's contents
        $(this).html($(this).html().replace(regex, (settings.link && !is_link ? '<a href="mailto:$1@$2">$1@$2</a>' : '$1@$2')));
  });
}