$(document).ready(function(){
	/* clear and restore search fields */
	$('#search input#search_term').val('Search');
	 $('input#newsletter_submit').wrap('<p id="nls_wrap"></p>');
	 $('#search_term').removeClass('clearClick').addClass('clickClear');
	 $('#newsletter_text').removeClass('clearClick').addClass('clickClear');
	 $('input.clickClear').focus(function() {
	    startText = $(this).val();
	    $(this).val('').addClass('focus');
	 });
	 $('input.clickClear').blur(function() {
	    blurText = $(this).val();
	    if (blurText === '') {
	       $(this).val(startText).removeClass('focus');
	    };
	 });


	$("#nav li:last, #footer .sep:last, #steps li:last").addClass("last");
	$("#footer .churchinfo a").text("E-MAIL");
	$("#steps li:first").addClass("first");
	$("#subsection > .col ").each(function(){
		$(this).find("li:last").addClass("last");  
	});

	$("#site-guide, #header #locations ul, #header #newsfeed ul").hide(); 
    
	// color box launch
	$('#login .thickbox, #comments .thickbox').colorbox({iframe:true,width:400, height:250});
	$('.thickbox[href*=donate.php]').colorbox({iframe:true,width:400, height:500});
	$('.thickbox[href*=loginMCMS.php]').colorbox({iframe:true,width:400, height:250});
	$('#footer .thickbox').colorbox();
	$('#content .slideshow').colorbox({
		slideshow:true,
		photo:true,
		preloading:true,
		slideshowSpeed:5000
		});
	$('.rsvp .thickbox').colorbox({iframe:true,width:450, height:570});
	$('#options .thickbox,.section .thickbox').colorbox({iframe:true,width:500, height:570});  
	//@end



	$("#header .link a").click(function(){
	       var parent = $(this).parent().parent();
		   var link = $(this);
	     if(parent.attr("id") === "siteguide"){
			   if(link.hasClass('active')){
					   $("#site-guide").slideUp("normal", function(){link.removeClass("active");});
				}else{
					   $("#site-guide").removeClass("hide").slideDown("normal", function(){link.addClass("active");});  
				}
		       

		 } else if(parent.attr("id") === "locations"){ 
			
		   	if(link.hasClass('active')){
					   $("#locations ul").slideUp("fast", function(){link.removeClass("active");});
				}else{
					   $("#locations ul").slideDown("fast", function(){link.addClass("active");});  
				}
		
		 } else if(parent.attr("id") === "newsfeed"){ 
			
			if(link.hasClass('active')){
					   $("#newsfeed ul").slideUp("fast", function(){link.removeClass("active");});
				}else{
					   $("#newsfeed ul").slideDown("fast", function(){link.addClass("active");});  
				} 
		 } 
		
		return false;
		
	});
	
      $("#locations li a").click(function(){
	   window.location = $(this).attr("href");
	});

	//$("#locations .dropdown li a[href='"+$.cookie('location')+"']").addClass("current");  

	
	/*$("#locations .dropdown li a").click(function(){
		//$.cookie('location', eurl, { expires: 7, path: '/', domain: , secure: false });
		$("#locations .dropdown li a").removeClass("current");
		$(this).addClass("current");
		$.cookie('location', $(this).attr("href"), { expires: 0, path: '/', domain: 'copperhillchurch.monkcms.net/', secure: false });
	  $.ajax({
				cache:false,
	            data:"loc=" + $(this).attr("href"),
				dataType:"html", 
	            url: "/_inc/ajax-set-cookie.php",
	            timeout: 1000,
	            type:"GET",
	            async:false, 
	            error: function(){ 
					object.html("error");
	            },
	            success: function(e){
	                  $("#header").prepend(e);

	            }
	        }); *
	//return false;
		window.location.reload(true);
	}); */
	
   
	$("#sub-content .first .feature:gt(0),#sub-content .middle .feature:gt(2),#sub-content .last .feature:gt(2) ").hide();
	
	
	$("#sub-content .seemore").click(function(){
		
	   if($("#sub-content").hasClass("open")){
		     	
			    $("#sub-content .first .feature:gt(0),#sub-content .middle .feature:gt(2),#sub-content .last .feature:gt(2) ").fadeOut("slow");  
   				$("#sub-content").animate({ 
				        height: "333px"
				      }, 800, function(){
					
						$("#sub-content").removeClass("open");
					    $("#sub-content .seemore").removeClass("down");
					
					 });
			 
		}else{  
			
			     $("#sub-content .first .feature:gt(0),#sub-content .middle .feature:gt(2),#sub-content .last .feature:gt(2) ").show();  
		    	$("#sub-content").animate({ 
			        height: "625px"
			      }, 800,function(){ $("#sub-content").addClass("open");  $("#sub-content .seemore").addClass("down"); });
		   
		}

	 return false; 
	
	  });  

	}); 