// JavaScript Document

function webget_insertHandle(id, src, title, w, h, fvars) {
//	var fv = (typeof(fvars) != 'undefined') ? '&' + fvars : '';
//	AC_FL_RunContent( 'codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width',w,'height',h,'id',id,'align','middle','name',id,'src',src,'menu','false','quality','high','wmode','transparent','bgcolor','#ffffff','allowscriptaccess','always','pluginspage','http://www.macromedia.com/go/getflashplayer','movie',src,'class','handle','flashvars','id=' + id + '&htitle='+title+fv); //end AC code
	var d = '<div id="' + id + '" class="aba aba_cor ' + src + '"><a href="javascript:;" id="' + id + '_bt_move" class="aba_move aba_cor" title="Mover">&#x25CF;</a>';
	if (typeof(fvars)=='undefined') 
	{
		d += '<a href="javascript:;" id="' + id + '_bt_close"  class="aba_close aba_cor" title="Fechar" onclick="webget_close(\'' + id + '\')">X</a><a href="javascript:;" id="' + id + '_bt_minmax"  class="aba_resize aba_cor" onclick="webget_toggleContent(\'' + id + '\')" title="Minimizar">&#x25B2;</a>';
	}
	d += title + '</div>';
	document.write(d);

}

function webget_updateMinMaxButton(sId)
{
		if ($(sId + '_b').visible())
		{
			$(sId + '_h_bt_minmax').innerHTML = '&#x25B2;'
			$(sId + '_h_bt_minmax').title = 'Minimizar';
		}
		else
		{
			$(sId + '_h_bt_minmax').innerHTML = '&#x25BC;'
			$(sId + '_h_bt_minmax').title = 'Maximizar';
		}
}


function webget_toggleContent(sHdrId) {
	try {
		var sId = sHdrId.substring(0, sHdrId.length-2)
		$(sId + '_b').toggle();
		MyWebgets.update($(sHdrId).parentNode.parentNode.id);
		webget_updateMinMaxButton(sId);
	}
	catch(e) {}
}

function webget_toggle(sId, bShow) {
	try {
		if (bShow) 
			$(sId.substring(0, sId.length-2)).style.display = '';
		else 
			$(sId.substring(0, sId.length-2)).style.display = 'none';
		MyWebgets.update($(sId).parentNode.parentNode.id);
	} 
	catch(e) {}
}
function webget_close(sId) {
	webget_toggle(sId, false);
}
function webget_show(sId) {
	webget_toggle(sId, true);
}
function webget_contentVisible(sId) {
	return $(sId.substring(0, sId.length-1) + 'b').visible();
}


//  _/_/_/_/_/_/_/_/_/_/_/_/_/_/
// _/ Widgets Customization  _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/

var MyWebgets = {
	Webgets: $H(),
	_construct: function() {
		for (var i=0; i<arguments.length; i++) {
			var sCol = arguments[i];
			this.update(sCol, false);
			this.restore(sCol);
		}
		return this;
	},
	checkStatus: function(sWebget) {
		var iStt = 0;
		try {
			if ($(sWebget).visible()) iStt |= 1;
			if ($(sWebget+'_b').visible()) iStt |= 2;
		}
		catch(e) {}
		return iStt;
	},
	reset: function() {
		this.Webgets.each(function(aPair) {
			MyMemory.forget(aPair.key);
		});
	},
	restore: function(sCol) {
		var Saved = MyMemory.whatis(sCol);
		if (Saved != null) {
			this.Webgets[sCol].merge(Saved);
		}

		var aWebgets = $H(this.Webgets[sCol]);
		var aWIds = $A(aWebgets.keys());
		var aSort = $A();
		for (var i=0; i<aWIds.length; i++) {
			try {
				var aProps = $H(aWebgets[aWIds[i]]);
				if ((aProps['stt'] & 1) == 0) $(aWIds[i]).hide();
				else $(aWIds[i]).show();
				if ((aProps['stt'] & 2) == 0) $(aWIds[i]+'_b').hide();
				else $(aWIds[i]+'_b').show();
				webget_updateMinMaxButton(aWIds[i]);

	//			aSort[aProps['pos']] = aWIds[i].substring(sCol.length+1, aWIds[i].length);
				aSort[aProps['pos']] = aWIds[i].match(/\d+$/);
			}
			catch(e) {}
		}
		// Commented line 912 of scriptaculous/src/dragdrop.js 
		// (912): n.parentNode.removeChild(n);
		// If not, the handles color do not update anymore in IE7 after the call below
		Sortable.setSequence($(sCol), aSort);
	},
	update: function(sCol, bSave) {

		if (typeof(bSave) == 'undefined') bSave = true;
		var aWebgets = $A($(sCol).childElements());
		this.Webgets[sCol] = $H();
		for (var j=0; j<aWebgets.length; j++) {
			var sWId = aWebgets[j].id;
			this.Webgets[sCol][sWId] = {
				stt: this.checkStatus(sWId),
				pos: j
			}
		}
		if (bSave) {
			MyMemory.remember(sCol, this.Webgets[sCol]);
		}
		
	}
};

