function pausecomp(millis) {
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

$(document).ready(function() {
	var ul = $('#agendaDesportiva ul');
	$('#agendaDesportiva').hover(function() { ul.show('slow'); }, function() { pausecomp(2000); ul.hide('slow') });
	$('#agendaDesportiva ul li').hover(
		function() {
			$(this).find('a').css('color', '#F0CE87');
			$(this).css('background-color', '#333333');
		},
		function() {
			$(this).find('a').css('color', 'white');
			$(this).css('background-color', 'gray');
		}
	);
	$('#agendaDesportiva ul li').click(function() { window.location.href=$(this).find('a').attr('href'); });
	$('span#name').click(function() { window.location.href=$(this).next().attr('href'); });
	$('#cronicaDirector a div img').click(function() { window.location.href=$(this).parents('a').attr('href'); });
});

var Newsletter = {
    submitAjax: function() {
        var newsletterNome = $('input[name=newsletter_nome]').val();
        var newsletterMail = $('input[name=newsletter_email]').val();
        
		if(newsletterNome == '' || newsletterMail == '') return;
		
		var properties = {
            type: "POST",
			url: "newsletter.subscribe.php",
			data: 'nome=' + escape(newsletterNome) + '&email=' + escape(newsletterMail),
			dataType: 'html',
			complete: function(req, suc) {
                alert(req.responseText);
			}
		};
		$.ajax(properties);
    }
}

var Poll = {
	showResults: function() {
    	$('#pollQuestions').hide('slow');
		$('#pollAnswers').show('slow');
 	},

	showPoll: function() {
    	$('#pollAnswers').hide('slow');
		$('#pollQuestions').show('slow');
 	},
 	
 	submitAjax: function() {
        pollAnswerSelected = 0;
	    var pollAnswers = $('input[name=resposta]');
	    for(i = 0; i < pollAnswers.length; i++) {
            if(pollAnswers[i].checked) {
		        pollAnswerSelected = pollAnswers[i].value;
            }
		}
		if(pollAnswerSelected == 0) return;
		
		pollQuestionId = $('input[name=poll_id]').val();
		
		var properties = {
            type: "POST",
			url: "poll.vote.php",
			data: 'poll=' + pollQuestionId + '&answer=' + pollAnswerSelected,
			dataType: 'html',
			complete: function(req, suc) {
	            $('#pollAnswers').empty();
	            $('#pollAnswers').append(req.responseText);
	            Poll.showResults();
			}
		};
		$.ajax(properties);
    }
}

var Concursos = {
	openPopup: function() {
		var popupConcursos = window.open('/concursos.php', 'concursosWin', 'height=450,width=600,toolbar=no,status=no,scrollbars=yes');	
	},
	
	resizePopup: function(w, h) {
		if(navigator.appName.indexOf("Microsoft")!=-1){
			document.body.offsetWidth = w;
			document.body.offsetHeight = h;
		}
		if (navigator.appName=="Netscape") {
			window.innerWidth = w;
			window.innerHeight = h;
		}
	},
	centraJanela: function(){
		if(navigator.appName.indexOf("Microsoft")!=-1){
			var winxpos = (window.screen.width-document.body.offsetWidth)/2
			var winypos = (window.screen.height-document.body.offsetHeight)/2
		}
		if (navigator.appName=="Netscape") {
			var winxpos = (window.screen.width-window.innerWidth)/2
			var winypos = (window.screen.height-window.innerHeight)/2
		}
		window.moveTo(winxpos,winypos);
	}	
}
