reg.importAll();

if(!lteie6){
	reg.setup('img@src$="big-feed-icon.gif"',function(){
			this.src = this.src.replace(/\.gif$/,'.png');
	},true);
}

reg.setup('li.selected',function(){
	var as = this.getElementsByTagName('a');
	if (!as || as.length == 0) {
		this.innerHTML = '<a>'+this.innerHTML+'</a>';
	}
},true);

reg.click("div.question li",function(e){
	if (typeof window.quizLis == 'undefined') {
		window.quizLis = reg.getElementsBySelector('div.question li',this.parentNode.parentNode);
	}
	var active = hasClassName(this,'active');
	for (var b=0; b<window.quizLis.length; b++){
		removeClassName(window.quizLis[b], 'active');
	}
	if (!active) { addClassName(this,'active'); }
	else { removeClassName(this, 'active'); }
});

reg.setup("form#searchForm",function(){
	if (typeof resourcePath == 'undefined') { return; }
	var inputs = gebtn('input',this);
	for (var a=0; a<inputs.length; a++){
		if (inputs[a].type == 'submit') {
			try{
				inputs[a].type = 'image';
				inputs[a].alt = inputs[a].value;
				inputs[a].src = resourcePath+'search-button.gif';
			}catch(ex){}
			return;
		}
	}
});

reg.focus('div.search input@type="text"', function(ev){
	this.style.width = '150px';
}, function(ev){
	this.style.width = null;
});

if (!String.prototype.strip) {
	String.prototype.strip = function() {
		return this.replace(/^\s+|\s+$/g,"");
	};
}

if (!String.prototype.padLeft) {
	String.prototype.padLeft = function(ch, amount) {
		var result = this;
		while(result.length < amount){ result = ch + result; }
		return result;
	};
}

reg.setup('pre.numbered',function(){
	var ih = this.innerHTML;
	if (!ih || lteie6) { return; }
	ih = ih.strip();
	var lines = ih.split("\n");
	var numberOfLines = lines.length;
	var sep = lteie7 ? '&nbsp;<br>' : "\n";
	ih = lines.join(sep);
	var cn = "onedigit", pad = 1;
	if (numberOfLines > 9) { cn = "twodigit"; pad = 2; }
	if (numberOfLines > 99) { cn = "threedigit"; pad = 3; }
	if (numberOfLines > 999) { cn = "fourdigit"; pad = 4; }
	var append = '<span class="numbers">';
	var nums = [];
	for (var i=1;i<=numberOfLines;i++) {
		nums.push((i+'').padLeft('0',pad));
	}
	append += nums.join("<br/>") + '</span>';
	this.innerHTML = ih + append;
	acn(this,cn);
});
