function insertemail(name){
			var emailpt = "mailto:";
			var dom = "societyofthecincinnati.org";
			document.write('<a href="' + emailpt + name  + '@' + dom +'" rel="nofollow"><span>' + name + '@' + dom +'</span></a>');
}
	
var that = {};

$(document).ready(function() {
		
		
			//cache nav
			var nav = $("#subnav");
			//add indicators and hovers to submenu parents
			nav.find("li").each(function() {
				if ($(this).find("ul").length > 0) {				
					$(this).mouseenter(function() {
						nav.data("status", "mouseEnter");
						$(this).closest("nav").find("#line").show();
						$(this).find("ul").stop(true, true).slideDown("slow") ;
					});
	
					$(this).mouseleave(function() {	
						nav.data("status", "mouseLeave");
						$(this).find("ul").stop(true, true).slideUp("normal", function() { 
							if (nav.data("status") == "mouseLeave") 
								$(this).closest("nav").find("#line").fadeOut("fast");
						});
						
					});
				}
			});
		
		
		/* NEWSLETTER SIGNUP FORM */
		$("#B_newsletter, #B_newsletter_events").click(function(e) {
			e.preventDefault();
			clearPopup();
			if ($(this).attr("id") == "B_newsletter") {
				$("#newsletter").addClass("bottom").removeClass("top");
				$("#newsletter_wrapper").fadeIn();
			} else {
				$("#newsletter").addClass("top").removeClass("bottom")
				$("#newsletter_wrapper").fadeIn();
			}
			
		});
		
		//qString checks
		if ($.queryString("newsletter")){ 
			$("#B_newsletter").click();
		}	
		
		
		$(".B_cancel").click(function(e) {
			e.preventDefault();
			$(this).closest(".popup").fadeOut();
			clearPopup();
		});
		
		/* FORGOT PASSWORD FORM */
		$("#B_forgotpw").click(function(e) {
			e.preventDefault();			
			clearPopup();
			$("#forgotpw_wrapper").fadeIn();
		});
		
		/* CHANGE PASSWORD FORM */
		$("#B_changepw").click(function(e) {
			e.preventDefault();
			clearPopup();
			$("#changepw_wrapper").fadeIn();
		});
		
		$(".preauth").click(function(e) {
			e.preventDefault();
			clearPopup();
			$("#preauth_wrapper").appendTo($(this)).fadeIn().end().find(".B_close").live("click",function(e) {
			e.preventDefault();
			$(this).closest(".popup").fadeOut();
			
		});;
		});
		
		
		//FORM HANDLING
		$('form.service_form').each(function(){
			$(this).oc_forms({mainDelegate: that});
		});
		
		// ADMIN TOOL CONTENT
		//NOTIFICATION BAR
		$.fn.showNotice = function(path) {
		    	$.ajax({
		    	    url: path + "getNotices.do",
		       	    cache:false,
		    	    success: function(json) {
		    	    	if(json.Response.Payload.notices.notice.length > 0 ) {
			    	        var notice = json.Response.Payload.notices.notice[0].message;
			    	        if (notice !== undefined) {
			    	        	//alert (notice);
			    	        	$("#homepage").after("<aside id=\"notice\"><label>IMPORTANT NOTICE: </label><p>" + notice + "</p></aside>");
			    	        
			    	        } else {
			    	        	//alert ("There was a problem loading the notice.");
			    	        }
		    	    	}
		    	        
		    	    }
		    	});
		    	
		    };
		  //CINCINNATI FOURTEEN
		  $.fn.showFourteen = function(path) {				   				    	
			  var servePath = path.split("/");
			  if (servePath.length>0)
					servePath.pop();
			  servePath= servePath.join("/");
			  $.ajax({
		    	    url: path + "getFourteen.do",
		    	    data:{page:1, perPage:100, locale:"EN"},
		       	    cache:false,
		    	    success: function(json) {
		    	    	var response = json.Response.Payload.fourteens.fourteen;
		    	    	var container = $(".fourteenList");
		    	    	if(response.length > 0) {    	    		
		    	    		var list = "";
	    	    	        var column = 3;
	    	    	        var columnCount = 0;
	    	    	        if(response.length %3 != 0) columnCount = Math.floor(response.length/3) +1;
	    	    	        else columnCount = Math.floor(response.length/3);
		    	    		for (var i=0; i<response.length; i++){
		    	    			var title = response[i].title;
		    	    	        var file = response[i].file;    	        
		    	    	        if (title !== undefined) {
			    	    	        list += "<li><a href='"+servePath + file + "' target='_blank'>" + title + "<span class=\"button B_download_icon\">download</span></a></li>";
			    	    	        if(i == columnCount - 1){
			    	    	        	list1 = "<div id='firstColumn'>"+list+"</div>";
			    	    	        	container.append(list1);
			    	    	        	list ="";
			    	    	        }else if(i == columnCount*2 - 1){
			    	    	        	list2 = "<div id='secondColumn'>"+list+"</div>"; 
			    	    	        	container.append(list2);
			    	    	        	list ="";
			    	    	        }else if(i == response.length - 1){
			    	    	        	list3 = "<div id='thirdColumn'>"+list+"</div>";    	    	            
			    	    	        	container.append(list3);
			    	    	        	list ="";
			    	    	        }
			    	    	     }
		    	    		}
		    	    	} 
		    	    	else container.html("There was a problem loading the list.");
		    	    } 
		    	});
		   
		  };
				    	
	//PRESS
	$.fn.showPress = function(path) {
		
		var servePath = path.split("/");
		if (servePath.length>0)
			servePath.pop();
		servePath= servePath.join("/");
		
    	$.ajax({
    	    url: path +"getPress.do",
    	    data:{page:1, perPage:100, locale:"EN"},
       	    cache:false,
    	    success: function(json) {
    	    	var response = json.Response.Payload.presss.press;
    	    	var container = $(".articleList");
    	    	if(response.length > 0) {    	    		
    	    		var list = "";
    	    		for (var i=0; i<response.length; i++){
    	    			var title = response[i].title;
    	    	        var file = response[i].file;
    	    	        var date = response[i].date;
    	    	        if (title !== undefined) {
    	    	        	list += "<li><i>" + date + "</i><br><a href='"+servePath + file + "' target='_blank'>" + title + "<span class=\"button B_download_icon\">download</span></a></li>";    	    	        
    	    	        } 
    	    		}
    	    		container.html(list);
    	    	} 
    	    	else container.html("There was a problem loading the list.");
    	    }
    	});
								    	
								    
	};


	//MEMBERS-ONLY TESTIMONIALS
	$.fn.showTestimonials = function(path) {	
		$.ajax({
		    url: path +"members/getTestimonials.do",
		    data:{page:1, perPage:100, locale:"EN"},
	   	    cache:false,
		    success: function(json) {
		    	var response = json.Response.Payload.testimonials.testimonial;
		    	var container = $("#testimonials");
		    	if(response.length > 0) {    	    		
		    		var list = "";
		    		for (var i=0; i<response.length; i++){
		    			var title = response[i].title;
		    	        var body = response[i].body;
		    	        var date = response[i].date;
		    	        if (title !== undefined) {
		    	        	list += "<h4>" + title + "</h4><p>\"" + body + "\"<span class='date'>" + date + "</span></p>";    	    	        
		    	        } 
		    		}
		    		container.html(list);
		    	} 
		    	else container.html("There was a problem loading the list.");
		    }
		});
								    	
								    
	};
	
	$('#viewlarge').click(function(){
		$('.popup_class').fadeIn();
		$('.showcontent').hide();
		$('#closeBtn').show();
		$('#imagesdivision').show();
	});
	
	$('#closeBtn').click(function(){
		$('.popup_class').fadeOut();
	});
});
				    

function clearPopup(){
	$("form", ".popup").find("input[type=text]").val("");
	$(".errors", ".popup").remove();

}
		 


$(function(){
	
	var lightbox = $('#lightbox'),
	    iframe = lightbox.find('iframe'),
	    close = lightbox.find('span.close');
	
	var links = $('a[rel="lightbox"]');
	
	
		links.click(function () {
			lightbox.addClass('open');
			
			var me = $(this);
			setTimeout(function () {
				iframe.attr("src", me.attr("href"));
			}, 1500)
			
			return false;
		});
	

	close.click( function () {
		lightbox.addClass('closed').removeClass("open");
		iframe.attr("src", 'about:blank');
		return false;
	});
	
							    	
});	

				
						

