var openTopics = new Array();


function expandTopic(el, topic) {
	// we really want the li, not the a
	el = el.parentNode;

	// check to make sure this date hasn't been expanded
	if (!getobj('gallery'+topic)) {
	  var xmlHttp = xmlhttp_req();
	  var url = "./getPics.cgi?" + topic;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.onreadystatechange = function() { expandTopicCallback(el, xmlHttp); };
	  xmlHttp.send(null);
	} else {
		new Effect.SlideUp('gallery'+topic, { duration: 0.5 });
		setTimeout(function() { el.removeChild(getobj('gallery'+topic)); },500);
	}
}

function expandTopicCallback (el, xmlHttp) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText.split("::",2);
			el.innerHTML = el.innerHTML + response[1];
			new Effect.SlideDown(response[0], { duration: 0.5 });
		}
	}
}

function makeNSFW(id) {
	var xmlHttp = xmlhttp_req();
	var url = "./makeNSFW.cgi?" + id;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = function() { makeNSFWCallback(id, xmlHttp); };
	xmlHttp.send(null);
}

function makeNSFWCallback(id, xmlHttp) {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			if (xmlHttp.responseText == "OK") {
				getobj("thumb"+id).src="/thumbs/nsfw.jpg";
			}
		}
	}
}

function suggestTopic(el) {
	getobj('suggestedTopicIntro').innerHTML = "Thanks for your suggestion, care to submit another?";
	var xmlHttp = xmlhttp_req();
	var url = "./suggestTopic.cgi?topic=" + el.value;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange = null;
	xmlHttp.send(null);
	getobj('suggestedTopic').value = "";
}


