// initialize the expand/collapse functionality

registerSetupFunction('div.sidebar-sect',function(div){
	if (hasClassName(div,'search')){return;}
	if(hasClassName(document.body,'permalink') && hasClassName(div,'recent')){
		addClassName(div,'default-expanded');
	}
	if(!hasClassName(div,'default-expanded')){addClassName(div, 'collapsed');}
	var h2 = div.getElementsByTagName('h2')[0];
	var toggler = elem('a',{'href':'','class':'expand-collapse'},elemText(h2));
	toggler.expandTitle='Expand this Section';
	toggler.collapseTitle='Collapse this Section';
	toggler.title=toggler.expandTitle;
	toggler.parentSect = div;
	h2.innerHTML = '';
	h2.appendChild(toggler);
	toggler.onclick = function(){
		if (hasClassName(this.parentSect, 'collapsed')){
			removeClassName(this.parentSect, 'collapsed');
			this.title = this.collapseTitle;
		} else {
			addClassName(this.parentSect, 'collapsed');
			this.title = this.expandTitle;
		}
		return false;
	}
});

// initialize the auto-clearing form field functionality

registerSetupFunction('label[for=^q$]',function(label){
	var labelFor=label.htmlFor;
	var input=document.getElementById(labelFor);
	if(!input){return;}
	if(input.defaultValue.match(/^\s*$/)){input.defaultValue=input.value=elemText(label);}
	input.onfocus=function(){
		if(this.value==this.defaultValue){
			this.value='';
		};
	};
	input.onblur=function(){
		if(this.value==''){
			this.value = this.defaultValue;
		}
	};
});

registerSetupFunction('img[src=big\-feed\-icon\.gif]',function(img){
	if(lteie6){return;} // don't do it for ie6 and below!
	img.src=img.src.replace(/\.gif$/,'.png');
},true);

