$(document).ready(function(){
	
	/* clear and restore search fields */
	 $('#search input#search_term').val('');
	 $('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');
	    };
	 });   

	// color box launch
	$('#login .thickbox, #comments .thickbox, #content #text a.thickbox').colorbox({iframe:true,width:400, height:250});
	$('.gallery-thumbnail a').colorbox({
		slideshow:true,
		photo:true,
		preloading:true,
		slideshowSpeed:5000,
		slideshowAuto:false
		});
	$('.rsvp .thickbox ').colorbox({iframe:true,width:450, height:570});
	$('#options .thickbox, .section .thickbox, a[title=Edit Profile].thickbox, #giving-login .thickbox').colorbox({iframe:true,width:500, height:570});
	
	//nav dropdown
	$('#nav').superfish({
		delay: 500,
		animation: {
		  opacity: 'show',
		  height: 'show'
		},
		speed: 'fast',
		autoArrows: false,
		dropShadows: false
	  });
				
	//other
	$('#nav li li:first-child, #subnav li:first-child').addClass('first');
	$('#nav li li:last-child, #subnav li:last-child').addClass('last');
	
	$(document).bind("contextmenu",function(e){
        return false;
    });

	  
	  //rotator
	  $('#rotator').after('<div id="rotatorbtns">').cycle({ 
                    fx:     'fade', 
                    speed:  'slow', 
                    timeout: 5000, 
                    pager:  '#rotatorbtns' 
                });
				
		$('#rotatorbtns').hide();
		
		$('#content-rotator ,#sidebar-rotator').mouseover(function(){
			$('#rotatorbtns').fadeIn('slow');
		});
		$('#content-rotator, #sidebar-rotator').mouseleave(function(){
			$('#rotatorbtns').fadeOut('slow');
		});
		
		//share form
		$("#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: "<p class='error'>Please enter a valid email address</p>",
		toemail: "<p class='error'>Please enter a valid email address</p>",
		name: "<p class='error'>Please enter your name</p>",
		toname: "<p class='error'>Please enter the recepients name</p>"
						},
	submitHandler: function(form) {
	   				var inputs = [];
	                   $("#response").html("Sending Invite...").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("<p><strong>Err: Email Not Sent Try Again Later</strong></p>");   
	                       },
	                       success: function(r){
	                         $("#response").html(r);
							 $("#tellafriend").find("input").not("[name=hidden]").val("").removeClass("focus");      
	                       }
	                   });
	          //return false;
			}
	  });
	
	
}); //@end doc ready
