// -- 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 iWidth = 740, iHeight = 550, 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')

	}, 
	
	init: function() {
		var o
		
		addClass(getAll('body')[0], 'script')
		
		// Popups de imagem
		if ((o = getElem('imagens'))) addEvent(getAll('a', o), 'click', _Custom.PopupImagem)

		// Popup Responsabilidade Social e Principios Express
		if (Page.isCurrent('responsabilidade_social.asp') || Page.isCurrent('nossa_historia.asp'))  {
			iHeight = (screen.height > 700) ? 750 : 750
			addEvent('popup', 'click', Popup.eventFeatures('width=620, height=' + iHeight + ', top=0, left=0, scrollbars=1'))
		}
		
		// Navegação das dicas
		if ((o = getElem('dicas'))) Dicas.init()

		// Enquete
		if ((o = getElem('f-enquete')))
			addEvent(o, 'submit', function(e) { 
				var src = e.currentTarget;
				e.preventDefault(); 
				if (filter(getAll('input', src), function(el) { return el.checked }).length == 0)
					alert('Você deve selecionar uma alternativa da enquete'); 
				else {
					var wEnquete = window.open(src.getAttribute('action'), 'wEnquete', 'width=338, height=300, scrollbars=1')
					wEnquete.focus()
					src.setAttribute('target', 'wEnquete')
					src.submit()
				}
			})
			
		// Abre receitas em popup
		addEvent(getElementsByClass('receita', 'a'), 'click', Popup.eventFeatures('width=600, height=600, scrollbars=1'))
		
		// Imprimir receitas
		if (Page.isCurrent('popup_receita.asp')) {
															
			var oA = document.createElement('a')
			oA.setAttribute('href', '#')
			oA.appendChild(document.createTextNode('Imprimir esta receita'))
			
			oP = document.createElement('p')
			oP.setAttribute('id', 'impressao')
			oP.appendChild(oA)
			
			getElem('conteiner').appendChild(oP)
				
			addEvent(oA, 'click', function() { window.print() })
			
		}
		
		// Popup da página inicial
		if (Page.getCurrent() == '/default.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)
		
	}
	
}