browseRoot = 'http://browse.minitokyo.net';
forumRoot = 'http://forum.minitokyo.net';
ddmenu = {
	'Tags': {
		'http://browse.minitokyo.net/': 'Popular Tags',
		'http://www.minitokyo.net/Series': 'Series',
		'http://www.minitokyo.net/Mangaka+%26+Studios': 'Mangaka & Studios',
		'http://www.minitokyo.net/Games': 'Games',
		'http://www.minitokyo.net/Artbooks': 'Artbooks'
	},
	'Wallpapers': {
		'http://browse.minitokyo.net/gallery?index=1&order=id': 'Recent',
		'http://browse.minitokyo.net/gallery?index=1&order=favorites&time=1': 'Popular Last Week',
		'http://browse.minitokyo.net/gallery?index=1&order=favorites&time=2': 'Popular Last Month',
		'http://browse.minitokyo.net/gallery?index=1&order=favorites&time=3': 'Popular Last 3 Months',
		'http://browse.minitokyo.net/gallery?index=1&order=favorites&time=4': 'Popular Last Year',
		'http://browse.minitokyo.net/gallery?index=1&order=favorites': 'Popular All Time'
	},
	'Indy Art': {
		'http://browse.minitokyo.net/gallery?index=2&order=id': 'Recent',
		'http://browse.minitokyo.net/gallery?index=2&order=favorites&time=1': 'Popular Last Week',
		'http://browse.minitokyo.net/gallery?index=2&order=favorites&time=2': 'Popular Last Month',
		'http://browse.minitokyo.net/gallery?index=2&order=favorites&time=3': 'Popular Last 3 Months',
		'http://browse.minitokyo.net/gallery?index=2&order=favorites&time=4': 'Popular Last Year',
		'http://browse.minitokyo.net/gallery?index=2&order=favorites': 'Popular All Time'
	},
	'Scans': {
		'http://browse.minitokyo.net/gallery?index=3&order=id': 'Recent',
		'http://browse.minitokyo.net/gallery?index=3&order=favorites&time=1': 'Popular Last Week',
		'http://browse.minitokyo.net/gallery?index=3&order=favorites&time=2': 'Popular Last Month',
		'http://browse.minitokyo.net/gallery?index=3&order=favorites&time=3': 'Popular Last 3 Months',
		'http://browse.minitokyo.net/gallery?index=3&order=favorites&time=4': 'Popular Last Year',
		'http://browse.minitokyo.net/gallery?index=3&order=favorites': 'Popular All Time'
	},
	'Forum': {
		'http://forum.minitokyo.net/recent': 'Active Threads',
		'x00': 'hr',
		'http://forum.minitokyo.net/21': 'General Discussions',
		'http://forum.minitokyo.net/11': 'Off-topic Discussions',
		'http://forum.minitokyo.net/5': 'Introductions Forum',
		'x01': 'hr',
		'http://forum.minitokyo.net/10': 'General Anime & Mange Talk',
		'http://forum.minitokyo.net/12': 'New Releases & Licensing Issues',
		'http://forum.minitokyo.net/13': 'OSTs and AMVs',
		'http://forum.minitokyo.net/14': 'In-depth Discussions',
		'x02': 'hr',
		'http://forum.minitokyo.net/8': 'Music & Movies',
		'http://forum.minitokyo.net/15': 'Hobbies & Sports',
		'http://forum.minitokyo.net/6': 'Art',
		'http://forum.minitokyo.net/25': 'The Sandbox',
		'x03': 'hr',
		'http://forum.minitokyo.net/9': 'Love, Friends & Family',
		'http://forum.minitokyo.net/17': 'School & Work',
		'http://forum.minitokyo.net/18': 'Body, Mind & Fashion',
		'http://forum.minitokyo.net/19': 'Shopping & Food',
		'http://forum.minitokyo.net/20': 'Religion & Science',
		'x04': 'hr',
		'http://forum.minitokyo.net/7': 'Computers & Internet',
		'http://forum.minitokyo.net/23': 'Games',
		'x05': 'hr',
		'http://forum.minitokyo.net/2': 'News',
		'http://forum.minitokyo.net/3': 'Minitokyo Discussions',
		'http://forum.minitokyo.net/4': 'Bug Reports',
		'http://forum.minitokyo.net/26': 'Userpage Customization',
		'http://forum.minitokyo.net/29': 'Deletion Appeals'
	},
	'Reviews': {
		'http://reviews.minitokyo.net/': 'Browse Reviews',
		'http://reviews.minitokyo.net/submit': 'Submit Review'
	},
	'Groups': {
		'http://groups.minitokyo.net/': 'List All Groups',
		'http://my.minitokyo.net/groups': 'My Groups',
		'http://groups.minitokyo.net/new': 'Found New Group'
	},
	'Admin': {
		'http://admin.minitokyo.net/proposed': 'Proposed Highlights',
		'http://admin.minitokyo.net/reports': 'Reports'
	}
}

function setThumbWidth() {
    if ($('#content').width() < 450) {
		$('.scans li').css({width: '48%'});
	} else if ($('#content').width() < 900) {
		$('.scans li').css({width: '32%'});
	} else {
		$('.scans li').css({width: '24%'});
	}
	if ($('#content').width() < 750) {
//		$('.wallpapers dt').css({width: '180px'});
		$('.wallpapers dd').css({width: ($('#content').width() - 242) + 'px'});
	} else {
//		$('.wallpapers dt').css({width: '27%'});
		$('.wallpapers dd').css({width: ($('#content').width() - 444) / 2 + 'px'});
	}

};

var resizeTimer = null;
$(window).bind('resize', function() {
    if (resizeTimer) clearTimeout(resizeTimer);
    resizeTimer = setTimeout(setThumbWidth, 10);
});

function buildMenu(p, d) {
	div = $('<div />');

	ul = $('<ul />');
	$(p).append($(div).append(ul));
	jQuery.each(d, function(i, v) {
		if (v == 'hr') {
			$(ul).append($('<hr/>'));
		} else if (typeof v == 'object') {
			li = document.createElement('li');
			$(li).append(
				$('<tt/>').html('&raquo;')
			).append(
				$('<a />').append(i)
			);
			$(ul).append(li);
			buildMenu(li, v);
		} else {
			$(ul).append(
				$('<li />').append(
					$('<a />').append(v).attr('href', i)
				)
			);
		}
	});
}
function delShout(stamp, e) {
	$.get('http://www.minitokyo.net/delshout', {'stamp': stamp}, function() {
		$(e).parent().next().remove();
		$(e).parent().remove();
	});
	return false;
}
function selectInverse() {
	$('#content input[type=checkbox]').each(function() {
		if ($(this).attr('checked')) {
			$(this).attr('checked', false);
		} else {
			$(this).attr('checked', true);
		}
	});
}

// set thumbnail #rows
setThumbWidth();

// build menus
$('#sections li').each(function(i) {
	title = $('a', this).text();
	if (ddmenu[title]) {
		buildMenu(this, ddmenu[title]);
	}
});

// drop shadows
$('.wallpapers dt a, .scans li > a, #preview > a, .avatar, #sections li div, #nav-bar li div, #search-form div div').each(function() {
	$(this).prepend($('<b/>')).append($('<i/>'));
});

// auto complete
$("#search-form input[type=text]").autocomplete('/suggest', {
	selectFirst: false,
	width: 350,
	scrollHeight: 600,
	formatItem: function(row) {
		return row[0] + ' <span>' + (row[1] == 'Character' ? row[2] : row[1]) + '</span>';
	}
});

// hide ads
$('#ad-toggle').click(function(event) {
	event.preventDefault();
	$('#skyscraper').hide();
	$('#leaderboard div').fadeOut();
	$('#body').animate({marginRight: '10px'});
	$('#footer').animate({marginRight: '0'});
	$('#nav-bar > ul').animate({paddingRight: '40px'});
	$('#ad-toggle').hide();
	setTimeout(setThumbWidth, 400);
});

// scale large images in posts
$('#posts dd img').each(function() {
	m = $('#posts dd').eq(0).width() - 20;
	if ($(this).width() > m) {
		$(this).width(m + 'px');
	}
});

// links in new window
$('a.new-window').attr('title', 'Will open in a new window or tab');
$('a.new-window').click(function(){
	window.open(this.href);
	return false;
});

$('#search-filter li').click(function() {
	option = $(this).text();
	$('#search-filter span').text(option);
	if (option == 'Tags') {
		$('#search-form').attr('action', 'http://www.minitokyo.net/search');
	} else if (option == 'Forum') {
		$('#search-form').attr('action', 'http://forum.minitokyo.net/search');
	} else if (option == 'Members') {
		$('#search-form').attr('action', 'http://members.minitokyo.net/');
	} else if (option == 'Groups') {
		$('#search-form').attr('action', 'http://groups.minitokyo.net/search');
	}
	$('#search-filter div').hide();
	setTimeout("$('#search-filter div').show()", 10);
});

// shoutbox

if (0 && $('#shoutbox')) {
	setInterval(function() {
		$.get('/shoutbox', {}, function(html) {
			$('#shoutbox').html(html);
		});
	}, 120000);
}

$('#rectangle').html('<iframe src="http://static.minitokyo.net/fastclick300.html" style="width: 300px; height: 250px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');
$('.adsense-leaderboard').html('<iframe src="http://static.minitokyo.net/adsense-leaderboard.html" style="width: 728px; height: 90px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');
$('.adsense-banner').html('<iframe src="http://static.minitokyo.net/adsense-banner.html" style="width: 468px; height: 60px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');
$('.adsense-rectangle').html('<iframe src="http://static.minitokyo.net/adsense-rectangle.html" style="width: 300px; height: 250px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');
$('#skyscraper').html('<iframe src="http://static.minitokyo.net/fastclick160.html" style="width: 160px; height: 600px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');
$('#leaderboard div').html('<iframe src="http://static.minitokyo.net/fastclick728.html" style="width: 728px; height: 90px; border: none; overflow: hidden; " border="0" frameborder="0" scrolling="no"></iframe>');

