// -- Custom
var _Custom = {
	
	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 iScrollbars = 0, iWidth, iHeight, iTop, iLeft
		
		iWidth = 500
		iHeight = 500
		if (height > 500 || bLegenda) { iWidth += 20; iScrollbars = 1 }
		if (height <= 500 && bLegenda) { iWidth -= 20; iHeight += 30; iScrollbars = 0 }
		iHeight += 40
		iWidth += 70
		
		iTop = parseInt((screen.height - iHeight) / 2)
		iLeft = parseInt((screen.width - iWidth) / 2)
		
		return Popup.link(src, 'width=' + iWidth + ',height=' + iHeight + ',top=' + iTop + ',left=' + iLeft + ',scrollbars=' + iScrollbars + ',location=0,statusbar=0,menubar=0')

	}, 
	
	addFakeHover: function(els, classe) {
		classe = classe || 'hover'
		addEventDict(els, 
			{ 
				'mouseover' : function(e) { addClass(e.currentTarget, classe) },
				'focus' : function(e) { addClass(e.currentTarget, classe) },
				'mouseout' : function(e) { remClass(e.currentTarget, classe) },
				'blur' : function(e) { remClass(e.currentTarget, classe) }
			}
		)
	},
	
	iniciar: function() {
		var o
		
		// Acrescenta classe "script" no elemento "body"
		addClass(getAll('body')[0], 'script')
		
		// Hover do menu
		each(getAll('li', 'ct-menu'), function(el) { 
			if (hasClass(el, 'submenu')) { 
				_Custom.addFakeHover(el, el.className + '-hover')
				_Custom.addFakeHover(el, el.getAttribute('id') + '-hover')
			}
		})
		addEvent(getAll('a', 'ct-menu').filter(function(el) { return hasClass(el.parentNode, 'submenu') }), 'click', function(e) { e.preventDefault() })
		
		// Popups de imagem
		if ((o = getElem('fotos'))) addEvent(getAll('a', o), 'click', _Custom.PopupImagem)
		if ((o = getElem('certificados'))) addEvent(getAll('a', o), 'click', _Custom.PopupImagem)
		if ((o = getElem('imagens'))) addEvent(getAll('a', o), 'click', _Custom.PopupImagem)

		// Popups de imagem
		//each(getElementsByClass('galeria'), function(el) { addEvent(getAll('a', el), 'click', _Custom.PopupImagem) })

		// Popup da página inicial
		if (Page.getCurrent() == '/default2.asp')
			if ((o = getElem('popup'))) {
				var oA = document.createElement('a')
				oA.setAttribute('href', '#')
				oA.setAttribute('title', 'Fechar')
				oA.className = 'fechar'
				oA.appendChild(document.createTextNode('Fechar'))
				o.appendChild(oA)
				addEvent(oA, 'click', function(e) { e.preventDefault(); addClass(e.currentTarget.parentNode, 'hide') })
			}		

		// Abre links com classe 'externo' em nova página
		addEvent(getElementsByClass('externo', 'a'), 'click', Popup.event)
		
	}
	
}
