	ajax = {
		makeObject: function() {
		  var xmlhttp;
		  /*@cc_on
		  @if (@_jscript_version >= 5)
		    try {
		      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
		      try {
		        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		      } catch (E) {
		        xmlhttp = false;
		      }
		    }
		  @else
		  xmlhttp = false;
		  @end @*/
		  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		    try {
		      xmlhttp = new XMLHttpRequest();
		    } catch (e) {
		      xmlhttp = false;
		    }
		  }
		  return xmlhttp;
		},

		loadData: function(year,month) {
			month++;
			var myurl = '/getCalendar.php?year='+year+'&month='+ month;
			
			http.open("GET", myurl, true);
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
					eventData = eval("("+http.responseText+")");
					//alert(year + ',' + month + ',' + eventData);
					calendar.parseData(eventData);
				}
			}
			http.send(null);
		}
	}
	
	calendar = {
		months: new Array('JANUAR', 'FEBRUAR', 'MAREC', 'APRIL', 'MAJ', 'JUNIJ', 'JULIJ', 'AVGUST', 'SEPTEMBER', 'OKTOBER', 'NOVEMBER', 'DECEMBER'),
		currMonth: new Date().getMonth(),
		currYear: new Date().getFullYear(),
		timer: 0,
				
		init: function() {
			this.currMonth = new Date().getMonth();
			this.currYear = new Date().getFullYear();
			
			ajax.loadData(this.currYear,this.currMonth);
		},
		
		nextMonth: function() {
			if (this.currMonth < 11) this.currMonth++;
			else {
				this.currMonth = 0;
				this.currYear++;
			}
			ajax.loadData(this.currYear,this.currMonth);
			// this.drawMonth(this.currYear,this.currMonth);
		},

		prevMonth: function() {
			if (this.currMonth > 0) this.currMonth--;
			else {
				this.currMonth = 11;
				this.currYear--;
			}
			
			ajax.loadData(this.currYear,this.currMonth);
			// this.drawMonth(this.currYear,this.currMonth);
		},
				
		parseData: function(data) {
			this.calData = data;
			this.drawMonth(this.currYear,this.currMonth);
		},
		
		showDay: function(day) {
			tmpHTML = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width: 219px;\"><tr><td colspan=\"3\" style=\"width: 219px; height: 34px; background: url('/images/koledarcek_top.png'); text-align: center;\">";
			tmpHTML += "<p style=\"font-weight: bold; margin: 7px 0px 0px 0px;\">Dogodki, "+ day + ". "+ this.months[this.currMonth] + "</p>";
			tmpHTML += "</td></tr><tr><td style=\"width: 8px; height: 200px; background: url('/images/koledarcek_left.png');\">&nbsp;</td><td style=\"width: 202px; background: #fff url('/images/koledarcek_back.png') repeat-x; vertical-align: top;\"><div style='margin: 3px 10px; font-size: 11px; line-height: 14px;'>";
			//tmpHTML = "<table cellpadding='0' cellspacing='0' border='0' style='width: 156px;' id='eventTable' onmouseover='calendar.resetTimer();'><tr><td><img src='/images/eventsTop.gif' alt='eTop' /></td></tr><tr><td style='border-left: 1px solid #d8d8d8; border-right: 1px solid #d8d8d8; background-color: #ffffff; vertical-align: top;'><p style='margin: 0px 8px; font-size: 11px; color: #000000;'>";
			targetDiv = document.getElementById('events');

			for (var x in this.calData[day]) {
				if (this.calData[day][x]["hour"]) {	
					if (this.calData[day][x]["location"]) tmpHTML += "<b>Lokacija:</b> "+ this.calData[day][x]["location"] + "<br />";
					if (this.calData[day][x]["hour"]) tmpHTML += "<b>Ura:</b> "+ this.calData[day][x]["hour"] + "<br />";
					if (this.calData[day][x]["end"]) tmpHTML += "<b>Zaključek:</b> "+ this.calData[day][x]["end"] + "<br />";

					tmpHTML += "<div style='margin: 6px 0px 15px 0px; border-bottom: 1px dotted #999; padding-bottom: 4px;'>";
					if (this.calData[day][x]["link"]) tmpHTML += '<a href="'+this.calData[day][x]["link"]+'" style="font-size: 11px; line-height: 14px;">'+this.calData[day][x]["title"]+'</a>';
					else tmpHTML += this.calData[day][x]["title"];
					
					// tmpHTML += this.calData[day][x]["text"];
					tmpHTML += "</div>";
				}
			}
			// tmpHTML = tmpHTML.substring(0, (tmpHTML.length-12));
			
			tmpHTML += "</div></td><td style=\"width: 9px; background: url('/images/koledarcek_right.png');\">&nbsp;</td></tr>";
			tmpHTML += "<tr><td style=\"background: url('/images/koledarcek_left.png');\">&nbsp;</td><td style=\"background: #fff;\"><p style='text-align: right; margin: 4px 10px 0px 0px;'><a href='javascript:calendar.hideDay();'><img src='/images/lightview/close_large.png' alt='close'></a></p></td><td style=\"background: url('/images/koledarcek_right.png');\">&nbsp;</td></tr>";
			tmpHTML += "<tr><td colspan=\"3\" style=\"width: 219px; height: 22px; background: url('/images/koledarcek_bottom.png'); text-align: center;\">&nbsp;</td></tr></table>";
			//tmpHTML += "</p><p style='text-align: right; margin: 4px 10px 0px 0px;'><a href='javascript:calendar.hideDay();'><img src='/images/lightview/close_large.png' alt='close'></a></p></td></tr><tr><td><img src='/images/eventsBottom.gif' alt='eTop' /></td></tr></table>";
			targetDiv.innerHTML = tmpHTML;
			targetDiv.style.visibility = 'visible';
			
			// calendar.timer = setTimeout(calendar.hideDay, 5000);
		},
		
		hideDay: function() {
			targetDiv = document.getElementById('events');
			targetDiv.style.visibility = 'hidden';
			
			clearTimeout(calendar.timer);
		},
		
		resetTimer: function() {
			clearTimeout(calendar.timer);
			
			// pageFunctions.addEvent(document.getElementById('eventTable'), 'mouseout', calendar.hideDay);
		},
		
		drawMonth: function(year,month) {
			var mydate = new Date(year,month,1);
			var totaldays = mydate.daysInMonth() + mydate.getDay();
			var rows = Math.ceil(totaldays/7);
			var totalfields = rows*7;
			var out;
			var htmlOut = "";
			var dayHasEvents;
			htmlOut = '<table cellpadding="0" cellspacing="0" border="0" style="width: 154px;" id="koledarcek">';
			htmlOut += '<tr><td style="width: 21px; background-color: #fff2e5; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>N</strong></td><td style="width: 21px; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>P</strong></td><td style="width: 21px; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>T</strong></td><td style="width: 21px; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>S</strong></td><td style="width: 21px; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>Č</strong></td><td style="width: 21px; border-right: 1px solid #d3c8c2; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>P</strong></td><td style="width: 21px; border-bottom: 1px dotted #d8d8d8; border-top: 1px dotted #d8d8d8;"><strong>S</strong></td></tr>';
			
			for (var i=0; i<totalfields; i++) {
				if (i == 0) htmlOut += '<tr>';
				if (i>0 && i%7 == 0) htmlOut += '</tr><tr>';
				
				if (i<mydate.getDay() || (i-mydate.getDay()>=mydate.daysInMonth())) out = '&nbsp;';
				else out = i-mydate.getDay()+1;
				
				dayHasEvents = false;
				for (var x in this.calData) {
					if (x == out) dayHasEvents = true;
				}

				if (dayHasEvents) {
					if (i%7 == 0) htmlOut += '<td style="width: 21px; background-color: #f2f5bc; border-right: 1px solid #d3c8c2;" onclick="calendar.showDay('+out+');"><a href="javascript:void(0);" style="font-family: Verdana; font-size: 10px; font-weight: normal;"><b>'+out+'</b></a></td>';
					else if ((i+1)%7 == 0) htmlOut += '<td style="width: 21px; background-color: #f2f5bc" onclick="calendar.showDay('+out+');"><a href="javascript:void(0);" style="font-family: Verdana; font-size: 10px; font-weight: normal;"><b>'+out+'</b></a></td>';
					else htmlOut += '<td style="width: 21px; border-right: 1px solid #d3c8c2; background-color: #f2f5bc" onclick="calendar.showDay('+out+');"><a href="javascript:void(0);" style="font-family: Verdana; font-size: 10px; font-weight: normal;"><b>'+out+'</b></a></td>';
				}
				else {
					if (i%7 == 0) htmlOut += '<td style="width: 21px; background-color: #fff2e5; border-right: 1px solid #d3c8c2; ">'+out+'</td>';
					else if ((i+1)%7 == 0) htmlOut += '<td style="width: 21px;">'+out+'</td>';
					else htmlOut += '<td style="width: 21px; border-right: 1px solid #d3c8c2;">'+out+'</td>';
				}
				
				if (i == (totalfields-1)) htmlOut += '</tr>';
			}
			htmlOut += '<tr><td style="height: 5px; width: 21px; background-color: #fff2e5; border-right: 1px solid #d3c8c2; "><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px; border-right: 1px solid #d3c8c2;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px; border-right: 1px solid #d3c8c2;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px; border-right: 1px solid #d3c8c2;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px; border-right: 1px solid #d3c8c2;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px; border-right: 1px solid #d3c8c2;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td><td style="height: 5px; width: 21px;"><img src="/images/spacer.gif" alt="/" style="width: 20px; height: 5px;" /></td></tr>';
			htmlOut += '</table>';
			
			var target = document.getElementById('clndContainter');
			target.innerHTML = htmlOut;
			
			var mesectarget = document.getElementById('mesecName');
			mesectarget.innerHTML = this.months[this.currMonth] + " " + this.currYear.toString().substring(2);
			// mesectarget.innerHTML = this.currMonth + ", " + this.currYear;
		}
	}
	
	var http = ajax.makeObject();
	pageFunctions.addEvent(window, 'load', calendar.init);