/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function TwistWords(e) {
	if(Math.random()*1000 < 900) return;
	var entries = getElementsByClassName("entrybody"); 
	if(entries.length < 1) return;
	var offset = Math.round( Math.random() * (entries.length - 1) );
	var entry = entries[offset];
	var txt = entry.getElementsByTagName('p')[0].innerHTML;
	var img = txt.match(/<img[^>]+>/);
	txt = txt.replace(/<img[^>]+>/,"!IMG!");
	var woerter = txt.split(" ");
	var rand1 = Math.round( Math.random() * (woerter.length - 1) );
	var rand2 = Math.round( Math.random() * (woerter.length - 1) );
	if(woerter[rand1].match(/!IMG!/) || woerter[rand2].match(/!IMG!/)) return;
	var tmp = woerter[rand1];
	woerter[rand1] = woerter[rand2];
	woerter[rand2] = tmp;
	txt = woerter.join(" ");
	txt = txt.replace(/!IMG!/,img);
	entry.getElementsByTagName('p')[0].innerHTML = txt;
}

function dobookmark(where) {
	switch(where) {
		case 'wong': newHref = 'http://www.mister-wong.de/index.php?action=addurl&bm_url='+encodeURIComponent(location.href)+'&bm_notice=&bm_description='+encodeURIComponent(document.title)+'&bm_tags='; break;
		case 'wong2': newHref = 'http://www.mister-wong.de/addurl/?bm_url='+encodeURIComponent(location.href)+'&amp;bm_description='+encodeURIComponent(document.title); break;
		case 'delicious': newHref = 'http://del.icio.us/post?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title); break;
		case 'twitter': newHref = 'http://twitter.com/home?status='+encodeURIComponent(location.href); break;
		case 'facebook': newHref = 'http://www.facebook.com/share.php?u='+encodeURIComponent(location.href); break;
		case 'digg': newHref = 'http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title); break;
		case 'yigg': newHref = 'http://yigg.de/neu?exturl='+encodeURIComponent(location.href); break;
		case 'stumbleon': newHref = 'http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title); break;
		case 'reddit': newHref = 'http://reddit.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title); break;
		case 'wikio': newHref = 'http://www.wikio.de/vote?url='+encodeURIComponent(location.href); break;
		case 'yahooweb': newHref = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+encodeURIComponent(location.href)+'&amp;='+encodeURIComponent(document.title); break;
		case 'hype': newHref = 'http://hype.yeebase.com/submit/'+encodeURIComponent(location.href); break;
		case 'linkarena': newHref = 'http://www.linkarena.com/linkadd.php?linkName='+encodeURIComponent(document.title)+'&linkURL='+encodeURIComponent(location.href); break;
		case 'alltagz': newHref = 'http://www.favoriten.de/url-hinzufuegen.html?bm_url='+encodeURIComponent(location.href)+'&amp;bm_title='+encodeURIComponent(document.title); break;
		case 'folkd': newHref = 'http://www.folkd.com/submit/page/' + document.location.href; break;
	}
	location.href = newHref;
}
