var style_cookie;
var style_cookie_txt;
var style_cookie_site;
var kumod_set = false;
var quick_reply = false;
var ispage;
var lastid;
var val = 0;
var loopid;
var Utf8 = {
    encode: function (a) {
        a = a.replace(/\r\n/g, "\n");
        var b = "";
        for (var n = 0; n < a.length; n++) {
            var c = a.charCodeAt(n);
            if (c < 128) {
                b += String.fromCharCode(c)
            } else if ((c > 127) && (c < 2048)) {
                b += String.fromCharCode((c >> 6) | 192);
                b += String.fromCharCode((c & 63) | 128)
            } else {
                b += String.fromCharCode((c >> 12) | 224);
                b += String.fromCharCode(((c >> 6) & 63) | 128);
                b += String.fromCharCode((c & 63) | 128)
            }
        }
        return b
    },
    decode: function (a) {
        var b = "";
        var i = 0;
        var c = c1 = c2 = 0;
        while (i < a.length) {
            c = a.charCodeAt(i);
            if (c < 128) {
                b += String.fromCharCode(c);
                i++
            } else if ((c > 191) && (c < 224)) {
                c2 = a.charCodeAt(i + 1);
                b += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2
            } else {
                c2 = a.charCodeAt(i + 1);
                c3 = a.charCodeAt(i + 2);
                b += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3
            }
        }
        return b
    }
};
var gt = new Gettext({
    'domain': 'kusaba'
});
function _(a) {
    return gt.gettext(a)
}
function toggle(a, b) {
    if (match = /manage/.exec(document.location.toString())) var c = 0;
    else var c = "normal";
    $('#' + b).slideToggle(c, function () {
        $(a).html($(this).is(":hidden") ? '+' : '&minus;');
        set_cookie('nav_show_' + b, $(this).is(":hidden") ? '0' : '1', 30)
    })
}
function removeframes() {
	if (match = /news.php/.exec(parent.main.window.location.toString())) {
		$('a.boardlink').attr("target", "_top");
		$("#removeframes").html(_("Frames removed") + ".")
	} else {
		frame = $("#main", top.document);
		
		frame.css("left", (frame.width()  * .15) + "px");
		frame.animate({
			left: "0",
			"width": "100%"
		},
		1000, '', function () {
			set_cookie('frameremoved', 1, 30);
			top.document.title =  $(this).contents().find("title").html();
			$(this).contents().find(".navbar").after("<a id=\"toggleframe\"></a>");
			$(this).contents().find("#toggleframe").html("< Bring back frame").bind("click",
			function() {
				set_cookie('frameremoved', 0, 30);
				$(this).remove();
				frame = $("#main", top.document);
				frame.css("left", 0);
				frame.animate({
					left: (frame.width() * .15) + "px",
					"width": (frame.width() - frame.width() * .15) + "px"
				}, 1000, '');
			});
		});
	}
	return false
}

function reloadmain() {
    if (parent.main) {
        parent.main.location.reload()
    }
}
function replaceAll(a, b, c) {
    var d = a.indexOf(b);
    while (d > -1) {
        a = a.replace(b, c);
        d = a.indexOf(b)
    }
    return a
}
function insert(a) {
    if (!ispage || quick_reply) {
        var b = document.forms.postform.message;
        if (b) {
            if (b.createTextRange && b.caretPos) {
                var c = b.caretPos;
                c.text = c.text.charAt(c.text.length - 1) == " " ? a + " " : a
            } else if (b.setSelectionRange) {
                var d = b.selectionStart;
                var e = b.selectionEnd;
                b.value = b.value.substr(0, d) + a + b.value.substr(e);
                b.setSelectionRange(d + a.length, d + a.length)
            } else {
                b.value += a + " "
            }
            b.focus();
            return false
        }
    }
    return true
}
function checkhighlight() {
    var a;
    if (a = /#i([0-9]+)/.exec(document.location.toString())) if (!document.forms.postform.message.value) insert(">>" + a[1] + "\n");
    if (a = /#([0-9]+)/.exec(document.location.toString())) highlight(a[1])
}
function highlight(a, b) {
    if ((b && ispage) || ispage) {}
    $("td.highlight").removeClass().addClass("reply");
    var c = $("#reply" + a);
    var d = c.parents("table");
    if ((c.length || $('#postform [name=replythread]').val() == a) && d.parent().attr("class") != "reflinkpreview") {
        if (c.length) {
            c.removeClass();
            c.addClass("highlight")
        }
        var e = /^([^#]*)/.exec(document.location.toString());
        document.location = e[1] + "#" + a;
        return false
    }
    return true
}
function get_password(a) {
    var b = getCookie(a);
    if (b) return b;
    var c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var b = '';
    for (var i = 0; i < 8; i++) {
        var d = Math.floor(Math.random() * c.length);
        b += c.substring(d, d + 1)
    }
    set_cookie(a, b, 365);
    return (b)
}
function togglePassword() {
    $("#passwordbox").html('<td class="postblock">Mod</td><td><input type="text" name="modpassword" size="28" maxlength="75">&nbsp;<acronym title="Display staff status (Mod/Admin)">D</acronym>:&nbsp;<input type="checkbox" name="displaystaffstatus" checked>&nbsp;<acronym title="Lock">L</acronym>:&nbsp;<input type="checkbox" name="lockonpost">&nbsp;&nbsp;<acronym title="Sticky">S</acronym>:&nbsp;<input type="checkbox" name="stickyonpost">&nbsp;&nbsp;<acronym title="Raw HTML">RH</acronym>:&nbsp;<input type="checkbox" name="rawhtml">&nbsp;&nbsp;<acronym title="Name">N</acronym>:&nbsp;<input type="checkbox" name="usestaffname"></td>');
    return false
}
function toggleOptions(a, b, c) {
    if ($('#opt' + a).length) {
        if (!$('#opt' + a).is(":hidden")) {
            $('#opt' + a).toggle();
            $('#opt' + a).html()
        } else {
            var d = '<td class="label"><label for="formatting">Formatting:</label></td><td colspan="3"><select name="formatting"><option value="" onclick="$(\'#formattinginfo' + a + '\').html(_(\'All formatting is performed by the user.\'));">Normal</option><option value="aa" onclick="$(\'#formattinginfo' + a + '\').html(_(\'[aa] and [/aa] will surround your message.\'));"';
            if (getCookie('kuformatting') == 'aa') {
                d += ' selected'
            }
            d += '>Text Art</option></select> <input type="checkbox" name="rememberformatting"><label for="rememberformatting">Remember</label> <span id="formattinginfo' + a + '">';
            if (getCookie('kuformatting') == 'aa') {
                d += '[aa] and [/aa] will surround your message.'
            } else {
                d += 'All formatting is performed by the user.'
            }
            d += '</span></td><td><input type="button" value="Preview" class="submit" onclick="javascript:postpreview(\'preview' + a + '\', \'' + c + '\', \'' + a + '\', document.' + b + '.message.value);"></td>';
            $('#opt' + a).html(d);
            $('#opt' + a).toggle()
        }
    }
}
function getCookie(a) {
    with(document.cookie) {
        var b = new RegExp("(^|;\\s+)" + a + "=(.*?)(;|$)");
        var c = b.exec(document.cookie);
        if (c && c.length > 2) return Utf8.decode(unescape(replaceAll(c[2], '+', '%20')));
        else return ''
    }
}
function set_cookie(a, b, c) {
    if (c) {
        var d = new Date();
        d.setTime(d.getTime() + (c * 24 * 60 * 60 * 1000));
        var e = "; expires=" + d.toGMTString()
    } else e = "";
    document.cookie = a + "=" + b + e + "; path=/"
}
function del_cookie(a) {
    document.cookie = a + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/'
}
function set_stylesheet(a, b, c) {
	if ($("a").length) {
	    if (a == 'Nigrachan') {
			$("body").bind('mousemove.rainbow', function (e) {
				if( !loopid && $(e.target).is('a') ) {
					anchorobj = e.target;
					loopid = setInterval("colors()", 100)
				}
				else if (loopid && e.target != anchorobj) {
					clearInterval(loopid);
					$(anchorobj).css("color", '');
					loopid = 0;
				}
			});
	    } else {
    	    $("body").unbind('.rainbow')
	    }
	}
    if (b) {
        if (a == get_default_stylesheet()) del_cookie("kustyle_txt");
        else set_cookie("kustyle_txt", a, 365)
    } else if (c) {
        if (a == get_default_stylesheet()) del_cookie("kustyle_site");
        else set_cookie("kustyle_site", a, 365)
    } else { if (a == get_default_stylesheet()) del_cookie("kustyle");
        else set_cookie("kustyle", a, 365)
    }
    var d = false;
    $('link[rel$=stylesheet][title]').each(function (i) {
        this.disabled = true;
        if (this.getAttribute('title') == a) {
            this.disabled = false;
            d = true
        }
    });
    if (!d) set_preferred_stylesheet()
}
function set_preferred_stylesheet() {
    $('link[rel=stylesheet][title]')[0].disabled = false
}
function get_active_stylesheet() {
    styles = $('link[rel$=stylesheet][title]');
    for (var i = 0, len = styles.length; i < len; i++) {
        if (!styles[i].disabled) return styles[i].title
    }
    return null
}
function get_default_stylesheet() {
    style = $('link[rel=stylesheet][title]');
    if (style.length) {
        return style.attr('title')
    }
    return null
}
if (style_cookie) {
    var cookie = getCookie(style_cookie);
    var title = cookie ? cookie : get_default_stylesheet();
    if (title != get_active_stylesheet()) set_stylesheet(title)
}
if (style_cookie_txt) {
    var cookie = getCookie(style_cookie_txt);
    var title = cookie ? cookie : get_default_stylesheet();
    set_stylesheet(title, true)
}
if (style_cookie_site) {
    var cookie = getCookie(style_cookie_site);
    var title = cookie ? cookie : get_default_stylesheet();
    set_stylesheet(title, false, true)
}
function delandbanlinks(c) {
    if (!kumod_set) return;
    if (!c) {
        togglePassword();
        var d = $("#fileonly");
        d.length && d.parent().html('[<input type="checkbox" name="fileonly" id="fileonly" value="on" /><label for="fileonly">File Only</label>] <input name="moddelete" onclick="return confirm(_(\'Are you sure you want to delete these posts?\'))" value="' + _('Delete') + '" type="submit" /> <input name="modban" value="' + _('Ban') + '" onclick="this.form.action=\'' + ku_cgipath + '/manage_page.php?action=bans\';" type="submit" />')
    }
    var e;
    var f = $("span[id^='dnb']", c).each(function (i) {
        dnbinfo = $(this).attr("id").split('-');
        $.get(ku_boardspath + "/manage_page.php?action=getip&boarddir=" + dnbinfo[1] + "&id=" + dnbinfo[2], {},
        function (a, b) {
            ipaddr = a.split("=") || "what are you doing get out you don't even fit";
            $("#" + ipaddr[0]).prepend("[IP: " + ipaddr[1] + " <a href=\"" + ku_boardspath + "/manage_page.php?action=deletepostsbyip&ip=" + ipaddr[1] + "\" title=\"" + _('Delete all posts by this IP') + "\">D</a> / <a href=\"" + ku_boardspath + "/manage_page.php?action=ipsearch&ip=" + ipaddr[1] + "\" title=\"" + _('Search for posts with this IP') + "\">S</a>] ")
        });
        e = '&#91;<a href="' + ku_cgipath + '/manage_page.php?action=delposts&boarddir=' + dnbinfo[1] + '&del';
        if (dnbinfo[3] == 'y') {
            e += 'thread'
        } else {
            e += 'post'
        }
        e += 'id=' + dnbinfo[2] + '" title="' + _('Delete') + '" onclick="return confirm(_(\'Are you sure you want to delete this post/thread?\'));">D<\/a>&nbsp;<a href="' + ku_cgipath + '/manage_page.php?action=delposts&boarddir=' + dnbinfo[1] + '&del';
        if (dnbinfo[3] == 'y') {
            e += 'thread'
        } else {
            e += 'post'
        }
        e += 'id=' + dnbinfo[2] + '&postid=' + dnbinfo[2] + '" title="' + _('Delete &amp; Ban') + '" onclick="return confirm(_(\'Are you sure you want to delete and ban the poster of this post/thread?\'));">&amp;<\/a>&nbsp;<a href="' + ku_cgipath + '/manage_page.php?action=bans&banboard=' + dnbinfo[1] + '&banpost=' + dnbinfo[2] + '" title="' + _('Ban') + '">B<\/a>&#93;&nbsp;&#91;<a href="' + ku_cgipath + '/manage_page.php?action=bans&banboard=' + dnbinfo[1] + '&banpost=' + dnbinfo[2] + '&instant=y" title="' + _('Instant Permanent Ban') + '" onclick="instantban(\'' + dnbinfo[1] + '\',' + dnbinfo[2] + '); return false;">P<\/a>&#93;&nbsp;&#91;<a href="' + ku_cgipath + '/manage_page.php?action=delposts&boarddir=' + dnbinfo[1] + '&del';
        if (dnbinfo[3] == 'y') {
            e += 'thread'
        } else {
            e += 'post'
        }
        e += 'id=' + dnbinfo[2] + '&postid=' + dnbinfo[2] + '&cp=y" title="' + _('Child Pornography') + '" onclick="return confirm(_(\'Are you sure that this is child pornography?\'));">CP<\/a>&#93;';
        $(this).html(e)
    })
}
function instantban(c, d) {
    var e = prompt(_('Are you sure you want to permenently ban the poster of this post/thread?\nIf so enter a ban message or click OK to use the default ban reason. To cancel this operation, click "Cancel".'));
    if (typeof e === 'string') {
        var f = ku_cgipath + '/manage_page.php?action=bans&banboard=' + c + '&banpost=' + d + '&instant=y';
        if (e != '') {
            f += '&reason=' + e
        }
        $.get(f, {},
        function (a, b) {
            if (a == "success") alert(_("Ban was sucessful."));
            else alert(_("Ban failed!"));
            if (b != "success") alert(_("Ban failed!"))
        })
    } else {
        alert(_("OK, no action taken."))
    }
}
function togglethread(a) {
    if (hiddenthreads.toString().indexOf(a) !== -1) {
        $('#unhidethread' + a).toggle();
        $('#thread' + a).toggle("thread");
        hiddenthreads.splice(hiddenthreads.indexOf(a), 1);
        set_cookie('hiddenthreads', hiddenthreads.join('!'), 30)
    } else {
        $('#thread' + a).toggle();
        $('#unhidethread' + a).toggle();
        hiddenthreads.push(a);
        set_cookie('hiddenthreads', hiddenthreads.join('!'), 30)
    }
    return false
}
function toggleblotter(a) {
    $(".blotterentry").slideToggle("normal", function () {
        if (a) {
            set_cookie('ku_showblotter', $(this).is(":hidden") ? '0' : '1', 365)
        }
    })
}
function expandthread(c, d) {
    var e = $("#replies" + c + d);
    if (e.length) {
        e.prepend(_('Expanding thread') + '...<br /><br />');
        e.load(ku_boardspath + '/ajax.php?act=expand&board=' + d + '&thread=' + c, {},
        function (a, b) {
            if (!a) {
                e.html(_("something went wrong (blank response)"))
            }
            if (b == "error") {
                alert(_('Something went wrong...'))
            }
            delandbanlinks(this);
            addpreviewevents(this)
        })
    }
    return false
}
function quickreply(a) {
    if (a == 0) {
        quick_reply = false;
        $('#posttypeindicator').html('new thread')
    } else {
        quick_reply = true;
        $('#posttypeindicator').html('reply to ' + a + ' [<a href="#postbox" onclick="javascript:quickreply(\'0\');" title="Cancel">x</a>]')
    }
    $('#postform [name=replythread]').val(a)
}
function startPostSpyTimeout(a, b, c) {
    var d = getCookie('postspy');
    if (d == '1') {
        if ($('#thread' + a + b).length) {
            lastid = c;
            setTimeout('postSpy(' + a + ', "' + b + '");', 10000)
        }
    }
}
function postSpy(d, e) {
    var f = $("#thread" + d + e);
    if (f.length) {
        $.get(ku_boardspath + '/ajax.php?act=spy&board=' + e + '&thread=' + d + '&pastid=' + lastid, {},
        function (a, b) {
            if (b != "success") {
                alert(_('Something went wrong...'))
            } else {
                var c = a.split('|');
                newlastid = c[0];
                if (newlastid != '') {
                    a = a.substr((newlastid.length + 1));
                    oldpost = $("#spy" + lastid);
                    if (!oldpost.length) {
                        oldpost = f.children("table:last")
                    }
                    if (!oldpost.length) {
                        oldpost = f
                    }
                    oldpost.after($("<div id=\"spy" + newlastid + "\">" + a + "</div>").hide());
                    lastid = newlastid;
                    newpost = $("#spy" + lastid);
                    newpost.slideToggle("normal");
                    addpreviewevents(newpost);
                    delandbanlinks(newpost)
                }
                setTimeout('postSpy(' + d + ', "' + e + '");', 5000)
            }
        })
    }
}
function getwatchedthreads(c, d) {
    var e = $("#watchedthreadlist");
    if (e.length) {
        e.html(_('Loading watched threads...'));
        e.load(ku_boardspath + '/ajax.php?act=threadwatch&board=' + d + '&thread=' + c, {},
        function (a, b) {
            if (!a) {
                e.html(_("something went wrong (blank response)"))
            }
            if (b == "error") {
                alert(_('Something went wrong...'))
            }
            $("#watchedthreads").css("min-height", ($("#watchedthreadlist").attr('offsetHeight') + $("#watchedthreadsdraghandle").attr('offsetHeight') + $("#watchedthreadsbuttons").attr('offsetHeight')))
        })
    }
}
function addtowatchedthreads(c, d) {
    var e = $("#watchedthreadlist");
    if (e.length) {
        $.get(ku_boardspath + '/ajax.php?act=threadwatch&do=addthread&board=' + d + '&thread=' + c, {},
        function (a, b) {
            if (b == "success") {
                alert(_('Thread successfully added to your watch list.'));
                getwatchedthreads('0', d)
            } else {
                alert(_('Something went wrong...'))
            }
        })
    }
}
function removefromwatchedthreads(c, d) {
    var e = $("#watchedthreadlist");
    if (e.length) {
        $.get(ku_boardspath + '/ajax.php?act=threadwatch&do=removethread&board=' + d + '&thread=' + c, {},
        function (a, b) {
            if (b == "success") {
                getwatchedthreads('0', d)
            } else {
                alert(_('Something went wrong...'))
            }
        })
    }
}
function hidewatchedthreads() {
    set_cookie('showwatchedthreads', '0', 30);
    $("#watchedthreads").fadeOut("slow", function () {
        $(this).remove()
    })
}
function showwatchedthreads() {
    set_cookie('showwatchedthreads', '1', 30);
    window.location.reload(true)
}
function togglePostSpy() {
    var a = getCookie('postspy');
    if (a == '1') {
        set_cookie('postspy', '0', 30);
        alert('Post Spy disabled.  Any pages loaded from now on will not utilize the Post Spy feature.')
    } else {
        set_cookie('postspy', '1', 30);
        alert('Post Spy enabled.  Any pages loaded from now on will utilize the Post Spy feature.')
    }
}
function checkcaptcha(a) {
    if ($("#" + a + " [name=captcha]").length && $("#" + a + " [name=captcha]").val() == '') {
        alert('Please enter the captcha image text.');
        $("#" + a + " [name=captcha]").focus();
        return false
    }
    return true
}
function expandimg(a, b, c, d, e, f, g) {
    var h = $("#thumb" + a + " img:first-child");
    var i = $("#thumb" + a);
    if (h.attr("src") == c) {
        i.html('<img src="' + b + '" alt="' + a + '" class="' + h.attr("class") + '" height="' + e + '" width="' + d + '">')
    } else if (h.attr("src") == b) {
        i.html('<img src="' + c + '" alt="' + a + '" class="' + h.attr("class") + '" height="' + g + '" width="' + f + '">')
    }
}
function postpreview(c, d, e, f) {
    var g = $("#" + c);
    if (g.length) {
        g.load(ku_boardspath + '/ajax.php?act=preview&board=' + d + '&thread=' + e + '&message=' + escape(f), {},
        function (a, b) {
            if (!a) {
                g.html(_("something went wrong (blank response)"))
            }
        })
    }
}
function set_inputs(a) {
    if ($("#" + a).length) {
        if (!$('#' + a + ' [name=name]').val()) $('#' + a + ' [name=name]').val(getCookie("name"));
        if (!$('#' + a + ' [name=em]').val()) $('#' + a + ' [name=em]').val(getCookie("email"));
        if (!$('#' + a + ' [name=postpassword]').val()) $('#' + a + ' [name=postpassword]').val(get_password("postpassword"))
    }
}
function set_delpass(a) {
    if ($("#" + a).length) {
        if (!$('#' + a + ' [name=postpassword]').val()) $('#' + a + ' [name=postpassword]').val(get_password("postpassword"))
    }
}
function addpreviewevents(g) {
    $("a[class^='ref|']", g).mouseenter(function (e) {
        var c = $(this).attr("class").split('|');
        var d = $("<div></div>").addClass('reflinkpreview').attr({
            id: "preview" + $(this).attr("class"),
            style: "left:" + (e.pageX + 50) + "px;display:none;overflow:auto"
        });
        if ($('#postform [name=board]').val() == c[1] && $('#reply' + c[3]).length && (($('#thumb' + c[3]).length && $('#thumb' + c[3] + " img:first-child").attr("src").lastIndexOf("thumb") != -1) || !$('#thumb' + c[3]).length)) {
            var f = true;
            d.html($("#reply" + c[3]).parents("table").html())
        } else {
            $.get(ku_boardspath + '/ajax.php?act=read&board=' + c[1] + '&thread=' + c[2] + '&post=' + c[3] + '&single', {},
            function (a, b) {
                if (b != "success") {
                    alert('wut')
                } else { if (a) {
                        d.html(a).toggle("normal")
                    } else {
                        d.html(_("something went wrong (blank response)")).toggle("normal")
                    }
                }
            })
        }
        d.insertBefore($(this));
        if (f) d.toggle("normal")
    }).mouseleave(function (e) {
        var a = ($("div [id='preview" + $(this).attr("class") + "']"));
        if (a.length) {
            a.remove()
        }
    }).click(function (e) {
        var a = $(this).attr("class").split('|');
        return highlight(a[3], true)
    })
}
$(document).ready(function () {
	if ($("#main", top.document).length) {
		if( $.browser.opera  && $("base").length) {
		}
		if (getCookie("frameremoved") == 1) {
			top.document.title =  $(this).contents().find("title").html();
			$(this).contents().find(".navbar").after("<a id=\"toggleframe\"></a>");
			$(this).contents().find("#toggleframe").html("< Bring back frame").bind("click",
			function() {
				set_cookie('frameremoved', 0, 30);
				$(this).remove();
				frame = $("#main", top.document);
				frame.css("left", 0);
				frame.animate({
					left: (frame.width() * .15) + "px",
					"width": (frame.width() - frame.width() * .15) + "px"
				}, 1000, '');
			});
		}
	}
    if (getCookie("kumod") == "allboards") {
        kumod_set = true
    } else if (getCookie("kumod") != "") {
        var h = getCookie("kumod").split('|');
        var i = $("#postform [name=board]").val();
        for (var j in h) {
            if (h[j] == i) {
                kumod_set = true;
                break
            }
        }
    }
    delandbanlinks();
    addpreviewevents();
    checkhighlight();
    if ($('#watchedthreads').length) {
        $('#watchedthreads').draggable({
            handle: '#watchedthreadsdraghandle',
            opacity: 0.7,
            stop: function () {
                set_cookie('watchedthreadstop', $(this).css('top'), 30);
                set_cookie('watchedthreadsleft', $(this).css('left'), 30)
            }
        });
        $('#watchedthreads').resizable({
            minHeight: ($("#watchedthreadlist").attr('offsetHeight') + $("#watchedthreadsdraghandle").attr('offsetHeight') + $("#watchedthreadsbuttons").attr('offsetHeight')),
            stop: function () {
                set_cookie('watchedthreadswidth', $(this).width(), 30);
                set_cookie('watchedthreadsheight', $(this).height(), 30)
            }
        })
    }
	$('textarea').css({"background-image": "url('/css/images/resize.png')", "background-repeat" : "no-repeat", "background-position" : "bottom right", "resize" : "none"}).resizable({
		resize: function(event, ui) { $("#postform .ui-wrapper").css("height" , ($("#postform .ui-wrapper").height()-12))},
	});
	$("#postform textarea").parents(".ui-wrapper").css({"height": ($("#postform .ui-wrapper").height()-12)});
    $(this).keydown(function (e) {
        if (e.altKey) {
            var a = document.location.toString();
            if ((a.indexOf('catalog.html') == -1 && a.indexOf('/res/') == -1) || (a.indexOf('catalog.html') == -1 && e.keyCode == 80)) {
                if (e.keyCode != 18 && e.keyCode != 16) {
                    if (a.indexOf('.html') == -1 || a.indexOf('board.html') != -1) {
                        var b = 0;
                        var c = a.substr(0, a.lastIndexOf('/') + 1)
                    } else {
                        var b = a.substr((a.lastIndexOf('/') + 1));
                        b = (+b.substr(0, b.indexOf('.html')));
                        var c = a.substr(0, a.lastIndexOf('/') + 1)
                    }
                    if (b == 0) {
                        var d = c
                    } else {
                        var d = c + b + '.html'
                    }
                    if (e.keyCode == 222 || e.keyCode == 221) {
                        if (match = /#s([0-9])/.exec(a)) {
                            var f = (+match[1])
                        } else {
                            var f = -1
                        }
                        if (e.keyCode == 222) {
                            if (f == -1 || f == 9) {
                                var g = 0
                            } else {
                                var g = f + 1
                            }
                        } else if (e.keyCode == 221) {
                            if (f == -1 || f == 0) {
                                var g = 9
                            } else {
                                var g = f - 1
                            }
                        }
                        document.location.href = d + '#s' + g
                    } else if (e.keyCode == 59 || e.keyCode == 219) {
                        if (e.keyCode == 59) {
                            b = b + 1
                        } else if (e.keyCode == 219) {
                            if (b >= 1) {
                                b = b - 1
                            }
                        }
                        if (b == 0) {
                            document.location.href = c
                        } else {
                            document.location.href = c + b + '.html'
                        }
                    } else if (e.keyCode == 80) {
                        document.location.href = d + '#postbox'
                    }
                }
            }
        }
    });
    if (title == 'Nigrachan') {
        $("body").bind('mousemove.rainbow', function (e) {
			if( !loopid && $(e.target).is('a') ) {
				anchorobj = e.target;
				loopid = setInterval("colors()", 100)
			}
			else if (loopid && e.target != anchorobj) {
				clearInterval(loopid);
				$(anchorobj).css("color", '');
				loopid = 0;
			}
        });
    }

});

function colors() {
    $(anchorobj).css("color", makeColor())
}
function makeColor() {
    red = Math.sin(.3 * val + 0) * 127 + 128;
    green = Math.sin(.3 * val + 2) * 127 + 128;
    blue = Math.sin(.3 * val + 4) * 127 + 128;
    red = Math.floor(red).toString(16);
    green = Math.floor(green).toString(16);
    blue = Math.floor(blue).toString(16);
    if (red.length == 1) red = "0" + red;
    if (green.length == 1) green = "0" + green;
    if (blue.length == 1) blue = "0" + blue;
    val++;
    if (val >= 40) val = 0;
    return '#' + red + green + blue
}

