function getParam(name){
var re=new RegExp("[\?|&]"+name + "=([^&]*)(&.*|$)"),
arr=re.exec(location.search);
if(arr && arr.length > 1) return arr[1];
else return 0;
}

HW.ShowHide.Contact = {
	openItem:parent.getParam('telefone'),
	nodes:[],
	init:function() {
		var obj = this;
		var nodes = $$('jcuRow',document.body,'li');
		for(var i=0,j=nodes.length;i<j;i++) {
			var row = new HW.ShowHide.Contact.Row(nodes[i]);
			row.init(i);
			this.nodes.push(row);
			if(i != this.openItem) {
				row.hide(true);
			}
			row.updateLinks();
		}
		HW.addClass(nodes[this.openItem],'open');
	},
	hide:function(n) {
		var obj = this;
		if(this.openItem !== null && this.openItem != n) {
			this.nodes[this.openItem].hide(false,function(){obj.nodes[n].show()});
		}
		else {
			this.nodes[n].show();
		}
		this.openItem = n;
	}
}

HW.ShowHide.Contact.Row = function(node){
	this.node = node;
}
HW.ShowHide.Contact.Row.prototype = {
	node:null,
	content:null,
	links:null,
	hidden:false,
	text:['Abrir','Fechar'],
	init:function(i) {
		this.index = i;
		this.findContent();
		this.findLinks();
		this.bindEvents();
	},
	findLinks:function() {
		this.links = [];
		var link1 = $$('jcuLink1',this.node,'a');
		var link2 = $$('jcuLink2',this.node,'a');
		if(link1.length) {this.links[0] = link1[0];}
		if(link2.length) {this.links[1] = link2[0];}
	},
	findContent:function() {
		var contents = $$('jcuContent',this.node,'div');
		if(contents.length) {this.content = contents[0];}
	},
	bindEvents:function() {
		var obj = this;
		for(var i=0,j=this.links.length;i<j;i++) {
			(function(){
				var o = obj.links[i];
				HW.attachEvent(o,'click',function(e){HW.preventDefault(e);obj.toggle();});
			})()
		}
	},
	toggle:function() {
		if(!this.hidden){
			this.hide();
			HW.ShowHide.Contact.openItem = null;
		}
		else {
			HW.ShowHide.Contact.hide(this.index);
		}
	},
	show:function() {
		HW.ShowHide.show(this.content,'slide',null,500);
		HW.addClass(this.node,'open');
		this.hidden = false;
		this.updateLinks();
	},
	hide:function(snap,cb) {
		var trans = snap?null:'slide';
		HW.ShowHide.hide(this.content,trans,cb,500);
		HW.removeClass(this.node,'open');
		this.hidden = true;
		this.updateLinks();
	},
	updateLinks:function() {
		if(this.links[1]) {
			this.links[1].innerHTML = this.hidden?this.text[0]:this.text[1];
		}
	}
}

HW.onload(function(){HW.ShowHide.Contact.init();});
