/******************************************** Copyright Class ********************************************/
var liveclockdate = new Class({
///////////////////////////////////////////////// Options /////////////////////////////////////////////////
	options: {
		hoursystem:0,
		clockupdate:1,
		suffix:'',
		display:'',

		language:'en-GB',
		
		wrapper:false
     },
///////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////// Constructor ///////////////////////////////////////////////
	initialize:function(id,options) {	
/*############################################# properties ##############################################*/
		var that = this;			//holds the instance

		this.id = id;				//holds the module number
		this.setOptions(options);  //sets the options

		//adds the instance to the cache array
		liveclockdateCache.addInstances(this);
		
		this.daysOfWeek = null;
		this.monthsOfYear = null;
		
		this.clockUpdate = new Array(0,1000,60000);
		
		this.timeObj = false;
		this.dateObj = false;
/*#######################################################################################################*/



/*############################################### methods ###############################################*/
		//creates the module content
		this.create = function(){
			if(!this.options.wrapper) return;
			
			var wrapperObj = $(this.options.wrapper);	//gets the liveclock div wrapper
			if(!wrapperObj) return;
			
			//sets the display elements
			switch(this.options.display)
			{
				case '1':
							this.timeObj = new Element('div', {'class': 'liveclock_time'+this.options.suffix});
							this.timeObj.inject(wrapperObj);
							break;
				case '2':
							this.dateObj = new Element('div', {'class': 'liveclock_date'+this.options.suffix});
							this.dateObj.inject(wrapperObj);
							break;
				default:
							this.timeObj = new Element('div', {'class': 'liveclock_time'+this.options.suffix});
							this.dateObj = new Element('div', {'class': 'liveclock_date'+this.options.suffix});
							this.timeObj.inject(wrapperObj);
							this.dateObj.inject(wrapperObj);
			}
			
			//gets tje language if the data is visible
			if(this.dateObj)
				this.getLanguage();
			
			//starts the clock
			this.update();
		}
		
		//clock and date cicle
		this.update = function(){
			//creates the data and clock object
			var clock = new Date();
			
			//if the data is visible, shows the data information
			if(that.dateObj)
			{
				var day = clock.getDay();		//holds the day
				var mday = clock.getDate();		//holds the week day
				var month = clock.getMonth();	//holds the month
				
				that.dateObj.innerHTML = that.daysOfWeek[day]+', '+mday+' '+that.monthsOfYear[month];
			}
			
			//if the time is visible, updates the clock
			if(that.timeObj)
			{
				var hours = clock.getHours();		//holds the hour
				var minutes = clock.getMinutes();	//holds the minutes
				var seconds = clock.getSeconds();	//holds the seconds
	
	
				var datePrefix = '';
				
				//sets the hour
				if (that.options.hoursystem==1) {
					datePrefix = "AM";
					if (hours == 0)
						hours = 12;
					if (hours > 12) {
						datePrefix = "PM";
						hours = hours - 12;
					}
				}
	
				if (minutes <= 9) { minutes = "0"+minutes; }	//sets the minutes
				if (seconds <= 9) { seconds = "0"+seconds; }	//sets the seconds
				
				//sets the time
				var time = hours+':'+minutes;
				if(that.options.clockupdate==1) time += ':'+seconds;
				if(datePrefix!='')	time += ' '+datePrefix;
				
				that.timeObj.innerHTML = time;
			}
			
			//sets the time when the clock will be updated
			if(that.options.clockupdate != 0)
				setTimeout(that.update,that.clockUpdate[that.options.clockupdate]);
		}
		
		//return the data content language
		this.getLanguage = function(){
			switch(this.options.language)
			{
				case "en-GB":
								this.daysOfWeek=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
								this.monthsOfYear=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
								break;
				case "de-DE":
								this.daysOfWeek=new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
								this.monthsOfYear=new Array("Januar","Februar","Marz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
								break;
				case "es-ES":
								this.daysOfWeek=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado");
								this.monthsOfYear=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
								break;
				case "pt-PT":
								this.daysOfWeek=new Array("Domingo","Segunda-Feira","Ter&ccedil;a-Feira","Quarta-Feira","Quinta-Feira","Sexta-Feira","S&aacute;bado");
								this.monthsOfYear=new Array("Janeiro","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
								break;
				case "fr-FR":
								this.daysOfWeek=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vndredi","Samedi");
								this.monthsOfYear=new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre");
								break;
				case "it-IT":
								this.daysOfWeek=new Array("Domenica","Lunedi","Martedi","Mercoled","Gioved","Venerd","Sabato");
								this.monthsOfYear=new Array("Gennaio","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
								break;
				case "ru-RU":
								this.daysOfWeek=new Array("Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота");
								this.monthsOfYear=new Array("Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь");
								break;
				case "da-DK":
								this.daysOfWeek=new Array("Søndag","Mandag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag");
								this.monthsOfYear=new Array("Januar","Februar","Marts","April","Maj","Juni","Juli","August","September","Oktober","November","December");
								break;
				case "fi-FI":
								this.daysOfWeek=new Array("Sunnuntai","Maanantai","Tiistai","Keskiviikko","Torstai","Perjantai","Lauantai");
								this.monthsOfYear=new Array("Tammikuu","Helmikuu","Maaliskuu","Huhtikuu","Toukokuu","Kesäkuu","Heinäkuu","Elokuu","Syyskuu","Lokakuu","Marraskuu","Joulukuu");
								break;
				case "nb-NO":
								this.daysOfWeek=new Array("Søndag","Måndag","Tirsdag","Onsdag","Torsdag","Fredag","Lørdag");
								this.monthsOfYear=new Array("Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember");
								break;
				case "sv-SE":
								this.daysOfWeek=new Array("Söndag","Måndag","Tisdag","Onsdag","Torsdag","Fredag","Lördag");
								this.monthsOfYear=new Array("Januari","Februari","Mars","April","Maj","Juni","Juli","Augustus","September","Oktober","November","December");
								break;
				case "nl-NL":
								this.daysOfWeek=new Array("Zondag","Maandag","Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag");
								this.monthsOfYear=new Array("Januari","Februari","Maart","April","Mei","Juni","Juli","Augusti","September","Oktober","November","December");
								break;
				default:
								this.daysOfWeek=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
								this.monthsOfYear=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
								break;
			}
		}
/*#######################################################################################################*/
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
});
liveclockdate.implement(new Events, new Options);
/*********************************************************************************************************/



/*************************************** Copyright Cache Object ******************************************/
var liveclockdateCache = {
	instances:new Array(),		//holds the instances
	
	//adds an instance
	addInstances:function(obj){
		this.instances.push(obj);
	},
	
	//inicialize all instances
	loadInstances:function(){
		for (var i=0; i<this.instances.length; i++)
			this.instances[i].create();
	}
};
/*********************************************************************************************************/



/************************************ Initialize the Copyright instances *********************************/
window.addEvent("load",function(){
	liveclockdateCache.loadInstances();
});
/*********************************************************************************************************/