/*
 *  © 2000-2005 deviantART, Inc. All rights reserved.
 */


var
deviantART = {},
DA_DEVIANT_SYMBOLS = "~*`:^%+$;="
;
deviantART.loggedIn = true;
window.deviantART = deviantART;
var browser={isKHTML: false, isGecko: false, isIE: false, isIE5: false, isIE55: false, isWin: false, isOpera: false, isOpera75: false, isSafe:null};
with (browser) {
isKHTML =
navigator.userAgent.indexOf("KHTML")>=0;
isGecko =
(!isKHTML) &&
navigator.product == "Gecko";
isIE =
(!isGecko) &&
navigator.cpuClass != undefined &&
navigator.appName == "Microsoft Internet Explorer";
isIE5 =
isIE && (!Function.apply);
isIE55 =
isIE && (document.onmousewheel == undefined);
isOpera =
(!(isIE || isGecko || isKHTML)) &&
document.attachEvent != undefined;
if (isOpera){
isOpera75 = (!/Opera[^0-9]*(?:[1-6]|[7\.[1-4]])/.test(navigator.userAgent));
}
isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
isSafe =
document.getElementById != undefined &&
(!isIE5) &&
(document.addEventListener != undefined ||
document.attachEvent != undefined);
}
function forEachItem(items, call, nonLinear)
{
if (nonLinear == true){
for (var i in items)
if (call(items[i], i) == -1)
return;
}else if((items.length != undefined) && (typeof items) != 'string'){
for (var i=0; items[i]; i++)
if (call(items[i], i) == -1)
return;
}else{
call(items, 0);
}
}
function forEachItemOptimal(items, call) {
var i = -1;
var iterations = items.length;
var n = iterations % 8;
while (n--)
{
call(items[++i], i);
}
n = parseInt(iterations / 8);
while (n--)
{
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
call(items[++i], i);
}
}
function findItem(items, check, nonLinear)
{
var match = -1;
forEachItem(
items,
function(item, i){
if (item == check){
match = i;
return -1;
}
},
nonLinear
);
return match;
}
function findEntry(items, entry, check, nonLinear)
{
var match = null;
forEachItem(
items,
function(item){
if (item[entry] == check){
match = item;
return -1;
}
},
nonLinear
);
return match;
}
function containsItem(items, check, nonLinear){
return findItem(items, check, nonLinear)>=0;
}
function containsEntry(items, entry, check, nonLinear){
return findEntry(items, entry, check, nonLinear)!=null;
}
function massSet(items, property, value)
{
forEachItem(
items,
function(item){
items[property] = value;
}
);
}
function mergeObjects(a, b)
{
var i;
for (i in b){
a[i] = b[i];
}
}
function setCookie(sName, sSetting)
{
var tStore = new Date();
document.cookie =
sName+ "="+ sSetting+ "; "+
"expires=7 Aug, "+ String(tStore.getFullYear() + 1)+ " 13:33:37 GMT; "+
"path=/; domain=deviantart.com"
;
delete tStore;
}
function getCookie(sName, sDefault)
{
var m = (
document.cookie+ "; "+
sName+ "="+ (sDefault || "")+ ";"
).match(RegExp("\\b" + sName + "=(.*?);"));
return m ? m[1] : null;
}
function isArray(o)
{
return (o.length && o.reverse);
}
function trimWhiteSpace(s)
{
s = String(s);  
s = s.replace(/^\s+/, '');
s = s.replace(/\s+$/, '');
s = s.replace(/\s+/g, ' ');
return s;
}
function prettyNumber(num){
var i, r;
num = String(num);
r = (3 - ((num.length) % 3)) % 3;
for(i = 1; i <= r; i++){
num = '0' + num;
}
num = num.replace(/(\d\d\d(?!$))/g, "$1,");
num = num.substr(r);
return num;
}
function getCurrentTime()
{
return (new Date()).valueOf();
}
function getDAAvatarURL(link){
var s, a;
if ((typeof link) != "string"){
a = getElement(link, "img");
if (a){
return a.getAttribute("src");
}
link = link.getAttribute("href");
}
s = getDeviantNameFromURI(link);
s =
"ht"+"tp://a.deviantart.com/avatars/" +
s.charAt(0) +
"/" +
s.charAt(1) +
"/" +
s +
".gif"  
;
return s;
}
function getDeviantMETA()
{
var meta = document.getElementsByName("deviantMETA")[0];
if (meta) {
return eval("meta="+meta.getAttribute("content"));
} else {
return {}
}
}
String.prototype.encode = function ()
{
var str = escape(this);
str = str.replace(/\+/g, "%2B");
str = str.replace(/\%u([\dABCDEF]{4})/g, "%26%23x$1%3B");
return str;
}
function getDeviantNameFromURI(sURI)
{
var match;
match = sURI.match(/^ht{2}p:\/\/(.+)\.deviantart\.com\/?$/i);
return match && match[1] ? match[1].toLowerCase() : sURI;
}
getDeviantNameFromURL = getDeviantNameFromURI;
function getCurrentDeviant()
{
var links = getElements(getElement("#bar-deviant"), "a"), a = links[0];
if (a && getDALinkType(a) != "deviant"){
a = links[1];
}
if (a && getDALinkType(a) == "deviant"){
var d, t;
d = getNodeText(a);
t = a.previousSibling.nodeValue;
return {
name: d,
username: d.toLowerCase(),
symbol: t.charAt(t.length-1),
href: "ht{2}p://" + d.toLowerCase() + ".deviantart.com/",
avatarSrc: getDAAvatarURL(d)
}
}
return null;
}
function newThread(f, delay)
{
setTimeout(f, delay || 1);
}
var flashVersion = 0;
function getFlashVersion() {
var latestFlashVersion = 8;
var agent = navigator.userAgent.toLowerCase(); 
if (navigator.plugins != null && navigator.plugins.length > 0) {
var flashPlugin = navigator.plugins['Shockwave Flash'];
if (typeof flashPlugin == 'object') { 
for (var i = latestFlashVersion; i >= 3; i--) {
if (flashPlugin.description.indexOf(i + '.') != -1) {
flashVersion = i;
break;
}
}
}
}
else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
var doc = '<scr' + 'ipt language="VBScript"\> \n\n';
doc += 'On Error Resume Next \n';
doc += 'Dim obFlash \n';
doc += 'For i = ' + latestFlashVersion + ' To 3 Step -1 \n';
doc += '   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n';
doc += '   If IsObject(obFlash) Then \n';
doc += '      flashVersion = i \n';
doc += '      Exit For \n';
doc += '   End If \n';
doc += 'Next \n';
doc += '</scr' + 'ipt\> \n';
document.write(doc);
}
else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;
else if (agent.indexOf("webtv") != -1) flashVersion = 2;
else {
flashVersion = flashVersion_DONTKNOW;
}
return flashVersion;
}
flashVersion_DONTKNOW = -1;
browser.flashVersion = getFlashVersion();
browser.hasFlash = (browser.flashVersion > 0);
deviantART.application = "Main";
if (location.href.indexOf("my.deviantart.com/messages") > 0) {
deviantART.isMessageCenter = true;
}
else if (location.href.indexOf("my.deviantart.com/devwatch") > 0) {
deviantART.isDevWatch = true;
} 
else if (location.href.indexOf("forum.deviantart.com") > 0) {
deviantART.application = deviantART.isForum = "Forum";
}
else if (location.href.indexOf("/forum/") > 0) {
deviantART.application = deviantART.isForum = deviantART.isUserForum = "Forum";
}
else if (location.href.indexOf("/help/") > 0) {
deviantART.isHelp = deviantART.application = "Help";
}
else if (location.href.indexOf("/gallery/") > 0) {
deviantART.isGallery = deviantART.application = "Gallery";
}
else if (location.href.indexOf("file:///") == 0) {
deviantART.isLocal = true;
}
String.prototype.toNumber = function () {
return parseFloat(this.replace(/[^\d\\.]/gi, ""));
}
ForEachItem		= forEachItem;
ReadCookie		= getCookie;
SetCookie		= setCookie;
Trim			= trimWhiteSpace;
var KHTML 	= browser.isKHTML;
var Gecko 	= browser.isGecko;
var IE 		= browser.isIE;
var IE5 	= browser.isIE5;
var Opera 	= browser.isOpera;
var Safe 	= browser.isSafe;
var Subcategories = null;

var _customEventHandlers = Array();
function registerCustomEvent(sEvent)
{
if (!(sEvent in _customEventHandlers)){
_customEventHandlers[sEvent] = Array();
}
}
function fireCustomEvent(node, sEvent, eventInfo, outputDebug)
{
var
ret = true,
bubble = true,
e = {
currentTarget: node,
target: null,  
timeStamp: 0,
type: sEvent,
bubbles: true,
stopPropogation: function(){
bubble = false;
},
cancelable: true,
preventDefault: function(){
if (e.cancelable){
ret = false;
}
}
}
;
if (eventInfo){
mergeObjects(e, eventInfo);
}
forEachItem(
_customEventHandlers[sEvent],
function(handler){
forEachAncestor(
handler.node,
function(handlerNode){
if (handlerNode == node){
e.target = handlerNode;
if (outputDebug){
startWatch("Event "+handler.debug);
}
handler.call(e);
if (outputDebug){
outputDebug(handler.debug, stopWatchValue("Event "+handler.debug));
}
if (!bubble)
return -1;
}
}
);
}
);
return ret;
}
function hookEvent(node, sEvent, call, capture, sDebug)
{
if (sEvent in _customEventHandlers){
_customEventHandlers[sEvent].push({node:node, call:call, debug:sDebug});
return;
}else if (node.addEventListener) {
node.addEventListener(sEvent, call, capture || false);
}else if (node.attachEvent) {
node.attachEvent("on"+sEvent, call);
}
if (eventHooks){
eventHooks.push({node:node, event:sEvent, call:call, capture:capture});
}
}
function unhookEvent(node, sEvent, call, capture)
{
if (sEvent in _customEventHandlers){
var e;
e = _customEventHandlers[sEvent];
forEachItem(
e,
function(h, i){
if (h.node==node && h.call==call){
e.splice(i, 1);
}
}
);
return;
}else if (node.removeEventListener) {
node.removeEventListener(sEvent, call, capture || false);
}else if (node.detachEvent) {
node.detachEvent("on"+event, call);
}
if (eventHooks){
forEachItem(
eventHooks,
function(hook, i){
if(
(!hook)
|| hook.node	 != node
|| hook.event	 != sEvent
|| hook.call	 != call
|| hook.capture	 != capture
)
return;
eventHooks[i] = null;
}
);
}
}
function nullEvent()
{
return false;
}
function cancelEvent(e)
{
if (e.cancelable){
if (browser.isKHTML && e.type == "click"){
var l, f;
l = getAncestor(e.target, "a");
if (l){
f = l.onclick || null;
l.onclick = nullEvent;
setTimeout(function(){ l.onclick = f; }, 1);
}
}
e.preventDefault();
}else{
e.returnValue = false;
}
return false;
}
function stopEvent(e)
{
if (e.bubbles && e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
return e;
}
function getMouseCoords(e)
{
return { x: e.clientX, y: e.clientY }
}
function getEventTarget(e)
{
return (e.srcElement || e.target);
}
function unloadEventHooks()
{
forEachItem(
eventHooks,
function(hook, i){
if (!hook)
return;
if (hook.node.removeEventListener){
hook.node.removeEventListener(hook.event, hook.call, hook.capture);
eventHooks[i] = null;
}else{
hook.node.detachEvent("on"+hook.event, hook.call);
}
}
);
}
var eventHooks;
if (browser.isIE || browser.isGecko){
eventHooks = Array();
}
function unloadEvent()
{
fireCustomEvent(deviantART, "enterstasis");
if (eventHooks)
unloadEventHooks();
}
hookEvent(window, "unload", unloadEvent);
registerCustomEvent("canvasready");
registerCustomEvent("applicationready");
registerCustomEvent("enterstasis");
registerCustomEvent("leavestasis");
function _readyStateCanvasCheck()
{
if (document.body){
clearInterval(deviantART._readyStateTimer);
fireCustomEvent(deviantART, "canvasready");
fireCustomEvent(deviantART, "leavestasis");
deviantART._readyStateTimer = setInterval(_readyStateApplicationCheck, 250);
}
}
function _readyStateApplicationCheck()
{
if (document.getElementById("deviantART-loves-you") || document.readyState=="complete"){
clearInterval(deviantART._readyStateTimer);
if (deviantART.debug){
startWatch("ApplicationReady Fire");
fireCustomEvent(deviantART, "applicationready", null, _applicationReadyDebugStep);
_applicationReadyDebugFlush(stopWatchValue("ApplicationReady Fire"));
}else{
fireCustomEvent(deviantART, "applicationready");
}
}
}
deviantART._readyStateTimer = setInterval(_readyStateCanvasCheck, 100);
function CatchEvent(node, sEvent, call, passEvent, capture)
{
if(passEvent){
return hookEvent(node, sEvent, call, capture);
}else{
var f;
if (node.addEventListener) {
node.addEventListener(
sEvent,
f=function(e) {
var r = call(node);
if (!r && e.cancelable)
e.preventDefault();
return r;
},
capture || false
);
}else if (node.attachEvent) {
node.attachEvent(
"on"+sEvent,
f=function(e) {
return call(node);
}
);
}
if (eventHooks){
eventHooks.push({node:node, event:sEvent, call:f, capture:capture});
}
}
}
CancelEvent = cancelEvent;
GetMousePos = getMouseCoords;
GetEventTarget = getEventTarget;


var
AJAX_PREFIX = "/global"
AJAX_SUFFIX = ""
;
function forEachAncestor(node, call)
{
var top = (node.ownerDocument || document).documentElement;
do{
if (call(node) == -1)
return;
}while(node.parentNode && (node = node.parentNode) != top)
}
var
SETNODECONTENTS_REPLACE = 0,
SETNODECONTENTS_APPEND = 1,
SETNODECONTENTS_PREPEND = 2
;
function setNodeContents(node, sXML, position)
{
if ((node.innerHTML != undefined) && ((!position) || node.insertAdjacentHTML != undefined)) {
if (position){
node.insertAdjacentHTML(position == SETNODECONTENTS_APPEND ? "BeforeEnd" : "AfterBegin", sXML);
}else{
node.innerHTML = sXML;
}
}else{
var r = node.ownerDocument.createRange();
if (position) {
if (position == SETNODECONTENTS_APPEND)
r.setStartBefore(node.firstChild);
else
r.setStartAfter(node.lastChild);
}else{
r.selectNodeContents(node);
r.deleteContents();
}
if (position == SETNODECONTENTS_PREPEND && node.childNodes.length>0){
node.insertBefore(r.createContextualFragment(sXML), node.firstChild);
}else{
node.appendChild(r.createContextualFragment(sXML));
}
}
}
function getNodeContents(node)
{
if (node.innerHTML != undefined)
return (node.innerHTML || "");
var sText;
sText = "<"+ getTag(node);
forEachItem(
node.attributes,
function(attribute) {
if (browser.isIE && attribute.value == null)
return; // Necessary? IE should always return Node.innerHTML above
sText += ' '+ attribute.name.toLowerCase()+ '="'+ attribute.value+ '"';
}
);
sText+=">";
forEachItem(
node.childNodes,
function(node) {
sText += (node.nodeValue || getNodeContents(Node));
}
);
sText += "</"+ getTag(node)+ ">";
return sText;
}
function getNodeText(Node)
{
var sText = "";
if (getTag(Node)=="br")
return "\n";
ForEachItem(
Node.childNodes,
function(Node) {
sText+=
Node.nodeValue?
Node.nodeValue:
getNodeText(Node);
}
);
return sText;
}
function setNodeText(node, sText)
{
while (node.childNodes[0])
node.removeChild(node.childNodes[0]);
node.appendChild((node.ownerDocument || node.document).createTextNode(sText));
}
function getTag(node)
{
return String(node.tagName).toLowerCase();
}
function getNodeRect(node, noScrollAdjust)
{
var
rect = {x:0, y:0, x2:0, y2:0},
same = false, fixed = false, top = (node.ownerDocument || node.document)
;
if (node.offsetWidth) {
rect.x2 = node.offsetWidth;
rect.y2 = node.offsetHeight;
}else if (window.getComputedStyle) {
with (getComputedStyle(node, "")){
rect.x2 = parseInt(getPropertyValue("width"));
rect.y2 = parseInt(getPropertyValue("height"));
}
}else return undefined;  
while (node && node != top) {
if ((!browser.isIE) && getComputedStyle(node, "").position == "fixed"){
fixed = true;
}
if (fixed || !same){
rect.x += node.offsetLeft;
rect.y += node.offsetTop;
}
if (!(noScrollAdjust || fixed)){
if (node.scrollTop != undefined) {
rect.x -= node.scrollLeft;
rect.y -= node.scrollTop;
}
}
if (browser.isGecko && !fixed){
same = node.parentNode != node.offsetParent;
node = node.parentNode;
}else{
node = node.offsetParent;
}
}
rect.x2 += rect.x;
rect.y2 += rect.y;
return rect;
}
function getNodeDocumentRect(node)
{
return getNodeRect(node, true);
}
function appendNode(node, after){
if (after.nextSibling){
return after.parentNode.insertBefore(node, after.nextSibling);
}else{
return after.parentNode.appendChild(node);
}
}
function removeNode(node){
return node.parentNode.removeChild(node);
}
var RgCSS = /^([^\.:\[]*)(?:\.([^:\[]*)|([^:\[]*))(?:\[([^\]]*)\]|([^:]*))$/;
function getElements(node, sSelector, max)
{
var sTokens, nodes, returns = Array();
if (typeof(node) == 'string' ){
max = sSelector;
sSelector = node;
node = document;
}
if (!max){
max = 10000;  
}
sTokens = sSelector.match(RgCSS);
if (sTokens[1] == ""){
sTokens[1] = "*";
}
if ((browser.isIE5 || browser.isIE55) && sTokens[1] == "*"){
nodes = node.all;
}else{
nodes = node.getElementsByTagName(sTokens[1]);
}
if (!sTokens[2])  
return nodes;
forEachItem(
nodes,
function(node, i) {
if (!hasClass(node, sTokens[2]))
return;
returns.push(node);
if(returns.length == max)
return -1;
}
);
return returns;
}
function getElement(node, sSelector){
if (typeof(node) == 'string' ){
sSelector = node;
node = document;
}
if (sSelector.charAt(0) == '#' ){
return node.getElementById(sSelector.substr(1));
}else{
return getElements(node, sSelector, 1)[0] || null;
}
}
function getChildNodes(node) {
var childNodes = node.childNodes;
var ar = new Array();
for (var i = 0; i < childNodes.length; i++) {
if (childNodes[i].nodeType == 1) ar[ar.length] = childNodes[i];
}
return ar;
}
function getAncestor(node, sSelector)
{
var sTokens, nodes, top = (node.ownerDocument || node.document).documentElement;
sTokens = sSelector.match(RgCSS);
if (!sTokens[2]) {
sTokens[2] = "";
}
do {
if (sTokens[1] != "" && getTag(node) != sTokens[1])
continue;
if (sTokens[2] != "" && !hasClass(node, sTokens[2]))
continue;
return node;
} while ((node = node.parentNode) && node != top);
return null;
}
function getNextSibling(node)
{
while (node = node.nextSibling){
if (node.nodeValue == null)
return node;
}
return null;
}
function getPreviousSibling(node)
{
while (node = node.previousSibling)
if (node.nodeValue == null)
return node;
return null;
}
function getFirstChild(node)
{
node = node.firstChild;
if (node.nodeValue == null)
return node;
return getNextSibling(node);
}
function getLastChild(node)
{
node = node.lastChild;
if (node.nodeValue == null)
return node;
return getPreviousSibling(node);
}
function setClass(node, className)
{
if (!hasClass(node, className)){
node.className += " "+ className;
}
}
function unsetClass(node, className)
{
node.className = node.className.replace( RegExp('\\b'+className+'\\b', 'g'), '');
}
function hasClass(check, className)
{
if (typeof(check) != 'string'){
check = check.className;
}
return ((' '+check+' ').indexOf(' '+className+' ') >= 0);
}
if (browser.isIE && !window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
return new ActiveXObject((browser.isIE55 ? "Microsoft" : "Msxml2") + ".XMLHTTP");
};
}
function _khtmlSelectNodes(select)
{
if (/^\/\/[^\/]*$/.test(select)){
return this.getElementsByTagName(select.substr(2));
}else{
return null;
}
}
function _khtmlSelectSingleNode(select)
{
var e = this.selectNodes(select);
if (e && e.length)
return e[0];
else
return null;
}
function _xmlhttprequestPrepare(r, method, uri, contentType, data, callback, userData)
{
uri = uri.replace(/^dAjax:\/{0,2}(.*)$/i, AJAX_PREFIX+ "/$1" +AJAX_SUFFIX);
if (method == "GET") {
if (uri.indexOf("?") < 0) uri += "?";
uri += data;
}
if (deviantART.isLocal && uri.indexOf("http") != 0) uri = "ht"+"tp://www.deviantart.com" + uri;
r.open(method, uri);
r.onreadystatechange = function () {
if(r.readyState == 4){
if (browser.isKHTML && !window.XMLDocument){
r.responseXML.selectNodes = _khtmlSelectNodes;
r.responseXML.selectSingleNode = _khtmlSelectSingleNode;
}
callback(r, uri, userData);
if (deviantART.debug){
Log({
type : "XMLHTTP Response", responseHeaders: r.getAllResponseHeaders(), 
status : r.status, responseXML: r.responseXML, responseText: r.responseText, uri: uri
});
}
}
return true;
}
if (deviantART.debug) {
Log({
type: "XMLHTTP Request", method : method, uri : uri, data : data, 
contentType : contentType, callBack : callback, userData : userData
});
}
if (!browser.isOpera) r.setRequestHeader("Content-Type", contentType);
return r.send(data);
}
function xmlhttpGet(r, uri, contentType, data, callback, userData)
{
return _xmlhttprequestPrepare(r, "GET", uri, contentType, data, callback, userData);
}
function xmlhttpPost(r, uri, contentType, data, callback, userData)
{
return _xmlhttprequestPrepare(r, "POST", uri, contentType, data, callback, userData);
}
if (!browser.isIE) try{
if (!XMLDocument.prototype.selectSingleNode){
XMLDocument.prototype.selectSingleNode = function (sExpression) {
return this.selectNodes(sExpression)[0];
}
}
if (!XMLDocument.prototype.selectNodes){
XMLDocument.prototype.selectNodes = function (sExpression) {
var oDoc = this.ownerDocument || this;
var xPathResult = oDoc.evaluate(sExpression, this, null, 0, null);
var aTemp = new Array();
while (oMatch = xPathResult.iterateNext()) {
aTemp.push(oMatch);
}
return aTemp;
}
}
function _xmlSerialize(oXml) {
return (new XMLSerializer()).serializeToString(oXml || this);
}
XMLDocument.prototype.__defineGetter__("xml", _xmlSerialize);
Element.prototype.__defineGetter__("xml", _xmlSerialize);
}catch (e){}
function getXMLNodeValue(xml, xpath) {
return xml.responseXML.selectSingleNode(xpath).firstChild.nodeValue;
}
function hasXMLError (r, expectedNode) {
var error = false;
if (!r.responseXML) {
error = "Server did not return proper response.";
if (r.responseText) error += "\n" + r.responseText.substring(0, 100);
}
else if (r.responseXML.selectSingleNode("//error")) {
error = "An error occured.";
error += getXMLNodeValue(r, "//error");
}
else if (!r.responseXML.selectSingleNode(expectedNode)) {
error = "Server did not return proper response";
}
return error;
}
_forcePageLayout = function ()
{
if (browser.isGecko || browser.isOpera) {
document.body.style.height = "1px";
document.body.style.height = "auto";
}
else if (!browser.isKHTML) {
document.body.style.display = "none";
document.body.style.display = "block";
}
}
function GetNodePos(node)
{
var r = getNodeRect(node);
return {x: r.x, y: r.y};
}
GetNodeContents				= getNodeContents;
SetNodeContents				= setNodeContents;
GetNodeText					= getNodeText;
SetNodeText					= setNodeText;
GetTag						= getTag;
GetElements					= getElements;
GetAncestor					= getAncestor;
GetNextSiblingElement 		= getNextSibling;
GetPreviousSiblingElement 	= getNextSibling;
GetFirstChildElement 		= getFirstChild;
SetClass					= setClass;
UnsetClass					= unsetClass;
HasClass					= hasClass;

function layoutFlush()
{
void(document.body.offsetHeight);
}
function layoutKick()
{
;
}
function forEachStyleRule(x, call)
{
if (x.styleSheets){
x = x.styleSheets;
for (var i=0; i!=x.length; i++){
if (forEachStyleRule(x[i].cssRules, call) == -1)
return -1;
}
}else{
if (x.cssRules){
x = x.cssRules;
}
for (var i=0; i!=x.length; i++){
if (x[i].styleSheet){
if (forEachStyleRule(x[i].styleSheet, call) == -1)
return -1;
}else{
if (call(x[i]) == -1)
return -1;
}
}
}
}
function _setStyle_IE_SetFixedScrolling(node, on){
if (!on){
forEachItem(
document.body.childNodes,
function(check){
if (
check.DApositionFixedPatch
&&
check!=node  
&&
getStyle(check, "display")!="none"
){
on = true;
return -1;
}
}
);
}
if (on != hasClass(document.body, "ie-positionfix")){
var t, scrollRegion = document.getElementById("body"), f;
if (on){
t = document.body.scrollTop;
document.body.scrollTop = 0;
setClass(document.body, "ie-positionfix");
if (!(f = document.getElementById("ieforcefocus"))){
f = document.createElement("input");
f.type = "checkbox";
f.id = "ieforcefocus";
scrollRegion.insertBefore(f, scrollRegion.firstChild);
}
f.style.display="inline";
f.focus();
f.style.display="none";
scrollRegion.scrollTop = t;
}else{
node.runtimeStyle.display = "none";
t = scrollRegion.scrollTop;
document.body.scrollTop = 0;
unsetClass(document.body, "ie-positionfix");
document.body.scrollTop = t;
}
}
}
function setStyle_IE(node, property, value)
{
if (node == null) return;
if (property == "opacity"){
return;
if(node.filters.alpha){
node.filters.alpha.opacity = value*100;
}else{
node.runtimeStyle.setAttribute("position", "relative");
node.runtimeStyle.setAttribute("filter", "alpha(opacity="+ Math.round(value*100) +")");
}
}else{
if (property == "display"){
if (node.DAoverlayGhostPatch){
if (value == "none"){
unhookEvent(document, "scroll", cancelEvent);
}else{
node.runtimeStyle.top = document.body.scrollTop;
hookEvent(document, "scroll", cancelEvent);
}
}else if (node.DApositionFixedPatch){
_setStyle_IE_SetFixedScrolling(node, value!="none");
}
}
else if (
value==0
&&
(property == "right" || property == "bottom")
){
if (getStyle(node, "position") == "absolute"){
property = (property=="right") ? "width" : "height";
value = "100%";
}
}
else if (property == "position"){
if (value == "fixed"){
value = "absolute";
if (node.parentNode){  
node.parendNode = document.body;
}
node.DApositionFixedPatch = true;  
if (getStyle(node, "display")!="none"){
_setStyle_IE_SetFixedScrolling(node, true);
}
}
}
node.runtimeStyle.setAttribute(property, value);
}
}
function getStyle_IE(node, property)
{
if (property=="opacity"){
return 1;
return parseInt(node.filters.alpha.opacity)/100;
}else{
return node.runtimeStyle[property] || node.currentStyle[property];
}
}
function setStyle_DOM(node, property, value)
{
if (node == null) return;
if (property == "opacity" && browser.isGecko){
if (node.style.opacity == undefined){
property = "-moz-opacity";
}
if (value == 1){
geckoFlickerFix(node);
value = .99;
}//else Debug(value);
} else if (property == "display") {
if (node.DAoverlayGhostPatch && value != "none") {
node.style.top = window.pageYOffset + "px";
node.style.bottom =
(
(browser.isKHTML ? 0 : parseInt(getComputedStyle(node, "").bottom))
-
window.pageYOffset
) + "px";
}
}
node.style[property] = value;
}
function getStyle_DOM(node, property)
{
property = property.replace(/([A-Z])/g, '-$1');
return getComputedStyle(node, "").getPropertyValue(property);
}
function holdStyle(node, sAttr)
{
setStyle(node, sAttr, getStyle(node, sAttr));
}
function removeStyle(node, sAttr)
{
node.style.removeProperty(sAttr);
}
var _geckoFlickerFixes = Array();
function geckoFlickerFix(node)
{
if(!_geckoFlickerFixes.length){
hookEvent(document.documentElement, "scroll", _geckoFlickerFixFlush);
hookEvent(document.documentElement, "mousewheel", _geckoFlickerFixFlush);
}
_geckoFlickerFixes.push(node);
}
function _geckoFlickerFixFlush()
{
forEachItem(
_geckoFlickerFixes,
function(node){
node.style.removeProperty("opacity");
}
);
_geckoFlickerFixes.length = 0;
unhookEvent(document.documentElement, "scroll", _geckoFlickerFixFlush);
unhookEvent(document.documentElement, "mousewheel", _geckoFlickerFixFlush);
}
function setBusy(node, on){
forEachItem(node, function(node){
node.disabled = on;
if (on){
setStyle(node, "cursor", "wait");
}else{
setStyle(node, "cursor", "auto");
}
});
}
if (browser.isIE){
setStyle = setStyle_IE;
getStyle = getStyle_IE;
}else{
setStyle = setStyle_DOM;
getStyle = getStyle_DOM;
}
function setStyles (node, properties) {
var blank = new Object(); // in case of prototypes later on
for (var i in properties) {
if (!blank[i]) setStyle(node, i, properties[i]);
}
}
var _styleStack = Array();
function pushStyle(node, property, value)
{
var a, p;
a = findEntry(_styleStack, 'node', node);
if (!a){
a =  { node: node };
_styleStack.push( a );
}
if (!a[property]){
a[property] = Array();
}
a[property].push(value);
}
function popStyleValue(node, property, value)
{
try{
return findEntry(_styleStack, 'node', node)[property].pop();
}catch(e){
return null;
}
}
function popStyle(node, property, value)
{
setStyle(node, property, popStyleValue(node, property, value));
}
var _cachedShadowPath;
function addShadow(n, forceTransparency)
{
var
sBg,  
sImg,  
Size  
;
if (n.type == 'load'){
n = getEventTarget(n);
}
if (getTag(n) == 'img'){
Size = { w: n.width, h: n.height };
n = getAncestor(n, '.shadow');
}else with (getFirstChild(n)){
if (!n.offsetWidth)
return;
Size = { w: offsetWidth, h: offsetHeight }
}
if (Size.w<90 || Size.h<60) {
if (Size.w >= 60 && Size.h >= 40) {
sImg = "small.png";
}else{
sImg = "null.png";
}
}else{
sImg = "logo.png";
}
if (browser.isIE && forceTransparency==true){
}else{
if (!(sBg = _cachedShadowPath)){
if (browser.isIE){
sBg = n.currentStyle.getAttribute("shadow-image");
}else{
if (browser.isKHTML){
forEachStyleRule(
document,
function(r){
if (r.selectorText.indexOf('.shadow:') == 0){
sBg = r.style.getPropertyValue("background-image");
return -1;
}
}
);
}else{
sBg = String(
getComputedStyle(
n,
browser.isGecko ? ":before" : "before"
).getPropertyValue("background-image"));
}
}
_cachedShadowPath = sBg;
}
if (browser.isIE){
sBg = sBg.replace(/alpha/, _getShadowColorString(n));
}
sBg = sBg.replace(
/\/?("?)\)/,
"/" + Size.w + "/" + Size.h + "/" + sImg + "$1)"
);
if (n.style.backgroundImage != sBg){
n.style.backgroundImage = sBg;
}
}
}
function addShadows(root)
{
var img, tmp;
if (!(root && root.tagName)){
root = document;
}
forEachItem(
getElements(root, "span.shadow"),
function(n) {
tmp = n.getElementsByTagName('a');
img = (tmp && tmp[0] ? tmp[0] : n).getElementsByTagName('img');
img = (img && img[0]) ? img[0] : undefined;  
if ((!img) || (img.width>0 && img.height>0) || (img.complete == true)) {
addShadow(img || n);
}else{
hookEvent(img, "load", addShadow);
}
}
);
}
function _getShadowColorString(node)
{
if (!node)
return null;
if (hasClass(node.parentNode, "devctrl")){
node = getAncestor(node, "p") || node;
}
if (node.currentStyle) {
var sBg = node.currentStyle.backgroundColor;
if (sBg != "transparent") {
return sBg.substr(1, 6).toUpperCase();
}
}
return _getShadowColorString(node.parentNode);
}
hookEvent(deviantART, "applicationready", addShadows, false, "Apply Shadow Images");
if (browser.isKHTML && !window.getComputedStyle){
window.getComputedStyle = function(node, pseudoElement){
return node.style;
}
}
function AddShadows(sID, sElements)
{
if (sID)
return addShadows(document.getElementById(sID));
else
return addShadows();
}
AddShadow = addShadow;


function getClientRect()
{
var w = 0, h = 0;
if (window.innerWidth) {
w = window.innerWidth;
h = window.innerHeight;
}else if (document.body.clientWidth) {
w = document.body.clientWidth;
h = document.body.clientHeight;
}else{
with (getComputedStyle(document.documentElement, "")){
w = parseInt(getPropertyValue("width"));
h = parseInt(getPropertyValue("height"));
}
}
return { x:0, x2:w, y:0, y2:h};
}
var _canvasResizeOldClass;
function _canvasResize(e)
{
var r, c, k, win;
win = (_canvasResizeOldClass == "window");
r = getClientRect();
if (r.x2 <= 450 && !win) {
c = "compact";
}else if (r.x2 <= 900) {
c = "lo-res";
}else{
c = "hi-res";
}
k = String(document.body.className);
if (hasClass(document.body, c))
return true;
if (c != "compact" && !win){
c += " "+_canvasResizeOldClass;
}
k = k.replace(/\b(?:compact|lo-res|hi-res|cols)\b/g, "");
k += " "+c;
document.body.className = k;
}
function _canvasResizeWindow(e)
{
var
section = document.getElementById("window"),
sectionNext, height, adjust = 0, Adjustments = Array()
;
height = getClientRect().y2;
Adjustments.push(document.getElementById("head"));
sectionNext = section;
while ( sectionNext = getNextSibling(sectionNext) ){
Adjustments.push(sectionNext);
}
sectionNext = section;
while ( sectionNext = getPreviousSibling(sectionNext) ){
Adjustments.push(sectionNext);
}
forEachItem(
Adjustments,
function(node) {
if (
getTag(node)!="script" &&
node.style.display != "none" &&
node.offsetHeight
)
adjust += node.offsetHeight;
}
);
adjust += 20;
section.style.height = Math.max(240, height-adjust)+"px";
}
function _canvasResizeInit(e)
{
if (
(!document.body.offsetHeight)
||
hasClass(document.body, "prints-portal")
||
hasClass(document.body, "very compact")
){
return true;
}
if (hasClass(document.body, "window")){
_canvasResizeOldClass = "window";
hookEvent(window, "resize", _canvasResizeWindow);
hookEvent(window, "load", _canvasResizeWindow);
_canvasResizeWindow();
}else{
_canvasResizeOldClass = hasClass(document.body, "cols") ? "cols" : "";
}
hookEvent(window, "resize", _canvasResize);
_canvasResize();
}
hookEvent(deviantART, "applicationready", _canvasResizeInit, false, "Prepare Window Resize Handler");
function GetClientArea()
{
var r = getClientRect();
return {
width: r.x2,
height: r.y2
};
}

function getDALinkType(link)
{
var sLink;
if ((typeof link) == "string"){
sLink = link;
link = null;
}else{
sLink = link.getAttribute("href");
}
if (sLink.match(/^ht{2}p:\/\/www\.deviantart\.com\/(?:deviation|view)\/\d+\/?$/i)){
return "deviation";
}
if (sLink.match(/^ht{2}p:\/\/.+\.deviantart\.com\/?$/i)){
var s, img;
img = getElement(link, "img");
if (img && img.getAttribute("src").indexOf("ht"+"tp://a.deviantart.com/")==0){
return "deviant";
}
if (link.previousSibling && link.previousSibling.nodeValue){
s = link.previousSibling.nodeValue;
if (DA_DEVIANT_SYMBOLS.indexOf(s.charAt(s.length-1)) >= 0){
return "deviant";
}
}
}
return null;
}
function getLinkBehavior(link)
{
var
sRel, sClass, sHRef,
rgPopup			= /(?=^|\s)popup(?=\(|\s|$)/,
rgToggle		= /\btoggle\b/,
rgExclusive		= /\bexclusive\b/,
rgOneWay		= /\bone-way\b/,
rgTab			= /\btab\b/,
rgReply			= /\#reply$/,
rgMarkAsRead    = /\#MarkAsRead/,
rgComment		= /\^ht{2}p:\/\/comments.deviantart.com\/.*$/
;
if (sRel = link.getAttribute("rel")) {
if (rgPopup.test(sRel))
return "popup";
if (rgTab.test(sRel))
return "tab";
}
if (sClass = link.className) {
if (rgToggle.test(sClass)) {
if (rgOneWay.test(sClass))
return "one-way toggle";
if (rgExclusive.test(sClass))
return "exclusive toggle"
return "toggle";
}
}
return null;
}
function getLinkTarget(link)
{
var s;
s = link.getAttribute("href");
s = s.substr(s.indexOf("#") + 1);
return document.getElementById(s);
}
function _hyperlinkGetHolder(node)
{
return getAncestor(node, ".toggle-holder") || node;
}
function _hyperlinkExclusiveToggle(Node)
{
var Holder = _hyperlinkGetHolder(Node);
forEachItem(
getElements(Holder, "a.toggle"),
function(Node) {
_hyperlinkToggle(Node);
}
);
_hyperlinkToggle(Node);
return false;
}
function _hyperlinkToggle(link)
{
var sClass = ' '+link.className+' ', target;
target = getLinkTarget(link);
if (sClass.indexOf(" toggle ")>=0) {
setStyle(target, "display", "none");
link.className = sClass.replace(" toggle ", " toggle-off ");
}else{
setStyle(target, "display", "block");
link.className = sClass.replace(" toggle-off ", " toggle ");
}
return false;
}
function _hyperlinkJump(link)
{
setStyle(_hyperlinkGetHolder(link), "display", "none");
setStyle(getLinkTarget(link), "display", "block");
return false;
}
function _hyperlinkPopupClick(link)
{
var sRel, Pos, PosII, sTmp, rgPopup = 0, Popup={name:"devart", width:400, height:300};
sRel = link.getAttribute("rel");
if (Pos = sRel.search(rgPopup)>=0) {
rgPopup = /(?=^|\s)popup(?=\(|\s|$)/;
RgNext = /[,\s\)]/;
Popup.name = getNodeText(link);
sRel = sRel.substr(Pos);
if (Pos = sRel.indexOf("(")) {
sRel = sRel.substr(Pos);
while (sRel.length && sRel.charAt(0)!=")") {
sRel = sRel.substr(1);
Pos = sRel.search(RgNext);
if ((PosII = sRel.indexOf(":"))<0)break;
sTmp = sRel.substring(PosII+1, Pos);
switch(sRel.substring(0, PosII)) {
case "name":
Popup.name = sTmp;
break;
case "width":
Popup.width = parseInt(sTmp);
break;
case "height":
Popup.height = parseInt(sTmp);
break;
}
if (Pos<0) {
break;
}else{
sRel = sRel.substr(Pos);
}
}
try {
return !window.open(link.getAttribute("href"), Popup.name, "toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=" + Popup.width + ", height=" + Popup.height);
}
catch (e) {
return true;
}
}
}
return true;
}
function _hyperlinkTabClick(link)
{
forEachItem(
link.parentNode.getElementsByTagName("a"),
function(tab) {
if (tab == link) {
setStyle(tab, "display", "none");
setStyle(getNextSibling(tab), "display", "block");
}else{
if (getStyle(getNextSibling(tab), "display") != "none") {
setStyle(getNextSibling(tab), "display", "none");
setStyle(tab, "display", "block");
}
setStyle(getLinkTarget(tab), "display", "none");
}
}
);
setStyle(getLinkTarget(link), "display", "block");
if (browser.isOpera){
getLinkTarget(link).parentNode.scrollTop = 0;
}
return false;
}
function CommentBox(div)
{
if (!div) return;
var n;
this.link = getElement("#"+div.parentNode.id + "Link");
this.container = div;
this.head = getFirstChild(div);
this.templates = getElement(this.head, ".templates");
this.body = n = getNextSibling(this.head);
while (n = getNextSibling(n)){
this.foot = n;
}
this.text = getElement(this.body, "textarea");
this.label = this.text.parentNode;
this.preview = getNextSibling(this.label);
}
CommentBox.uniqueID = 0;
function _hyperlinkReplyClick(link)
{
var commentBox, outputBox, outputMode, deviant, check;
if (deviantART.isMessageCenter) {
commentBox = getAncestor(link, ".beacon");
} else {
commentBox = getAncestor(link, ".item");
}
outputBox = getNextSibling(commentBox);
if ((!outputBox) || (!hasClass(outputBox, "nest"))){
outputBox = document.createElement("div");
setClass(outputBox, "nest");
if (deviantART.isMessageCenter) {
setStyle(outputBox, "marginTop", "10px");
}
appendNode(outputBox, commentBox);
outputMode = SETNODECONTENTS_REPLACE;
} else {
outputMode = SETNODECONTENTS_PREPEND;
}
if (outputBox.id.length == 0) {
CommentBox.uniqueID += 1;
outputBox.id = "EasyReply" + CommentBox.uniqueID;
link.id = "EasyReply" + CommentBox.uniqueID + "Link";
}
check = getElement(outputBox, "div.item-body");
if (!(check && getElement(check, "textarea"))){
setNodeContents(link, "Cancel Reply");
deviant = getCurrentDeviant();
var headerHTML  =
getElement(commentBox, ".item-head") && getElement(getElement(commentBox, ".item-head"), "img.avatar") ?
'<a href="'+ deviant.href +'"><img class="avatar" src="'+ deviant.avatarSrc +'" alt=""/></a>' :
''
;
if (deviantART.isMessageCenter) {
headerHTML += '<span class="aside-right">'+ (new Date()).toLocaleString() +'</span> \
<span class="aside-left">' + deviant.symbol +'<a href="'+ deviant.href +'">'+ deviant.name +'</a></span>'
} else {
headerHTML += deviant.symbol +'<a href="'+ deviant.href +'">'+ deviant.name +'</a><br/>';
if (deviantART.isForum) {
headerHTML += '<strong>Subject:</strong> ' + document.getElementsByName("subject")[0].value + '<br/>';
}
headerHTML += '<strong>Date:</strong> '+ (new Date()).toLocaleString() +'<br/>'
}
if (self.DA_CommentTemplates_ToHTML) {
headerHTML += 
'<div class="templates" style="clear: left;"><strong>Use Template:</strong> <select>'+
self["DA_CommentTemplates_"+deviantART.application+"_HTML"]+'</select></div>';
}
setNodeContents(
outputBox,
'<div class="item"> \
<div class="float-holder item-head">' + headerHTML + '</div> \
<div class="trailing item-body"> \
<span class="aside-right"><a href="ht'+'tp://comments.deviantart.com/emoticons" onclick="return popup(\'ht'+'tp://comments.deviantart.com/emoticons\', \'emoticons\', 400, 600);" tabindex="1">Emoticon Legend</a></span> \
<label><strong>Your Reply:</strong><textarea tabindex="1" style="height: 90px;"></textarea></label> \
<div class="preview"></div> \
</div> \
<div class="trailing float-holder item-foot"> \
<span class="aside-right"> \
<input class="reply-preview button" type="button" value="Preview Reply"/> \
<input class="reply-submit button" type="button" tabindex="1" value="Send Reply"/> \
</span> \
<span class="aside-left"> \
<input class="reply-cancel button" type="button" value="Cancel"/> \
</span> \
</div> \
</div>',
outputMode
);
hookEvent(getElement(outputBox, ".item-foot"), "click", _hyperlinkReplyControlsClick, false);
if (self.DA_CommentTemplates_Main) hookEvent(getElement(outputBox, "select"), "change", _hyperlinkTemplateSelectChange, false);
_hyperlinkTextarea = getElement(outputBox, "textarea");
setTimeout("_hyperlinkTextarea.focus()", 1);
} else {
_hyperlinkReplyCancel(new CommentBox(getFirstChild(outputBox)));
}
if (deviantART.isMessageCenter && browser.isIE) _forcePageLayout();
}
function _hyperlinkTemplateSelectChange (e){
var select = getEventTarget(e);
var boxElement = getAncestor(select, ".item");
var textarea = getElement(boxElement, "textarea");
if (textarea.disabled) return;
textarea.value = select.value ? self["DA_CommentTemplates_"+deviantART.application][select.value][1] : "";
textarea.focus();
}
function _hyperlinkReplyPreviewReady(r, uri, box){
var h;
XMLDOC = r;
if (!r.responseXML) {
setStyle(box.label, "display", "block");
box.text.disabled = false;
setBusy(getElements(box.foot, "input"), false);
alert("A problem occurred while submitting your comment.\n\nPlease try again after a short while.");
return;
}
h = box.body.offsetHeight;
if (!browser.isKHTML){
h -= parseInt(getStyle(box.body, "paddingTop") + getStyle(box.body, "paddingBottom"));
}
setStyle(box.body, "height", h + 'px');
setStyle(box.body, "overflow", "auto");
setStyle(box.label, "display", "none");
setNodeContents(
box.preview,
'<strong style="display:block">Preview:</strong>' +
r.responseXML.selectSingleNode("//comment").firstChild.nodeValue
);
setBusy(getElements(box.foot, "input"), false);
with (getElement(box.foot, "input.reply-preview")) {
value = "Edit Reply";
className = className.replace(/\breply-preview\b/, 'reply-edit');
}
if (browser.isIE && deviantART.isMessageCenter) {
_forcePageLayout();
}
}
function _hyperlinkReplyPostReady(r, uri, box){
XMLDOC = r;
if (!r.responseXML) {
setStyle(box.label, "display", "block");
box.text.disabled = false;
setBusy(getElements(box.foot, "input"), false);
alert("A problem occurred while submitting your comment.\n\nPlease try again after a short while.");
return;
}
var commentNode = r.responseXML.selectSingleNode("//comment");
setNodeContents(box.body, commentNode.firstChild.nodeValue);
setNodeContents(box.link, "Reply");
if (box.templates) setStyle(box.templates, "display", "none");
if (deviantART.isMessageCenter) {
if (browser.isIE) _forcePageLayout();
setStyle(box.foot, "display", "none");
_hyperlinkReplyPostReady.setToHide = box.container.parentNode;
_hyperlinkReplyPostReady.setToHide2 = getPreviousSibling(box.container.parentNode);
_hyperlinkReplyPostReady.setToHide3 = getPreviousSibling(_hyperlinkReplyPostReady.setToHide2);
if (getTag(_hyperlinkReplyPostReady.setToHide3) == "br") {
setTimeout("removeNode(_hyperlinkReplyPostReady.setToHide3)", 1000);
}
setTimeout("removeNode(_hyperlinkReplyPostReady.setToHide)", 1000);
setTimeout("removeNode(_hyperlinkReplyPostReady.setToHide2); if(browser.isGecko) _forcePageLayout()", 1000);
return;
}
else if (deviantART.isForum) {
var threadid = commentNode.getAttribute("threadid");
var href = box.link.getAttribute("href");
setNodeContents(
box.foot, 
'<a href="'+href+'">Parent</a>, \
<a href="'+href.substring(0, href.lastIndexOf("/"))+'">Top</a>'
);
return;
} else {
var typeid = commentNode.getAttribute("typeid");
var itemid = commentNode.getAttribute("itemid");
var parentid = commentNode.getAttribute("parentid");
var id = commentNode.getAttribute("id");
unsetClass(box.foot, "mod-double");
setNodeContents(
box.foot,
'<a href="ht'+'tp://comments.deviantart.com/'+typeid+'/'+itemid+'/'+id+'#reply">Reply</a>, \
<a href="ht'+'tp://comments.deviantart.com/'+typeid+'/'+itemid+'/'+parentid+'">Parent</a>'
);
enhanceHyperlinks(box.foot);
}
}
function _hyperlinkReplyControlsClick(e)
{
var
button = getEventTarget(e),
box = new CommentBox(getAncestor(button, ".item"))
;
if (button.disabled)
return;
if (getTag(button) == "input" && button.getAttribute("type") == "button"){
if (hasClass(button, "reply-cancel")){
_hyperlinkReplyCancel(box);
}
else if (hasClass(button, "reply-edit")){
var n;
setStyle(box.body, "height", "auto");
setStyle(box.body, "overflow", "visible");
box.preview.innerHTML = "";
setStyle(getElement(box.body, "label"), "display", "block");
box.text.disabled = false;
box.text.focus();
button.value = "Preview Reply";
button.className = button.className.replace(/\breply-edit\b/, 'reply-preview');
}
else if (hasClass(button, "reply-preview")){
if (box.text.value.length == 0) return;
var r = new XMLHttpRequest();
xmlhttpPost(
r,
"/ajax/comments/preview",
"application/x-www-form-urlencoded",
"ref=xml&body="+ escape(box.text.value),
_hyperlinkReplyPreviewReady,
box
);
box.text.blur();
box.text.disabled = true;
setBusy(getElements(box.foot, "input"), true);
}
else if (hasClass(button, "reply-submit")){
if (box.text.value.length == 0)
return cancelEvent(e);
unhookEvent(box.foot, "click", _hyperlinkReplyControlsClick, false);
var parentComment, uri, href_split, typeID, itemID, parentID, forumID, threadID, subject, data;
parentComment = getPreviousSibling(getAncestor(button, ".nest"));
var parentClass =
(deviantART.isMessageCenter) ?
".last" :
".item-foot"
;
href_split = box.link.getAttribute("href").split("/");
typeID = href_split[href_split.length-3];
itemID = href_split[href_split.length-2];
parentID = href_split[href_split.length-1].split("#")[0];
if (deviantART.isForum) {
forumID = document.getElementsByName("forumid")[0].value;
threadID = document.getElementsByName("threadid")[0].value;
subject = document.getElementsByName("subject")[0].value;
messageID = parentID ? parentID : document.getElementsByName("messageid")[0].value;
uri = (deviantART.isUserForum) ?
"/ajax/user/journal/forum/post" :
"/ajax/forum/post"
;
data =
"ref=xml&body=" + escape(box.text.value)+"&subject="+escape(subject)+
"&threadid="+threadID+"&forumid=" + forumID + "&messageid="+messageID;
} else {
uri = "/ajax/comments/post";
data =
"ref=xml&body=" + escape(box.text.value) + "&typeid=" + typeID +
"&itemid=" + itemID + "&parentid="+parentID;
}
var r = new XMLHttpRequest();
xmlhttpPost(
r,
uri,
"application/x-www-form-urlencoded",
data,
_hyperlinkReplyPostReady,
box
);
box.text.disabled = true;
setBusy(getElements(box.foot, "input"), true);
}
}
return cancelEvent(e);
}
function _hyperlinkReplyCancel(box){
var holder = box.container.parentNode;
setNodeContents(box.link, "Reply");
unhookEvent(box.foot, "click", _hyperlinkReplyControlsClick, false);
holder.removeChild(box.container);
if (!holder.firstChild){
holder.parentNode.removeChild(holder);
}
if (browser.isIE && deviantART.isMessageCenter) {
_forcePageLayout();
}
if (browser.isGecko) {
_forcePageLayout();
}
}
function _hyperlinkMarkAsReadClick(link)
{
var commentID = link.getAttribute("href").split("/");
commentID = commentID[commentID.length-1].split("#")[0];
var container = getAncestor(link, ".beacon");
var br = getPreviousSibling(container);
removeNode(container);
if (getTag(br == "br")) {
removeNode(br)
}
_forcePageLayout();
data = "ref=xml&commentids[]="+commentID;
var r = new XMLHttpRequest();
xmlhttpPost(
r,
"/ajax/my/messages/update",
"application/x-www-form-urlencoded",
data
);
}
function _hyperlinkParentClick(link) {
href_split = link.getAttribute("href").split("/");
typeID = href_split[href_split.length-3];
parentID = href_split[href_split.length-1];
}
function enhanceHyperlinks(root)
{
var
sRel, sClass, sType,
TabHolders = Array()
;
root = root || document;
forEachItem(
root.getElementsByTagName("a"),
function(link) {
if (link.DAhyperlinkEnhanced)
return;
sType = getLinkBehavior(link);
if	(!sType)
return;
switch (sType) {
case "reply":
if (deviantART.isMessageCenter) {
link.setAttribute("tabIndex", 1);
link.DAhyperlinkEnhanced = true;
if (browser.isIE && link.parentNode.lastChild.nodeValue == false) removeNode(link.parentNode.lastChild)
setNodeContents(
link.parentNode,
', <a tabIndex="1" href="'+link.getAttribute("href").split("#")[0]+'#MarkAsRead">Mark as Read</a>',
1);
break;
}
case "markasread":
case "popup":
case "parent":
break;
case "tab":
if (
TabHolders.length == 0
||
link.parentNode != TabHolders[TabHolders.length-1]
){
TabHolders.push(link.parentNode);
}
link.DAhyperlinkEnhanced = true;
return;
case "one-way toggle":
if (
getStyle(_hyperlinkGetHolder(link), "display") != "none"
&&
!hasClass(link, "toggle-off")
){
setStyle(getLinkTarget(link), "display", "none");
}
break;
case "exclusive toggle":
if (getElement(_hyperlinkGetHolder(link), "a") != link){
_hyperlinkToggle(link);
}
break;
case "toggle":
_hyperlinkToggle(link);
break;
default:
return;
}
link.DAhyperlinkEnhanced = true;
hookEvent(link, "click", _hyperlinkClicked);
}
);
forEachItem(
TabHolders,
function(Holder) {
setNodeContents(
Holder,
getNodeContents(Holder).replace(
/>([^>]*)<\/a>/gi,
'>$1</a><strong style="display:none">$1</strong>'
)
);
forEachItem(
Holder.getElementsByTagName("a"),
function(tab) {
if (/\btab\b/.test(String(tab.getAttribute("rel")))) {
hookEvent(tab, "click", _hyperlinkClicked);
}
}
);
_hyperlinkTabClick(getElement(Holder, "a"));
}
);
}
function _hyperlinkClicked(e)
{
if (e.button > 1)
return true;
var link = getEventTarget(e);
if (getTag(link) != "a"){
link = getAncestor(link, "a");
if (!link)
return true;
}
switch (getLinkBehavior(link)) {
case "popup":
_hyperlinkPopupClick(link);
break;
case "reply":
_hyperlinkReplyClick(link);
break;
case "markasread":
_hyperlinkMarkAsReadClick(link);
break;
case "tab":
_hyperlinkTabClick(link);
break;
case "toggle":
_hyperlinkToggle(link);
break;
case "one-way toggle":
_hyperlinkJump(link);
break;
case "exclusive toggle":
_hyperlinkExclusiveToggle(link);
break;
case "parent":
_hyperlinkParentClick(link);
break;
default:
return true;
}
return cancelEvent(e);
}
hookEvent(deviantART, "applicationready", function(e){ enhanceHyperlinks(); }, false, "Prepare Enhanced Hyperlinks [old module]");
linkToggle = LinkToggle = _hyperlinkToggle;

function GetNodeOffset(Node)
{
var i = 0;
while (Node = GetPreviousSiblingElement(Node))
i++;
return i;
}
function GetOffsetNode(Node, Offset)
{
Node = GetFirstChildElement(Node);
while ((Offset--)>0)
Node = GetNextSiblingElement(Node);
return Node;
}
function GetLabelInput(Label)
{
var sFor;
if (
sFor=
Label.htmlFor
?Label.htmlFor
:Label.getAttribute("for")
)
return document.getElementById(sFor);
else
return Label.getElementsByTagName("input")[0];
}
function GetInputLabel(Input)
{
var sTmp;
if (Input.label != undefined)
return Input.label;
var Label = Input.parentNode;
while ((sTmp = GetTag(Label)) != "label") {
if (!Label.parentNode || sTmp == "form") {
if (!Input.id)return 0;
var Form;
Form=
(sTmp == "form")
?Label
:GetForm(Input);
function MatchLabel(xLabel) {
if (
(
xLabel.htmlFor
?xLabel.htmlFor
:xLabel.getAttribute("for")
)==Input.id
) {
Label = xLabel;
return -1;
}
}
ForEachItem(Form.getElementsByTagName("label"), MatchLabel);
return Label;
}
Label = Label.parentNode;
}
return Input;
}
function GetAttribute(Node, sAttr)
{
var sReturn, Match, RgAttribute;
if ((sReturn = Node.getAttribute(sAttr)) || !Opera)
return sReturn;
RgAttribute = RegExp('<' + Node.tagName + '[^>]*' + sAttr + '="([^"]*)"[^>]*>', 'i');
Match = String(Node.outerHTML).match(RgAttribute);
return Match ? Match[1] : null;
}
function GetForm(Input)
{
if (Input.form)
return Input.form;
while (Input.parentNode && GetTag(Input)!="form")
Input = Input.parentNode;
return Input; // May return doc root; this is alright
}
function SetDisplay(Node, sValue)
{
if (Node.style.display)
Node.style.display = sValue;
else
Node.style["display"]=sValue;
}
function GetDisplay(Node)
{
return (Node.style.display || Node.style["display"]);
}
function GetTarget(Node)
{
var sTmp;
sTmp = Node.getAttribute("href");
if (!sTmp)
sTmp = Node.getAttribute("for");
if (sTmp) {
sTmp = sTmp.substr(sTmp.indexOf("#") + 1);
return document.getElementById(sTmp);
}return 0;
}
function GetBoxSize(Node)
{
var w = 0, h = 0;
if (Node.width) {
w = Node.width;
h = Node.height;
}
else if (window.getComputedStyle) {
w = parseInt(window.getComputedStyle(Node, "").getPropertyValue("width"));
h = parseInt(window.getComputedStyle(Node, "").getPropertyValue("height"));
}
else if (Node.offsetWidth) {
w = Node.offsetWidth;
h = Node.offsetHeight;
}
return {width:w, height:h};
}
function _IELabelClick(e) {
try{
getAncestor(getEventTarget(e), "label").click();
return cancelEvent(e);
}catch(e){}
}
function EnhanceFormControls(Node)
{
if (!Node)
Node = document;
if (browser.isIE) {
forEachItem(
Node.getElementsByTagName("label"),
function(label) {
forEachItem(
label.getElementsByTagName("img"),
function(sub) {
hookEvent(sub, "click", _IELabelClick);
}
);
}
);
}
function GetTopOptionLabel(Node) {
if (GetTag(Node)!="label" && HasClass(Node, "option"))
return Node;
while (Node.parentNode && GetTag(Node)!="label")
Node = Node.parentNode;
if (!HasClass(Node, "option"))
return 0;
while (HasClass(Node.parentNode, "option"))
Node = Node.parentNode;
return Node;
}
function OptionSelected(Node) {
var Label, Input, sClass, sInputName;
Label = GetTopOptionLabel(Node);
Input=
(GetTag(Node)=="input")
?Node
:GetLabelInput(Label)
;
sInputName = Input.getAttribute("name");
if (Input.getAttribute("type")=="checkbox") {
sClass = String(Label.className);
sClass = sClass.replace(RegExp("\\boption\\-selected\\b", "g"), "");
if (Input.checked == true || (Input.checked == undefined && Input.getAttribute("checked")=="checked"))
sClass+=" option-selected";
Label.className = sClass;
}else{
ForEachItem(
GetForm(Input).getElementsByTagName("input"),
function(xInput) {
var xLabel;
if (
xInput.getAttribute("type")!="radio" ||
!(xLabel = GetTopOptionLabel(xInput))
)return;
if (HasClass(xLabel, "option")) {
if (xLabel == Label)
xLabel.className+=" option-selected";
else if (xInput.getAttribute("name")==sInputName)
xLabel.className = String(xLabel.className).replace(/\boption\-selected\b/g, "");
}
}
);
}
return true;
}
function OptionHover(Node) {
SetClass(Node, "option-hover");
return true;
}
function OptionHoverOut(Node) {
UnsetClass(Node, "option-hover");
return true;
}
function InputAdjust(Input) {
var Label, sModString;
Label = GetInputLabel(Input);
sModString = "("+String(Label.childNodes[0].nodeValue).toLowerCase().replace(/:/, "")+")";
if (sModString == Input.value) {
if (Input.inputHovers)
Input.value = "";
}else if (!Input.inputHovers && Input.value == "") {
Input.value = sModString;
}
return true;
}
function InputHover(Input) {
if (++Input.inputHovers>2)
Input.inputHovers = 2;
return InputAdjust(Input);
}
function InputHoverOut(Input) {
if (--Input.inputHovers<0)
Input.inputHovers = 0;
return InputAdjust(Input);
}
ForEachItem(
document.getElementsByTagName("input"),
function(Input) {
var Label;
if (!(Label = GetInputLabel(Input)))
return;
if (HasClass(Label, "inline")) {
SetDisplay(Label, "none");
Input.label = Label;
Input.inputHovers = 0;
InputAdjust(Input, 0);
CatchEvent(Input, "mouseover", InputHover);
CatchEvent(Input, "mouseout", InputHoverOut);
CatchEvent(Input, "focus", InputHover);
CatchEvent(Input, "blur", InputHoverOut);
}else{
if (Label = GetTopOptionLabel(Label)) {
if (browser.isIE){
CatchEvent(Label, "mouseover", OptionHover);
CatchEvent(Label, "mouseout", OptionHoverOut);
}
CatchEvent(Input, "click", OptionSelected);
if (Opera){
CatchEvent(Label, "click", OptionSelected);
}
if (Input.checked || Input.getAttribute("checked")=="checked"){
OptionSelected(Input);
}
}
}
}
);
}
function Fixes()
{
EnhanceFormControls();
}
function popup(url, name, width, height, returnWin)
{
var url = url || "";
var width = width ? width : 500;
var name = name || "DA";
var height = height ? height : 600;
var win = window.open(url, name, 'toolbar = 0, scrollbars = 1, location = 0, statusbar = 0, menubar = 0, resizable = 1, width=' + width + ', height=' + height);
if (browser.isIE && event) {
stopEvent(event);
cancelEvent(event);
}
if (returnWin) return win;
return false;
}
hookEvent(deviantART, "applicationready", Fixes, false, "Prepare Enhanced Form Controls [old module]");


