Ext.onReady(function(){
	// zamiana małp
	// document.body.innerHTML = document.body.innerHTML.replace(/\(-malpa-\)/g,'@');
	Ext.String.replace(/\(-malpa-\)/g, '@');
	//REPLACE youtube IMAGES BY VIDEOS
	Ext.select(".video-youtube").each(function(el) {
		var h = el.getAttribute("height");
		var w = el.getAttribute("width");
		var url = 'http://www.youtube.com/v/'+el.getAttribute("alt")+'?fs=1&amp;rel=0';
		el.replaceWith({
			tag: 'object',
			width: w,
			height: h,
			children:[{
				tag: 'param', name: 'movie', value: url
			},{
				tag: 'param', name: 'allowFullScreen', value: true
			},{
				tag: 'param', name: 'allowscriptaccess', value: 'always'
			},{
				tag: 'embed',
				src: url,
				type: 'application/x-shockwave-flash',
				allowscriptaccess: 'always',
				allowfullscreen: true,
				width: w,
				height: h
			}]
		});
	});
});
/*
	// Just an example:
	var searchMatch = document.referrer.match(/[?&]q=([^&]+)/),
	    searchTerm = searchMatch && searchMatch[1];
	if (searchTerm) {
	    findAndReplace('\\b' + searchTerm + '\\b', function(term){
	        return '<span class="keyword">' + term + '</span>';
	    });
	}

 */
 Ext.ns('Ext.String');
 Ext.String.replace = function(searchText, replacement, searchNode) {
    if (!searchText || typeof replacement === 'undefined') {
        // Throw error here if you want...
        return;
    }
    var regex = typeof searchText === 'string' ?
                new RegExp(searchText, 'g') : searchText,
        childNodes = (searchNode || document.body).childNodes,
        cnLength = childNodes.length,
        excludes = 'html,head,style,title,link,meta,script,object,iframe';
    while (cnLength--) {
        var currentNode = childNodes[cnLength];
        if (currentNode.nodeType === 1 &&
            (excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
            arguments.callee(searchText, replacement, currentNode);
        }
        if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
            continue;
        }
        var parent = currentNode.parentNode,
            frag = (function(){
                var html = currentNode.data.replace(regex, replacement),
                    wrap = document.createElement('div'),
                    frag = document.createDocumentFragment();
                wrap.innerHTML = html;
                while (wrap.firstChild) {
                    frag.appendChild(wrap.firstChild);
                }
                return frag;
            })();
        parent.insertBefore(frag, currentNode);
        parent.removeChild(currentNode);
    }
}
