jQuery(function() {
	// open, close, clear, close button
	jQuery(".popup_container a").click(function() {
		var closeButton = '<img class="close" src="wp-content/themes/AW2LH/custom/images/close.png" alt="close" />';
		var popupContainer = jQuery(this).closest(".popup_container");
		popupContainer.addClass("active").append(closeButton).children('.popup').show().find('object').css('visibility','visible');
		jQuery('img.close').bind('click',function() {
			jQuery("#svdo_1").remove();
			vidContainer = jQuery(this).parent();
			if (vidContainer.attr('id') !== "testimonials") {
				vidContainer.children(".popup").empty().hide();
			} else {
				vidContainer.children(".popup").hide();
				jQuery('#testimonials .popup .format_text > div:first').show();
			}
			jQuery(this).parent().removeClass("active");
			jQuery(this).remove();
		});
		
		// men & women
		var id = jQuery(this).parent("p").attr('id');
		if (id == 'men') {
			jQuery('.popup.women').hide();
			jQuery('.popup.men:empty').load("mens-video/ #content .format_text").show();
		}
		if (id == 'women') {
			jQuery('.popup.men').hide();
			jQuery('.popup.women:empty').load("womens-video/ #content .format_text").show();
		}
		// mark pheltz
		var contID = jQuery(this).closest(".popup_container").attr('id');
		if (contID == 'situps') {
			jQuery('#situps .popup:empty').load("mark-pheltz-video/ #content .format_text");
		}
		return false;
	});
	jQuery('#situps .popup').load("mark-pheltz-video/ #content .format_text");
	jQuery('.popup.men').load("mens-video/ #content .format_text");
	jQuery('.popup.women').load("womens-video/ #content .format_text");
	
	// testimonials
	jQuery("#testimonials .popup").load("testimonials/ #content .format_text");
	jQuery("#testimonials a").click(function() {
		var buttons = '<p class="nav"><a href="#" class="previous">Back</a> <a href="#" class="next">Next</a></p>';
		jQuery(this).closest(".popup_container").children(".popup").append(buttons);
		jQuery('#testimonials .popup .format_text > div:gt(0)').hide();
		jQuery('#testimonials p.nav a').bind('click',function() {
			var elem = jQuery('#testimonials .popup .format_text > div:visible');
			if (jQuery(this).hasClass('next')) {
				if (elem.next()[0]) {
					elem.fadeOut().next().fadeIn();
				}
			}
			if (jQuery(this).hasClass('previous')) {
				if (elem.prev()[0]) {
					elem.fadeOut().prev().fadeIn();
				}
			}
			return false;
		});
	});

});
