$(document).ready(function(){
	
	init_ajaxComment();
	
	// --------------------------------
	// Thumbnail Image Gallery
	// --------------------------------
	$("#image_num a").click(function() {
		var newSrc = $(this).get(0).href;
		var myString = '<img src="' + newSrc + '" width="322" />';
		$("#aloader").css("display","block");
		$("#masterpic img").fadeOut('fast');
		$("#masterpic").html(myString);
		$("#masterpic img").fadeIn('slow');
		$("#image_num a").removeClass("current");
		$(this).addClass("current");
		return false;
	});
	
	// --------------------------------
	// FAQ
	// --------------------------------
	$("#faqs a").toggle(
		function(){
			$(this).parent().find(".answer").slideDown("fast");
		},function(){
			$(this).parent().find(".answer").slideUp("fast");
		}
	);
	
	
		
	// --------------------------------
	// Filthy Fact Ticker
	// --------------------------------
	
	/*
	newsitems = $("#ticker li").hide().size();
	$("#ticker li:eq("+curritem+")").show();
	setInterval(ticknews,3000); //time in milliseconds
	*/
	
	
}); // End jQuery


function init_ajaxComment() {
	
	$("form.addComment").submit( function() {
		var commentText = '';
		
		commentText = $(this).find("textarea").val();
		if(commentText=='') {
			alert('You must enter a comment');
			$("#comments").focus();
			return false;
		}
		
		$("#submit").hide(); // hide the submit button
		$("#comSpin").show(); // show the spinner
		
		var formID = $(this).attr("id");
		var kids = '';
		var moduleID = '';
		var uniqueID = '';
		
		
		kids = $(this).children();
		
		moduleID = $(kids[1]).val();
		uniqueID = $(kids[2]).val();
		
		// Insert the comment
		$.ajax({
	    	url: "/secondary/incs/comment.php",
	    	type: "POST",
	    	data: "unique="+uniqueID+"&module="+moduleID+"&comment="+commentText+"",
	    	error: function(msg){
	    		alert('error: '+msg+'');
	    	},
	    	success: function(msg){
	    		// hide the form
	    		$("#"+formID+"").slideUp('slow');
	    		// Show thanks
	    		$("#comThanks").html('<p>Thanks for your comment, it will be moderated soon, and will appear on the site shortly.</p>');
	    		$("#comThanks").slideDown('slow');
	    	}
  		});
  		
		return false;
	});
}

/*
var newsitems;
var curritem=0;
function ticknews() {
$("#ticker li:eq("+curritem+")").hide();
curritem = ++curritem%newsitems;
$("#ticker li:eq("+curritem+")").show();
}
*/

function DESemail(emailname,emailserver) {
	document.write("<a href='mailto:" + emailname + "@" + emailserver +"'>");
	document.write(emailname + "@" + emailserver); 
	document.write("</a>"); 
}
// Accessible Pop Ups
function DESopen(url,width,height,toolbar,scroll) {
	window.open(url, "", "scrollbars="+scroll+",toolbar="+toolbar+",height="+ height +",width="+width);
	return false;
}