window.addEvent('domready', function() {
	for (modCnt=0; modCnt < horoscopo.modules.length;modCnt++){
 		switch(horoscopo.modules[modCnt].openmethod){
			case 'mootoolsLightbox':
				horoscopo.lightboxActive = false;
				addMootoolsLightbox(horoscopo.modules[modCnt].id);
				break;
			case 'newWindow':
				addNewWindow(horoscopo.modules[modCnt].id);
				break;
			default:
		}
	}
});

function addMootoolsLightbox(moduleId){
	document.getElements('.closeBtn').each(function(element){
		element.addListener('click', function(event){ $$('#lightbox'+moduleId).fireEvent('click'); });
	});

	document.getElements('.horoscopo'+ moduleId +' a').each(function(element){
		element.addListener('click', function(event) {
			new Event(event).stop();
			if (horoscopo.lightboxActive) return;

			horoscopo.lightboxActive = true;
			$("predictionFrame"+ moduleId)
				.set({'src': element.href })
				.addEvent('load', function(){
					$("predictionFrame"+ moduleId).removeEvents('load');
					var background = new Element('div', {
						'id': 'lightbox'+moduleId,
						'class': 'horoscopo-lightbox',
						'events': {
							'click': function(){
								horoscopo.lightboxActive = false;
								this.remove();
								$('lightbox-panel'+ moduleId).setStyle('display', 'none').setStyle('opacity',0);
							}
						}
					}).inject($('lightbox-panel'+moduleId).getParent(),'top');
					new Fx.Styles(background, { duration: 1000 }).start({ 'opacity': ['0', '0.7'] });
					new Fx.Styles('lightbox-panel'+ moduleId, { duration: 1000 }).start({ 'opacity': ['0', '1'] });	
					$('lightbox-panel'+ moduleId).setStyle('display', 'block');
				});
		});
	});
}

function addNewWindow(moduleId){
	document.getElements('.horoscopo'+ moduleId +' a').each(function(element){
		element.addEvent('click', function(evnt){
						new Event(evnt).stop();
						openSign(element.href);
		});
	});
}

function openSign( link ){
	WindowObjectReference = window.open(link,'prediction','width=440,height=530,toolbar=no,location=no,directories=no,scrollbars=yes,status=no,menubar=no');
    if(WindowObjectReference.focus) {
	  WindowObjectReference.focus();
    }	
}
