(function DK(t) {
	var win = t.window, doc = win.document, http = null, obj = this, tmrV = 13, tmr = null, animSequences = [];

	// Complex
	this.createHttpRequest = function() { try { return new win.XMLHttpRequest(); } catch (e1) { } try { return new win.ActiveXObject("Msxml2.XMLHTTP"); } catch (e2) { } try { return new win.ActiveXObject("Microsoft.XMLHTTP"); } catch (e3) { } };
	this.sendHttpRequest = function(url) { http.open("GET", url, true); http.send(null); return false; };
	this.httpGetResponse = function() { return function() { if((http.readyState === 4) && (http.status === 200)) { return http.responseText; } return false; }; };
	this.httpInnerHTML = function(tgt) { return function() { if((http.readyState === 4) && (http.status === 200)) { tgt.innerHTML = http.responseText; } return false; }; };

	// Basics
	Object.prototype.getByClass = function(c) { var a = [], i = 0, j = 0, re = new RegExp('\\b' + c + '\\b'), els = this.getElementsByTagName("*"); for(i = 0, j = els.length; i < j; i += 1) { if(re.test(els[i].className)) { a.push(els[i]); } } return a; };
	Object.prototype.getByRel = function(c) { var a = [], i = 0, j = 0, re = new RegExp('\\b' + c + '\\b'), els = this.getElementsByTagName("*"); for(i = 0, j = els.length; i < j; i += 1) { if(re.test(els[i].rel)) { a.push(els[i]); } } return a; };
	Object.prototype.remove = function() { this.parentNode.removeChild(this); return false; };

	// Simples
	Object.prototype.innerHTMLFromURL = function(url) { http = obj.createHttpRequest(); obj.sendHttpRequest(url); http.onreadystatechange = obj.httpInnerHTML(this); return false; };
	Object.prototype.initExternalLinks = function() { var i = 0, j = 0, links = this.getByRel("external"); for(i = 0, j = links.length; i < j; i += 1) { links[i].target = "_blank"; } return false; };

	// Drawing
	Object.prototype.hide = function() { this.style.display = "none"; return false; };
	Object.prototype.show = function() { this.style.display = "block"; return false; };

	// Animation
	Object.prototype.setOpacity = function(a) { this.style.opacity = a / 100; return false; };
	Object.prototype.setPos = function(x, y) { if(x === null) { x = parseInt(this.style.left, 10); } if(y === null) { y = parseInt(this.style.top, 10); } this.style.left = x + "px"; this.style.top = y + "px"; return false; };

	this.animTimerRun = function() {
		var s = 0, sequence = null, anim = null, frame = null;
		for(s = 0; s < animSequences.length; s += 1) {
			sequence = animSequences[s]; anim = sequence.anims[sequence.curAnim]; anim.curFrame += 1; frame = anim.cFrames[anim.curFrame];
			switch(anim.attr) {
				case 'x': sequence.object.setPos(frame, null); break;
				case 'y': sequence.object.setPos(null, frame); break;
				case 'w': sequence.object.style.width = parseInt(frame, 10) + "px"; break;
				case 'h': sequence.object.style.height = parseInt(frame, 10) + "px"; break;
				case 'a': sequence.object.setOpacity(frame); break;
			}
			if(anim.curFrame > anim.cFrames.length) { anim.curFrame = 0; sequence.curAnim += 1; if(sequence.curAnim === sequence.anims.length) { sequence.curAnim = 0; if(sequence.loops > 0) { sequence.loops -= 1; } else { animSequences.splice(s, 1); } } }
		}
		this.clearTimeout(tmr); tmr = null; if(animSequences.length > 0) { tmr = this.setTimeout(this.animTimerRun, tmrV); }
		return false;
	};

	Object.prototype.animate = function(anims, loops) { if(!loops) { loops = 0; } var i = 0, j = 0;
		for(i = 0; i < anims.length; i += 1) {
			anims[i].delta = anims[i].end - anims[i].start; anims[i].distance = anims[i].delta / anims[i].frames; anims[i].cFrames = []; anims[i].curFrame = 0;
			for(j = 0; j < anims[i].frames; j += 1) { anims[i].cFrames.push(anims[i].start + (anims[i].distance * j)); }
		}
		animSequences.push({ 'object' : this, 'loops' : loops - 1, 'curAnim' : 0, 'anims' : anims });
		if(!tmr) { tmr = obj.setTimeout(obj.animTimerRun, tmrV); }
		return false;
	};

	// WYSIWYG
	Object.prototype.initWYSIWYGs = function() {
		var wysiwygs = this.getByClass("DK_wysiwyg"), wysiwyg = null, i = 0, j = wysiwygs.length;
		var formatButtons = ['bold', 'italic', 'h1', 'h2', 'h3', 'paragraph'];
		for(i = 0; i < j; i += 1) {
			wysiwygBar = this.createElement("ul"); wysiwygBar.className = "DK_wysiwygBar";
			wysiwygs[i].id = "DK_wysiwyg_" + i;
			for(var k = 0; k < formatButtons.length; k++) {
				fLI = this.createElement("li");
				fA = this.createElement("a"); fA.href = "#"; fA.rel = wysiwygs[i].id; fA.className = formatButtons[k]; fA.title = formatButtons[k];
				fLI.appendChild(fA); wysiwygBar.appendChild(fLI);
				fA.onclick = function() {
					var action = this.className, curRTedit = document.getElementById(this.rel);
					switch(action) {
						case "bold":		wrapTags(curRTedit, "<strong>", "</strong>");	break;
						case "italic":		wrapTags(curRTedit, "<em>", "</em>");			break;
						case "h1":			wrapTags(curRTedit, "<h1>", "</h1>");			break;
						case "h2":			wrapTags(curRTedit, "<h2>", "</h2>");			break;
						case "h3":			wrapTags(curRTedit, "<h3>", "</h3>");			break;
						case "paragraph":	wrapTags(curRTedit, "<p>", "</p>");				break;
					}
					return false;
				}
			}
			wysiwygs[i].parentNode.appendChild(wysiwygBar);
		}

		return false;
	};

	this.wrapTags = function(textarea, x, y) { 
		if(textarea.selectionStart == undefined) return;
		var chars = textarea.value.split("");
		chars.splice(textarea.selectionStart, 0, x);
		chars.splice(textarea.selectionEnd + 1, 0, y);
		textarea.value = chars.join("");
		return false;
	}

	this.updateWYSIWYGiframe = function() {
	};

	this.initSEOBox = function() {
		var seoLink = document.getElementById('seoLink'), seoClose = document.getElementById('seoClose'), seoBox = document.getElementById('seoBox');
		if(seoLink) { seoLink.onclick = function() {
			seoBox.style.display = (seoBox.style.display == 'none') ? 'block' : 'none';
			return false;
		}; }
		if(seoClose) { seoClose.onclick = function() { seoBox.style.display = 'none'; return false; }; }
		return false;
	};

	// Entry
	//doc.initExternalLinks();
	doc.initWYSIWYGs(); initSEOBox();
	return false;
}(this));
