// JavaScript Document

// clock.js a clock that update only when it's really required and what is required.
// What i mean with this is that for exemplo at the time 10:11:00 the clock just update the seconds and the minutes, not que hours.
// the close doesn't update at a fixed time like almost every clocks, just update when the output is different form the actual output
//
// Author: João Santos (jarsantos@gmail.com)
//
// Everyone can use it and change it, but keep the credits please
// Enjoy!

var weekDays = new Array("Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado")
var months = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
	
function formatClock(int)
{
	if(int < 10)
	{
		int = '0'+int
	}
	
	return int
}

function startClock()
{	
	var date = new Date()
	
	var time = new Array(date.getHours(), formatClock(date.getMinutes()), formatClock(date.getSeconds()))
	
	var weekDay = date.getDay()
	var month = date.getMonth()
	var day = new Array(weekDay, weekDays[weekDay], date.getDate(), month, months[month], date.getFullYear())
	
	return new Array(time, day)
}

function updateClock(passado)
{
	time = passado[0]
	day = passado[1]
	clockInfo = passado[2]
	
	date = new Date()
	
	time[2] = formatClock(date.getSeconds())
	
	if(time[2] == '00')
	{
		time[1] = formatClock(date.getMinutes())
	
		if(time[1] == '00')
		{
			time[0] = date.getHours()
	
			if(time[0] == 0)
			{
				day[0] = date.getDay()
				day[1] = weekDays[day[0]]
		
				day[2] = date.getDate()
	
				if(day[2] == 1)
				{
					day[3] = date.getMonth()
					day[4] = months[day[3]]
	
					if(day[3] == 1)
					{
						day[5] = date.getFullYear();
					}
				}
			}
		}
	}
	
	var saudacao;
	
	if(6<time[0] && time[0]<13)
	{
		saudacao = "Bom dia, seja bem-vindo(a)!"
	}
	else if(12<time[0] && time[0]<20)
	{
		saudacao = "Boa tarde, seja bem-vindo(a)!"
	}
	else
	{
		saudacao = "Boa noite, seja bem-vindo(a)!"
	}
	
	document.getElementById('clock').innerHTML=saudacao+"<br />"+day[1]+', '+day[2]+' de '+day[4]+' de '+day[5]+' - '+time.join(':')
	
	t=setTimeout('updateClock(new Array(time, day))',1000-(new Date().getMilliseconds()))	
}
