
window.addEvent('domready', function(){
	
	$$('.MGroupContent').setStyle('display', 'block');
	
	var selected = $('MSelected');
	
	var current = (selected) ? selected.getParent() : false;

	$$('div.MGroup').each(function(div){
		var link = div.getElement('a');
		var block = link.getNext();
		
		var fx = new Fx.Slide(block);
		
		if (block != current) fx.hide();

		link.addEvent('click', function(){
			fx.toggle();
		});
		
	});
	
	$$('.CTitle').each(function(heading){
		new Element('a', {
			'href': '#MainTopic',
			'class': 'toTop'
		}).setHTML('top').injectBefore(heading.getFirst());
	});
	
	new SmoothScroll();
	
});

document.write('<style type="text/css" media="screen">div.MGroupContent{display: none}</style>');
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(div,e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.div : document.getElementById(div);  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}



function div_switch (div,divvar)   {
	var divid=document.getElementById(div);
	var alto=parseInt(getStyle (divid,"height"));
	var altow=isIE?document.body.clientHeight:window.innerHeight;
   	if (divid.style.visibility=='visible'){
      divid.style.visibility = 'hidden'; 
      
   } else  {
   	  divvar.write(div);
      divid.style.visibility = 'visible'; 
   } 
}

function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)   
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ?
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}

function getStyle(el, style) {
   if(!document.getElementById) return;
     var value = el.style[toCamelCase(style)];
    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);
        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];
     return value;
}

function setStyle(objId, style, value) {
    document.getElementById(objId).style[style] = value;
}

var oldLink = null;
function setActiveStyleSheet(link, title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	if (oldLink) oldLink.style.fontWeight = 'normal';
	oldLink = link;
	return false;
}
function selected(cal, date) {
	cal.sel.value = date; 
	if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
	cal.callCloseHandler();
}

function closeHandler(cal) {
	cal.hide();                        
	//  cal.destroy();
	_dynarch_popupCalendar = null;
}
function showCalendar(id, format, showsTime, showsOtherMonths) {
	var el = document.getElementById(id);
	if (_dynarch_popupCalendar != null) {
		_dynarch_popupCalendar.hide();  
	} else {
		var cal = new Calendar(1, null, selected, closeHandler);
		// cal.weekNumbers = false;
		if (typeof showsTime == "string") {
			cal.showsTime = true;
			cal.time24 = (showsTime == "24");
		}
		if (showsOtherMonths) {
			cal.showsOtherMonths = true;
		}
		_dynarch_popupCalendar = cal;  
		cal.setRange(2006, 2010);   
		cal.create();
	}
	_dynarch_popupCalendar.setDateFormat(format); 
	_dynarch_popupCalendar.parseDate(el.value);  
	_dynarch_popupCalendar.sel = el; 
	_dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");       
	return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function dateChanged(calendar) {

if (calendar.dateClicked) {
var y = calendar.date.getFullYear();
var m = calendar.date.getMonth()+1; // integer, 0..11
var d = calendar.date.getDate(); // integer, 1..31
window.location = "eventos/" + d + "/" + m + "/" + y+".htm";
}
};
function isDisabled(date) {
	var today = new Date();
	return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
	var el = document.getElementById("preview");
	el.innerHTML = date;
}

function showFlatCalendar() {
	var parent = document.getElementById("display");
	var cal = new Calendar(0, null, flatSelected);

	cal.weekNumbers = false;
	cal.setDisabledHandler(isDisabled);
	cal.setDateFormat("%A, %B %e");
	cal.create(parent);
	cal.show();
}
