// JS for image page

jQuery(document).ready(function(){
	// cookie
	var cname = jQuery.cookie("comment_name");
	if(cname != null) jQuery("#comment_name").val(cname); // IE puts "null" in (!)
	
	// comment colors
	jQuery("div.comment_wrapper").hover(
		function(){
			jQuery(this).addClass("comment_wrapper_anchor");
			jQuery("div.comment_bottom img", this).attr("src", "images/comment_box_bottom_anchor.gif");
		},
		function(){
			jQuery(this).removeClass("comment_wrapper_anchor");
			jQuery("div.comment_bottom img", this).attr("src", "images/comment_box_bottom.gif");
		}
	);
	if(document.location.hash.length && document.location.hash.substr(0, 9) == "#comment_"){
		jQuery(document.location.hash).trigger("mouseenter").unbind('mouseenter').unbind('mouseleave');
	}
	
	// form stuff
	jQuery('#comment_form').preventDoubleSubmit(); // remember to reset the beenSubmitted variable if the form isn't actually posted!!
	jQuery("#comment_form").submit(function(){
		var msg = "";
		if(jQuery("#comment_name").val() == "") msg += "You must fill in a name. ";
		if(jQuery("#comment_body").val() == "") msg += "You must enter comment text. ";
		if(jQuery("#comment_name").val().toLowerCase()=='motts' || jQuery("#comment_body").val().indexOf("http://") != -1 || jQuery("#comment_body").val().indexOf("https://") != -1){
			// human check
			if(!jQuery("#human_check:visible").length){
				jQuery("#submit_row_orig").hide();
				jQuery("#human_check").show();
				jQuery("#human_answer").focus();
				this.beenSubmitted = false;
				return false;
			}else{
				if(jQuery("#human_answer").val() == ""){
					msg += "Please answer the security question. ";
					jQuery("#human_answer").focus();
				}
			}
		}
		
		if(msg != ""){
			alert(msg);
			this.beenSubmitted = false;
			return false;
		}
		return true;
	});
	
	// rollovers
	jQuery("input.button_post_comment").hover(
		function(){
			jQuery(this).attr("src", "images/button_post_comment_roll.gif");
		},
		function(){
			jQuery(this).attr("src", "images/button_post_comment.gif");
		}
	);
	
});
