jQuery.fn.extend({ scrollTo : function(speed, easing) { return this.each(function() { var targetOffset = $(this).offset().top; $('html,body').animate({scrollTop: targetOffset}, speed, easing); });} });
$(document).ready(function() {
	$("#forum-reply-form").hide();
	$("a[href='#post-reply']").click(function(e){ e.preventDefault(); $('#forum-reply-form').show(); $('#forum-reply-form').scrollTo(1000); $("#quickreply").focus(); });
	$("a[href^='#post-edit-']").each(function() {
		$(this).click(function(e){
			e.preventDefault();
			id = $(this).attr('href').match(/^#post\-edit\-([0-9]+)/);
			id = id[1];
			if ( $("#post-edit-"+id).length > 0 ) {
				$("#post-edit-"+id).toggle("slow");
				$("#post-content-"+id).toggle("slow");
			} else {
				$("#post-content-"+id).hide("slow");
				$("#post-content-"+id).after("<div class=\"forum-js-edit\" style=\"display: none;\"id=\"post-edit-"+id+"\"><div class=\"loading\">Loading Edit System... <a href=\"#\">Cancel</a></div></div>");
				$("#post-edit-"+id).show("slow");
				$("#post-edit-"+id).load("/edit/get/"+id+"/");
			}
		});
	});
	$("a[href^='#ibpanel-']").each(function() {
		$(this).mouseenter(function(e){
			e.preventDefault();
			id = $(this).attr('href').match(/^#ibpanel\-([0-9]+)/);
			id = id[1];
			for(i=0; i<=6; i++) {
				if(id == i) {
					$(this).addClass("act");
					$("#panel"+i).removeAttr("class").show();
					$("#pbg").addClass("bg"+i); 
				} else {
					$(this).removeClass("act");
					$("#pbg").removeClass("bg"+i);
					$("#panel"+i).hide();
				}
			}
		}).click(function(e){e.preventDefault();});
	});
	$("a[href^='#post-quote-']").each(function() {
		$(this).click(function(e){
			e.preventDefault();
			id = $(this).attr('href').match(/^#post\-quote\-([0-9]+)/);
			id = id[1];
			$('#forum-reply-form').show();
			$('#forum-reply-form').scrollTo(1000);
			$.getJSON("/quote/"+id+"/?format=json&callback=?",
				 function(data) {
					$("#quickreply").attr('value', $("#quickreply").attr('value') + "[quote="+ data.by +"]" + data.content + "[/quote]");
					$("#quickreply").focus();
				 }
			);
		});
	});
	$("#vote-remind-close").click(function(e) {
		e.preventDefault();
		$("#vote-full-reminder-text").hide("slow");
		$("#vote-full-reminder").hide("slow");
	});
	$("#vote-remind-ten").click(function(e) {
		e.preventDefault();
		$("#vote-full-reminder-text").hide("slow");
		$("#vote-full-reminder").hide("slow");
	});
	setTimeout('$("#splash-msg").hide("fast");', 30000);
	$("#splash-msg-close").click(function(e) {
		e.preventDefault();
		$("#splash-msg").hide("fast");
	});
});
var qst = setTimeout("quick_status_update()", 500);
function quick_status_update() {
	$.getJSON('http://www.wowtorn.net/api/qstatus.php?callback=?', function(data) { $("#torn_quick_status").replaceWith('<div id="torn_quick_status">Overview: '+data.html+'</div>'); });
	var qst = setTimeout("quick_status_update()", 30000);
}
var __hovers = new Array();
var __tooltip_cache = new Array();
function tt_on(id, img, type) {
	size = 'medium';
	if(id.length > 0) {
		__hovers[type+id] = true;
		if(__tooltip_cache[type+id] == undefined) {
			overlib(tt_holder('Loading...'),VAUTO,HAUTO,FULLHTML);
			var url = false;
			switch(type) {
				case 'i':
					url = 'http://www.wowtorn.net/api/itt.php?q='+id+'&t=1&format=json&callback=?';
				break;
				case 'm':
					url = 'http://www.wowtorn.net/api/mtt.php?m='+id+'&callback=?';
					size = 'large';
				break;
				case 't':
					url = 'http://www.wowtorn.net/api/ttt.php?t='+id+'&callback=?';
				break;
				default:
					if(__hovers[type+id] == true) { overlib(tt_img_holder('<b>Unknown Type... ('+type+')</b>', 'http://static.wowtorn.net/images/icons/medium/pedo_bear.jpg', size),VAUTO,HAUTO,FULLHTML); }
					return;
				break;
			}
			if(url != false) {
				$.getJSON(url, function(data, textStatus) {
					if(data.tooltip != 'undefined') {
						__tooltip_cache[type+id] = new Array();
						__tooltip_cache[type+id][0] = data.tooltip;
						if(data.icon != 'undefined') {
							if(data.icon != false) {
								__tooltip_cache[type+id][1] = data.icon;
								if(type == 'm') { img = true; }
							} else {
								img = false;
								__tooltip_cache[type+id][1] = '';
							}
						} else {
							img = false;
							__tooltip_cache[type+id][1] = '';
						}
						if(__hovers[type+id] == true) { if(img == true) { overlib(tt_img_holder(__tooltip_cache[type+id][0], __tooltip_cache[type+id][1], size),VAUTO,HAUTO,FULLHTML); } else { overlib(tt_holder(__tooltip_cache[type+id][0]),VAUTO,HAUTO,FULLHTML); } }
					} else {
						__tooltip_cache[type+id] = new Array();
						__tooltip_cache[type+id][0] = '<b>Server Busy... :(</b><br/><span class="q0">'+textStatus+'</span><br/><span class="q">Contact Torn staff if this keeps happening...</span>';
						__tooltip_cache[type+id][1] = 'http://static.wowtorn.net/images/icons/medium/pedo_bear.jpg';
						if(__hovers[type+id] == true) { overlib(tt_img_holder(__tooltip_cache[type+id][0], __tooltip_cache[type+id][1], size),VAUTO,HAUTO,FULLHTML); }
					}
				 });
			}
		} else {
			if(type == 'm' && __tooltip_cache[type+id][1] != '') { size = 'large'; img = true; } 
			if(__hovers[type+id] == true) { if(img == true) { overlib(tt_img_holder(__tooltip_cache[type+id][0], __tooltip_cache[type+id][1], size),VAUTO,HAUTO,FULLHTML); } else { overlib(tt_holder(__tooltip_cache[type+id][0]),VAUTO,HAUTO,FULLHTML); } }
		}
	}
}

function tt_holder(inner) {
	return '<table class="tt_outer"><tr><td width="300"><div class="tooltip"><table><tr><td>'+inner+'<th style="background-position: right top;"/></tr><tr><th style="background-position: left bottom;"/><th style="background-position: right bottom;"/></tr></table></div></td></tr></table>';
}

function tt_img_holder(inner, icon, size) {
	return '<table class="tt_outer"><tr><td valign="top"><div class="icon'+size+'" style="background-image: url('+icon+');"><div class="tile"></div></div></td><td valign="top" width="300"><div class="tooltip"><table><tr><td>'+inner+'<th style="background-position: right top;"/></tr><tr><th style="background-position: left bottom;"/><th style="background-position: right bottom;"/></tr></table></div></td></tr></table>';
}

function tt_off(id, type) {
	__hovers[type+id] = false;
	return nd();
}