jQuery(function(b) {
var l = null,
p = null,
q = null,
f = null,
r = null,
k = null,
F = null,
s = null,
G = null,
e = null,
H = null,
h = null,
j = null,
I = null,
J = "",
K = null,
A = !1,
u = !1,
B = !1,
n = !0,
o = !0,
v = !1,
w = null,
L = null,
M = null,
V = document.title,
m = 0,
x = 0,
W = function() {
var a = f.val();
a.replace(/[\r\n]+/g, "");
if (a.replace(/^[ \n]+$/, "") == "") return a.replace(/^\n+$/, "") == "" && f.val(""), !1;
if (A) return !1;
var b = q.serialize();
if (a == J && confirm(t("Will you stop sending the same message? If you click 'Cancel' you can send it again."))) return f.val(""), !1;
f.val("");
A = !0;
s.val(t("Sending..."));
J = a;
a.length - 1 > messageMaxLength && (a = a.substring(0, messageMaxLength) + "...");
var d = y(L),
a = y(a),
i = '<dl class="talk" id="' + w + '">';
i += '<dt class="' + M + '">' + d + "</dt>";
i += '<dd><div class="bubble">';
i += '<p class="body ' + userColor + '">' + a + "</p>";
i += "</div></dd></dl>";
r.prepend(i);
N();
O();
P(b);
return !1
},
P = function(a) {
m > 10 ? location.href = location.href : b.ajax({
type: "POST",
url: l,
data: a,
success: function() {
m = 0;
A = !1;
s.val(t("POST!"))
},
error: function() {
m += 1;
b("<div />").delay(500).queue(function() {
P(a)
})
},
dataType: "text"
})
},
Q = function() {
m > 10 ? location.href = location.href : b.ajax({
type: "POST",
url: p + "?fast=1",
data: {},
success: function(a) {
m = 0;
B = !1;
C(a)
},
error: function() {
m += 1;
b("<div />").delay(1500).queue(function() {
Q()
})
},
dataType: "xml"
})
},
X = function() {
b.post(p + "?fast=1", {}, function(a) {
R();
C(a)
}, "xml")
},
R = function() {
b.post(p, {}, function(a) {
R();
C(a)
}, "xml")
},
C = function(a) {
var c = b(a).find("room > update").text() * 1;
if (K == c || h.is(":visible")) x = 0;
else {
var d = Y(a);
if (d != 0) {
if (x += 1, x > 3) u = !0, alert(d), location.href =
duraUrl
} else x = 0, K = c, c = b(a).find("room > name").text(), document.title = c + " | " + V, H.text(c), roomLimitElement.text(b(a).find("room > limit").text()), roomTotalElement.text(b(a).find("users").length), b.each(b(a).find("talks"), Z), $(a), b(a).find("host").text() == w ? e.find("li.setting").show() : e.find("li.setting").hide()
}
},
Z = function() {
var a = b(this).find("id").text();
if (!(b("#" + a).length > 0)) {
var c = g(b(this).find("uid").text()),
d = g(b(this).find("name").text()),
i = g(b(this).find("message").text()),
f = g(b(this).find("icon").text()),
e = g(b(this).find("color").text());
g(b(this).find("time").text());
d = y(d);
i = y(i);
c == 0 || c == "0" ? r.prepend('<div class="talk system" id="' + a + '">' + i + "</div>") : c != w && (a = '<dl class="talk" id="' + a + '">', a += '<dt class="' + f + '">' + d + "</dt>", a += '<dd><div class="bubble">', a += '<p class="body ' + e + '">' + i + "</p>", a += "</div></dd></dl>", r.prepend(a), N());
O()
}
},
$ = function(a) {
k.find("li").remove();
j.find("li").remove();
var c = b(a).find("users").length;
k.append("<li>(" + c + ")</li>");
var d = b(a).find("host").text();
b.each(b(a).find("users"),
function() {
var a = b(this).find("name").text(),
c = b(this).find("id").text(),
f = b(this).find("icon").text(),
e = "";
d == c && (e = " " + t("(host)"));
k.append("<li>" + a + e + "</li>");
d != c && (j.append("<li>" + a + "</li>"), j.find("li:last").css({
background: 'transparent url("' + duraUrl + "/css/icon/" + f + '.png") center top no-repeat'
}).attr("name", c).click(function() {
b(this).hasClass("select") ? (j.find("li").removeClass("select"), settingPannelButtons.attr("disabled", "disabled")) : (j.find("li").removeClass("select"), b(this).addClass("select"),
settingPannelButtons.removeAttr("disabled"))
}))
});
S()
},
Y = function(a) {
a = b(a).find("error").text() * 1;
if (!(a == 0 || u))
if (a == 1) return t("Session time out.");
else if (a == 2) return t("Room was deleted.");
else if (a == 3) return t("Login error.");
return 0
},
N = function() {
var a = b(".bubble .body:first"),
c = a.parent(),
d = a.width() + "px",
e = a.height() + "px",
f = 5 + a.width() + "px",
g = 5 + a.height() + "px";
if (o) try {
messageSound.play()
} catch (h) {}
n ? (b("dl.talk:first dt").click(T), b.each(c, D), c.css({
opacity: "0",
width: "0px",
height: "0px"
}),
c.animate({
opacity: 1,
width: "22px",
height: "16px"
}, 200, "easeInQuart"), a.css({
"border-width": "0px",
"font-size": "0px",
"text-indent": "-100000px",
opacity: "0",
width: "0px",
height: "0px"
}), a.animate({
fontSize: "1em",
borderWidth: "4px",
width: f,
height: g,
opacity: 1,
textIndent: 0
}, 200, "easeInQuart", function() {
b.each(a, E);
a.animate({
width: d,
height: e
}, 100)
})) : (b.each(c, D), b.each(a, E))
},
y = function(a) {
a = a.replace(/&/g, "&");
a = a.replace(/"/g, """);
a = a.replace(/'/g, "'");
a = a.replace(/</g, "<");
return a = a.replace(/>/g,
">")
},
aa = function() {
var a = f.val();
if (a != a.replace(/[\r\n]+/g, "")) return q.submit(), !1
},
ba = function() {
u = !0;
b("*").hide();
b.post(l, {
logout: "logout"
}, function() {
location.href = duraUrl
})
},
O = function() {
if (b(".talk").length > 50)
for (; b(".talk").length > 50;) b(".talk:last").remove()
},
S = function() {
k.find("li:not(:last)").each(function() {
b(this).append(", ")
})
},
T = function() {
var a = b(this).text(),
c = f.val();
f.focus();
c.length > 0 ? f.val(c + " @" + a) : f.val(c + "@" + a + " ")
},
g = function(a) {
return a = a.replace(/^\s+|\s+$/g, "")
},
E = function() {},
D = function() {
var a = b(this).find(".body").height() + 30 + 8,
a = (Math.round((180 - a) / 2) + 23) * -1,
c = b(this).find(".body").css("background-image"),
d = "0px";
Math.floor(Math.random() * 2) == 1 && (d = "-17px");
a += 1;
b(this).find(".body").css({
margin: "0 0 0 15px"
});
b(this).prepend("<div><div></div></div>").css({
margin: "-16px 0 0 0"
});
b(this).children("div").css({
position: "relative",
"float": "left",
margin: "0 0 0 0",
top: "39px",
left: "-3px",
width: "22px",
height: "16px",
background: "transparent " + c + " left " + a + "px repeat-x"
});
b(this).children("div").children("div").css({
width: "100%",
height: "100%",
background: "transparent url('" + duraUrl + "/css/tail.png') left " + d + " no-repeat"
})
},
ca = function() {
e.find("li:hidden:not(.setting)").show();
var a = o ? "sound_on" : "sound_off",
b = v ? "member_on" : "member_off",
d = n ? "animation_on" : "animation_off";
e.find("li.sound").addClass(a);
e.find("li.member").addClass(b);
e.find("li.animation").addClass(d)
},
da = function() {
o ? (b(this).removeClass("sound_on"), b(this).addClass("sound_off"), o = !1) : (b(this).removeClass("sound_off"),
b(this).addClass("sound_on"), o = !0)
},
ea = function() {
v ? (b(this).removeClass("member_on"), b(this).addClass("member_off"), k.slideUp("slow"), v = !1) : (b(this).removeClass("member_off"), b(this).addClass("member_on"), k.slideDown("slow"), v = !0)
},
fa = function() {
n ? (b(this).removeClass("animation_on"), b(this).addClass("animation_off"), n = !1) : (b(this).removeClass("animation_off"), b(this).addClass("animation_on"), n = !0)
},
z = function() {
settingPannelButtons.attr("disabled", "disabled");
s.slideToggle();
I.slideToggle();
h.slideToggle()
},
ga = function() {
var a = h.find("input[name=room_name]").val(),
c = h.find("select[name=limit]").val();
b.post(l, {
room_name: a,
limit: c
}, function(a) {
alert(a);
z()
})
},
ha = function() {
var a = j.find("li.select").attr("name");
confirm(t("Are you sure to handover host rights?")) && b.post(l, {
new_host: a
}, function(a) {
alert(a);
z()
})
},
ia = function() {
U(!1, t("Are you sure to kick this user?"))
},
ja = function() {
U(!0, t("Are you sure to ban this user?"))
},
U = function(a, c) {
var d;
d = j.find("li.select").attr("name");
confirm(c) && (d = a == !0 ? {
ban_user: d,
block: 1
} : {
ban_user: d
}, b.post(l, d, function(a) {
alert(a);
z()
}))
};
(function() {
var a = location.href.replace(/#/, "");
l = a.replace(/\?/, "") != a ? a + "&ajax=1" : a + "?ajax=1";
p = duraUrl + "/ajax.php";
q = b("#message");
f = b("#message textarea");
r = b("#talks");
k = b("#members");
F = b("input[name=logout]");
s = b("input[name=post]");
G = b("dl.talk dt");
e = b("ul.menu");
H = b("#room_name");
roomLimitElement = b("#room_limit");
roomTotalElement = b("#room_total");
h = b("#setting_pannel");
j = b("#user_list");
settingPannelButtons = b("input[name=handover], input[name=ban], input[name=block]");
I = b(".messageInput");
w = g(b("#user_id").text());
L = g(b("#user_name").text());
M = g(b("#user_icon").text());
userColor = g(b("#user_color").text());
messageMaxLength = 140;
typeof GlobalMessageMaxLength != "undefined" && (messageMaxLength = GlobalMessageMaxLength);
q.submit(W);
f.keyup(aa);
F.click(ba);
G.click(T);
e.find("li.sound").click(da);
e.find("li.member").click(ea);
e.find("li.animation").click(fa);
e.find("li.setting").click(z);
h.find("input[name=save]").click(ga);
h.find("input[name=handover]").click(ha);
h.find("input[name=ban]").click(ia);
h.find("input[name=block]").click(ja);
S();
b("#talks dl.talk dd div.bubble p.body").each(E);
ca();
useComet ? X() : setInterval(function() {
!B && !u && (B = !0, Q())
}, 1500);
b.each(b(".bubble"), D)
})()
});