/* YWCA Plugins */
jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};
	 
$(document).ready(function() {
   	// Home Page Scroller
   	$('#featureScroller').before('<div id="fs-nav">').cycle({ 
		fx:     	'fade', 
		speed:   	1000, 
		timeout: 	8000,
		delay: 		-3000,
		pause: 		1,
		pager: 		'#fs-nav'
	});
	
	// News & Events Tabs (home & sidebar)
	var tabContainers = $('#newsEvents > div');
    $('#newsEvents ul#ne-nav a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('#newsEvents ul#ne-nav a').removeClass('selected');
        $(this).addClass('selected');
        
        return false;
    }).filter(':first').click();
	
	$('.ne-listing li:last-child').css('border-bottom','none');
	
	// Mailto: add class
	$('a[href^=mailto:]').addClass('mailto');
	// PDF: add class
	$('a[href$=pdf]').addClass('pdf');
	// Word: add class
	$('a[href$=doc], a[href$=docx]').addClass('doc');
	// Excel: add class
	$('a[href$=xls], a[href$=xlsx]').addClass('xls');
	
	// Opens new window for external sites
	$("a.external").click(function(){
		window.open(this.href);
		return false
	});
	
	// Search focus remove
	$("#search-field").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	// Tell a Friend
	$("#tellfriend").hide();
	$("li a.email, #tellfriend a.close").click(function() {
		$("#tellfriend").fadeToggle('slow');
		return false
	});
	
}); // end doc ready


// AJAX Eblitz Subscribe
$(function()
	{
		$("#subscribe-btn").click(function() {	
			
			// First, disable the form from submitting
			$('#sub-form').submit(function() { return false; });
			
			// Grab form action
			formAction = $("#sub-form").attr("action");
			
			emailId = "ihulkr";
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				alert("Please enter a valid email address");
				return;
			}
			
			// Serialize form values to be submitted with POST
			var str = $("#sub-form").serialize();
			
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			// Submit the form via ajax
			$.ajax({
				url: "/proxy_curl.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#theForm").hide(); // If successfully submitted hides the form
					$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
				}
			});
		});
	});

function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}

