window.onDomReady = initReady;
function initReady(fn) {
	if(document.addEventListener) {
		document.addEventListener("DOMContentLoaded", fn, false);
	}else{
		document.onreadystatechange = function() {
			readyState(fn);
		}
	}
}
function readyState(func) {
	if(document.readyState == "interactive" || document.readyState == "complete") {
		func();
	}
}

window.onDomReady(showFailLink);
function showFailLink() {
	if(document.getElementById('faillink') != null) {
		var failID = document.getElementById('faillink').innerHTML;
		document.getElementById('faillink').style.display = "inline";
		document.getElementById('faillink').innerHTML = '<a class="blogfail-href" href="/blog-fail/'+ failID +'.html">Link defekt? <img src="/static/images/icons/broken.png" alt="broken link" /></a>';
	}
}

window.onDomReady(sidebarKlick);
function sidebarKlick() {
	search = document.getElementById('sidebar-search');
	search.onclick = function () {
		//alert(search.value);
		if(search.value == 'Suchbegriff..')
			search.value = '';
		else {
			search.select();
			search.focus();
		}
	}
}


window.onDomReady(ciaoFrame);
function ciaoFrame() {
	if(top != self)
		window.setTimeout("top.location.replace(self.location.href)", 10);
}

/** fallback **/
//if(top != self ) {
	//alert(document.referrer.substring(25));
	/*if(stristr(document.referrer.substring(0,25),'google'))
		window.setTimeout("top.location.replace(self.location.href)", 5000); */
	//if(!stristr(document.referrer.substring(0,25),'google'))
	//	window.setTimeout("top.location.replace(self.location.href)", 1337); 
//}
/** simple stristr pendant to php **/
function stristr(haystack, needle) {
    pos			= 0;
    haystack	= haystack+"";
    pos			= haystack.toLowerCase().indexOf((needle+"").toLowerCase());
    if(pos == -1)
        return false;
    else
    	return true;
}

