$(document).ready(function() {

	/* 	Navigation Dropdowns
         -------------------------------------------------------------*/
	   
         $('#nav > ul > li').hover(function() {
				$(this).children('a').addClass('hovering');
				$('ul', this).css('display', 'block');
			}, function() {
				$(this).children('a').removeClass('hovering');
				$('ul', this).css('display', 'none');
			});



			// /*	CLEAR INPUT FIELDS ONFOCUS
			// 	-------------------------------------------------------------*/ 	
     		 $("input.clearinput").clearDefault();  
      
     
     		// Auto Generate Captions from ALT Tag using class 'caption' on IMG
			$("img.caption").each(function() {
				caption = $(this).attr("alt");
				width = $(this).attr("width");				
				$(this).wrap("<div class='caption' style='width:" + width + "px;' />");
				$(this).after("<p>" + caption + "</p>");
			});
			
			// Render Buttons
			$("a.buttonLightBlue, a.buttonBlue, a.buttonLightOrange, a.buttonOrange, a.buttonLightGreen, a.buttonGreen, a.buttonOrange").each(function() {
				text = $(this).html();
				$(this).html("<span>" + text + "</span>");
			});
			
			// Tabs Trigger using Plugin
			// $("ul.tabs").tabs("div.panes > div", {effect: 'fade'});
			
			
			// Trigger Expand/Collapse Accordions
			$("#page div.accordion a.showMore").click(function() {
				content = $(this).parent().find("div.more");
				label = $(this).find("span").html();
				altLabel = $(this).attr("rel");
				
				if ($(content).css("display") == "none") {
					$(this).find("span").html(altLabel);
					$(this).attr("rel", label);
					$(content).slideToggle(250);
				}
				else {
					$(this).find("span").html(altLabel);
					$(this).attr("rel", label);
					$(content).slideToggle(250);
				}
				return false;
			});
			
			// Trigger Expand/Collapse Accordions for Bios
			$("#page ul.bioList a.showMore").click(function() {
				$(this).parent().parent().find("div.more").slideToggle(450);
			});
			$("#page ul.bioList div.more a.close").click(function() {
				$(this).parent().slideToggle(450);	
			});
						
			// FANCYBOX Listeners
			$("#page a.fancyboxImage").fancybox({
				overlayColor: '#111',
				transitionIn: 'fade',
				transitionOut: 'fade',
				titlePosition: 'inside'
			});
			$("#page a.fancyboxSwf").fancybox({
				overlayColor: '#111',
				padding:	0,
				autoScale: false,
				transitionIn: 'fade',
				transitionOut: 'fade',
				titlePosition: 'inside'
			});
			
			$("#page a.fancyboxPage").fancybox({
				overlayColor: '#111',
				type:		'iframe',
				width:		'65%',
				height:		'50%',
				autoScale: false,
				transitionIn: 'fade',
				transitionOut: 'fade',
				titlePosition: 'inside'
			});
			
			$("#page a.fancyboxCode").fancybox({
				overlayColor: '#111',
				type:		'iframe',
				width:		400,
				height:		300,
				autoScale: false,
				transitionIn: 'fade',
				transitionOut: 'fade',
				titlePosition: 'inside'
			});
			
			$("#page a.fancyboxYouTube").click(function() {
				$.fancybox({
					'padding'		: 0,
					'overlayColor'	: '#111',
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'			: 640,
					'height'		: 385,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
					}
				});
				return false;
			});
			
			$("#main a.fancyboxYouTube").live("click", function() {
				$.fancybox({
					'padding'		: 0,
					'overlayColor'	: '#111',
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'			: 640,
					'height'		: 385,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
					}
				});
				return false;
			});
			
			
			// Other Side of War Video
			$("#page a.fancyboxOtherSide").fancybox({
				overlayColor: '#111',
				type:		'swf',
				width:		736,
				height:		503,
				autoScale: false,
				transitionIn: 'fade',
				transitionOut: 'fade',
				titlePosition: 'inside',
				scrolling:  'no'
			});




			// Side Navigation Auto Highlights
			// Navigation Highlights	   		
	   		$("#sidenav ul li a").each(function() {
				currentURL = window.location.href;		
				if ($(this).attr("href") == currentURL) {
					$(this).addClass("current").parent("li").children("ul").slideDown(200);
					$(this).parent("li").parent("ul").css("display","block").parent("li").children("a").addClass("current");
				}
			 });
			 
			 // Navigation Highlights	   		
	   		$("#sidenav ul.sidenavEvents li a").each(function() {
				currentURL = window.location.href;		
				if ($(this).attr("href") == currentURL) {
					$(this).addClass("current");
					$(".sidenavTitle").addClass("current");
				}
			 });
			 
			 
			 
	// -----------------------------------------------------------------------------
	//  MAILCHIMP SUBSCRIBE
	// -----------------------------------------------------------------------------
	
	$.getScript('http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js', function() {
		$("#emailSubscribeFooter").validate({
			rules: {
				EMAIL: 'required'
			},
			messages: {
				EMAIL: "Please enter a valid email address."
			},
			errorElement: 'div',
			errorPlacement: function(error, element) {
				$(element).parent("#emailSubscribeFooter").append(error);
			},
			focusInvalid: true,
			submitHandler: function(form) {
				var dataString = $(form).serialize();
								
				$.ajax({
					url: 'http://womenforwomen.us1.list-manage1.com/subscribe/post-json?u=7d6f1035cf521297e869f35b3&id=c8f5b92846&c=?', 
					type: 'GET', 
					dataType: 'json', 
					data: dataString,
					contentType: "application/json; charset=utf-8",
					success: function(data)
					{
						$("#emailSubscribeFooter").find('.message').slideUp(300).remove();
						$("#emailSubscribeFooter").append('<div class="message">' + data.msg + '</div>');
						$("#emailSubscribeFooter .message").hide().animate({ height: "show", opacity: "show" }, 500);
						$("#emailSubscribeFooter").find("input").val("Enter Email Address");
					},
					error: function(xhr, errorNumber, errorText)
					{
						alert(errorText);
					}
				});
			}
		});
	});

	
	$.getScript('http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js', function() {
		$("#emailSubscribeSidenav").validate({
			rules: {
				EMAIL: 'required'
			},
			messages: {
				EMAIL: "Please enter a valid email address."
			},
			errorElement: 'div',
			errorPlacement: function(error, element) {
				$(element).parent("#emailSubscribeSidenav").append(error);
			},
			focusInvalid: true,
			submitHandler: function(form) {
				var dataString = $(form).serialize();
								
				$.ajax({
					url: 'http://womenforwomen.us1.list-manage1.com/subscribe/post-json?u=7d6f1035cf521297e869f35b3&id=c8f5b92846&c=?', 
					type: 'GET', 
					dataType: 'json', 
					data: dataString,
					contentType: "application/json; charset=utf-8",
					success: function(data)
					{
						$("#emailSubscribeSidenav").find('.message').slideUp(300).remove();
						$("#emailSubscribeSidenav").append('<div class="message">' + data.msg + '</div>');
						$("#emailSubscribeSidenav .message").hide().animate({ height: "show", opacity: "show" }, 500);
						$("#emailSubscribeSidenav").find("input").val("Enter Email Address");
					},
					error: function(xhr, errorNumber, errorText)
					{
						alert(errorText);
					}
				});
			}
		});
	});
			 
			 
});

// Clear Default Plugin
(function($){
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("");
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value);
			});
		});
	};
})(jQuery);

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
	var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}


