$("document").ready(function(){ 
   
	 //form reset
	 $('#search input#search_term').val('Search');
	 $('#newsletter_submit').wrap('<p id="nls_wrap"></p>');
	 $('#search_term').removeClass('clearClick').addClass('clickClear');
	 $('#newsletter_text').removeClass('clearClick').addClass('clickClear');
	 $('#share input').removeClass('clearClick').addClass('clickClear');
	 $('#share #message').removeClass('clearClick').addClass('clickClear');
	 $('.clickClear').focus(function() {
	    startText = $(this).val();
	    $(this).val('').addClass('focus');
	 });
	 $('input.clickClear').blur(function() {
	    blurText = $(this).val();
	    if (blurText == '') {
	       $(this).val(startText).removeClass('focus');
	    };
	 }); 
	  
	//colorbox
	$('.login .thickbox, #comments .thickbox, a[title=Log In].thickbox, #content #text a.thickbox').colorbox({iframe:true,width:400, height:250});
	$('#footer .thickbox').colorbox();
	$('.slideshow').colorbox({
		slideshow:true,
		photo:true,
		preloading:true,
		slideshowSpeed:5000,
		slideshowAuto:false
		});
	$('.rsvp .thickbox, #subnav .thickbox').colorbox({iframe:true,width:450, height:570});
	$('#options .thickbox,.section .thickbox').colorbox({iframe:true,width:500, height:570});
	
	//subnav adjustments
	if ($('ul#subnav li').length == 0){
			$('.subnav').remove();
	}
	
	//subnav adjustments
	if ($('ul#subnav li').length == 0 && $('#sidebar section').length == 0 ){
			$('#sidebar').remove();
	}
	
	//sidebar faq dd
	$('.faq .faq-item').click(function(){ 
			var $answer = $(this).next('div');
			if ($answer.is(':hidden')) {
					$answer.slideDown('fast');
					$(this).addClass('current');
				} 
			else {
					$answer.slideUp('fast');
					$(this).removeClass('current');
				}
	  });
	  	
	//other
	$('#footer .sitemap span:last-child').remove();
	if ($('#sidebar .top').length != 0){
			$('#subnav').css('margin-top', '0');
	}
	if ($('#articles ul.media li').length == 0){
			$('#articles .media').remove();
	}
	
	
	//invite form
	$("#backgroundPopup").css({ "opacity": "0.5" });
	$("#share").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);
						 $("#tellafriend").find("input").not("[name=hidden]").val("").removeClass("focus");  
						 $("#tellafriend").find("#message").val("").removeClass("focus"); 
                       }
                   });
          //return false;
		}
  });
	
  $(".invite").live("click",function(){
	    $("#backgroundPopup").fadeIn("fast"); 
		$("#share").fadeIn("fast"); 
	return false;
	});
	
	$("#share .close").click(function(){
		$("#share").hide();
		$("#backgroundPopup").hide(); 
	});

});
