/*

	South Paw Javascript

*/

/*

	Last list items
	
	We want to remove the border from the last item in the any unordered lists
	The lists are dynamic, so we need to do this with javascript

*/

jQuery('#nav ul li:last').addClass('last');

if(!jQuery('#twitter').length){

	jQuery('#nav ul').each(function(i, el){
		
		jQuery(el).children('li:last').addClass('last');
		
	});

}

/*

	Disable Right Click

*/


jQuery(this).bind("contextmenu", function(e) {
	
	return false;	
	
	//e.preventDefault();
	
});
this.oncontextmenu = function() { return false; };
document.oncontextmenu = function() { return false; };

/*

	Comment Slide down
	When the user clicks add comment, the respond box slides into view

*/

jQuery('a.add_comment').click(function(e){
	
	e.preventDefault();
	
	var id = jQuery(this).attr('id').replace('add_comment','');
		
	jQuery('#respond'+id).slideDown('slow');
	
});

/*

	Comment Scrollbar

*/

if(jQuery('.commentlist').length){
	jQuery('.commentlist').jScrollPane({
		scrollbarWidth: 13
	});
}

/*

	Ajax Comments
	
	We are hijacking the default wordpress comment creation (hopefully)

*/

if(jQuery('.respond').length){

	jQuery('.respond form').submit(function(){
				
		var self = jQuery(this);
						
		var post_id = self.attr('id').split('_');
		var post_id = post_id[1];

		var err = jQuery('#comment_error_'+post_id);
		
		self.ajaxSubmit({			
			beforeSubmit: function() {

				jQuery('#respond_'+post_id).prepend('<div class="loading_overlay"></div>');
				jQuery('.loading_overlay').fadeTo('fast',0.9)

				//Fade out the form to alert the user that something is happening
				self.fadeTo('fast',0.5);
			},
			error: function(request){
				
				//Remove the overlay
				jQuery('.loading_overlay').remove();
				
				//Empty the error
			    err.empty();
			    
			    //Get the response and add it to the error
			    var data = request.responseText.match(/<p>(.*)<\/p>/);
			    err.html(data[1]);
			    			    			    
			    //Fade back the form
				self.fadeTo('fast',1);
				
			},
			success: function(data) {
				
				//Remove the "No Comments" message (if it exists)			    
			    //if(jQuery('#commentlist_'+post_id).children('li.nocomment').length()){	
			    	jQuery('#commentlist_'+post_id).children('li.nocomment').slideUp().fadeTo('slow',0);
			    //}
			    	
			    //Erase the error messages	
			    err.empty();			   	
			    		
			   	//Grab the response and add it to the list	    
			    var response = jQuery("<ol>").html(data);
			    var replace = response.find('.commentlist li:last').hide().appendTo(jQuery('#commentlist_'+post_id)).fadeTo('slow',1);

				//Remove the overlay
				jQuery('.loading_overlay').remove();

				//Reset the form
				jQuery('#respond_'+post_id).slideUp('slow');
				self.reset();
				
				//Reset the scrollers
				jQuery('.commentlist').jScrollPane();
				
				//Re-Fade the form
				self.fadeTo('fast',1);

			}
				
		});
	
		return false;
	
	});

}

/*

	Nav Dropdown

*/

var nav = jQuery('#nav li');

var is_ie6 = typeof document.body.style.maxHeight === "undefined" ? true : false;

nav.mouseenter(
	function(){
		
		if(is_ie6){ return false; }
		
		var self = jQuery(this);
		
		self.addClass('active');		
		self.find("ul").css('display','block');
	
	}
);

nav.mouseleave(
	function(){
	
		if(is_ie6){ return false; }

		var self = jQuery(this);
		
		self.removeClass('active');
		self.find("ul").css('display','none');
		
		Cufon.refresh();
		
	}
);

/*

	Header Slider

*/

if(jQuery('#header_slider').length){

	jQuery('#header_slider').nivoSlider({
		effect: 'fade',
		pauseOnHover: false,
		directionNav: false,
		controlNav: false
	});

}

/*

	Set subcontent li to equal heights

*/

jQuery('#sub_content').equalHeights();
