// -- Custom
var _Custom = {
	
	Slide: {
		
		indexCurrent: null,
		oSlides: null,
		
		slide: function() {
			each(_Custom.Slide.oSlides, function(el) { addClass(el, 'hide'); }); 
			remClass(_Custom.Slide.oSlides[_Custom.Slide.indexCurrent], 'hide'); 
			_Custom.Slide.indexCurrent = (_Custom.Slide.indexCurrent == _Custom.Slide.oSlides.length - 1) ? 0 : _Custom.Slide.indexCurrent + 1; 
			$('div.slide > div').inner_slide('#ct-auxiliar', 'left', { duration: 'slow' });
			setTimeout("_Custom.Slide.slide()", 6000); 
		},
		
		iniciar: function() {
			_Custom.Slide.indexCurrent = 0; 
			_Custom.Slide.oSlides = filter(getAll('div', 'ct-auxiliar'), function(el) { return el.parentNode.getAttribute('id') == 'ct-auxiliar' && hasClass(el.parentNode, 'slide'); }); 
			if (_Custom.Slide.oSlides.length > 1) _Custom.Slide.slide();
		}
		
	},
	
	PopupImagem: function(e) {
		
		e.preventDefault()
		
		var src = e.currentTarget
		
		var width = parseInt(src.getAttribute('href').split('&').filter(function(el) { if (el.substr(0, 2) == 'w=') return true })[0].substr(2))
		var height = parseInt(src.getAttribute('href').split('&').filter(function(el) { if (el.substr(0, 2) == 'h=') return true })[0].substr(2))
		var bLegenda = (src.getAttribute('href').indexOf('Legenda=') != -1)  
		
		var iWidth = 660, iHeight = 580, iTop, iLeft
		
		iWidth += 20 // scrollbars
		
		iTop = 30
		iLeft = parseInt((screen.width - iWidth) / 2)
		
		return Popup.link(src, 'width=' + iWidth + ',height=' + iHeight + ',top=' + iTop + ',left=' + iLeft + ',scrollbars=1,location=0,statusbar=0,menubar=0')

	}, 
	
	iniciar: function() {
		var o
		
		// Acrescenta classe "script" no elemento "body"
		addClass(getAll('body')[0], 'script')
		
		// Popups de imagem
		if ((o = getElem('imagens'))) addEvent(getAll('a', o), 'click', _Custom.PopupImagem)
		each(getElementsByClass('galeria'), function(el) { addEvent(getAll('a', el), 'click', _Custom.PopupImagem) })
		
		// Abre links com classe 'externo' em nova página
		addEvent(getElementsByClass('externo', 'a'), 'click', Popup.event)
		
	}
	
}