$(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');
    };
 });
 



$("#footer li.sep:last").addClass("last");
$("#sidebar .section.events .item:odd").addClass("odd");
$("#sidebar .section.events .item").click(function(){
	window.location = $(this).find("a").attr("href");
});


	if($("#subnav li.current ul").length > 0){
		
	}else{
		$("#subnav li.current").addClass("nosub");
	}                                      




// color box launch
$('#login .thickbox, #comments .thickbox').colorbox({iframe:true,width:400, height:250});
$('#footer .thickbox').colorbox();
$('#content .slideshow').colorbox({
	slideshow:true,
	photo:true,
	preloading:true,
	slideshowSpeed:5000,
	slideshowAuto:false
	});
$('#donate .thickbox').colorbox({iframe:true,width:450, height:570});
$('.rsvp .thickbox').colorbox({iframe:true,width:450, height:570});
$('#options .thickbox,.section .thickbox').colorbox({iframe:true,width:500, height:570});  
//@end   

 $("#shareform").hide();   
 $("#response").hide();
 $("#tellafriend").validate({
	rules: {
	email: {
		required: true,
		email: true
	},
	toemail: {
	    required: true,
		email: true
           },
	name:{ 
	   required:true,
	   minlength: 2
	},
	toname:{ 
	required:true,
	minlength: 2
	}
},
messages: {
	email: "Please enter a valid email address",
	toemail: "Please enter a valid email address",
	name: "Please enter your name",
	toname: "Please enter the recievers name"
					},
submitHandler: function(form) {
   				var inputs = [];
                   $("#response").html("<p>Sending Form...</p>").show();
                   $('#tellafriend input').each(function(){
                      inputs.push(this.name + '=' + escape(this.value));
                   });
                       
 					 $('#tellafriend textarea').each(function(){
                    
                        inputs.push(this.name + '=' + escape(this.value));
                    });
                   $.ajax({
                       data: inputs.join('&'),
				       dataType:"html", 
                       url: "/_inc/tellform.php",
                       timeout: 3000,
				 
                       error: function(){
                         $('#response').html("<strong>Err: Email Not Sent Try Again Later</strong>");   
                       },
                       success: function(r){
                         $("#response").html(r);
                       }
                   });
                   //return false;
		}
  });

$("#share .invite").tooltip({ 
	    // change trigger opacity slowly to 0.8
	 	tip: '#shareform',
		delay: .05,
		offset:[-5,-122],
        relative:true,
		position: ['top','right'],
		effect: 'fade',
		opacity: 1,

		onHide: function(){
		   $("#share #response").html("").hide();
		} 

	});

});  
