var inspectBlock=Class.create();
inspectBlock.prototype={
	initialize:function(blockObj){
	  try {
		this.blockObj=blockObj;
		var ifEmpty=true;
		var childs= $A(blockObj.childNodes);
		if(childs.length<1) this.finish(true);
		for(var i=0,L=childs.length;i<L;i++){
			var childObj=childs[i];
			var ndname=childObj.nodeName;
			if(ndname=="H2" || ndname=="H3" || ndname=="BR" || ndname=="SCRIPT" || ndname=="#comment"){
				continue;
			} else if((childObj.style) && (childObj.style.display=="none")){
				continue;
			} else if(ndname=="#text") {
				var node_text=childObj.nodeValue;
				if(/(\S)/.exec(node_text)){
					//alert("not empty text:"+RegExp.$1+":");
					ifEmpty=false;
					break;
				} else {
					continue;
				}
			} else if(ndname=="P") {
				if(childObj.innerHTML=="&nbsp;" || childObj.innerHTML=="") {
					continue;
				} else {
					//alert("not empty Paragraph")
					ifEmpty=false;
					break;
				}
			}else {
				//alert("some non-empty element:"+ndname)
				ifEmpty=false;
				break;
			}
		}
		this.finish(ifEmpty);
	  } catch(e){
		  alert("error:"+e);
		  this.finish(false)
	  }
	},
	finish:function(ifEmpty){
		if(!ifEmpty){
			this.blockObj.style.visibility="visible";
		} else{
			this.blockObj.style.display="none";
		}
	}
}

var toggleBlock=Class.create();
toggleBlock.prototype={
	targetClassName:"toggleBlock",
	initialize:function(){
		//try{ 
		var a=[],c=0;
		a[c++]="<style>.";
		a[c++]=this.targetClassName;
		a[c++]="{visibility:hidden}<\/style>";
		document.write(a.join(""));
		//Event.observe(window,"load",this.load.bind(this),false);
		Event.observe(document, "dom:loaded",this.load.bind(this),false);
		//} catch(e){alert("0"+e)}
	},
	load:function(){
		//try{ 
		setTimeout(this.start.bind(this),10);
		//} catch(e){alert("1"+e)}
	},
	start:function(){
		try{ 
		//var targets = $A(document.getElementsByClassName(this.targetClassName));
		var targets = $$("."+this.targetClassName)
		targets.each(this.setTarget.bind(this));
		} catch(e){alert("2"+e)}
	},
	setTarget:function(blockObj){
		//try{ 
		new inspectBlock(blockObj);
		//} catch(e){alert("3"+e)}
	}
}
new toggleBlock();


var pointToggle=function(targetElement){
	if(!targetElement.parentNode) return false;
	var inner=targetElement.innerHTML;
	if(inner==="" || inner==="<p>&nbsp;</p>") {
		return 	targetElement.parentNode.innerHTML="";
	}
}
