/*

How to call this routine to build the data

REQUIRED PARAMETERS:
callname			id
sitepath			site path to images/files			
eventsAreaId		location of widget data
feed				rss feed

OPTIONAL PARAMETERS:
uniqueid			# ([0]-9999999)						when multiple widgets are on one page, each must have unique identifier
google				true | [false]						use google to load feed otherwise load using xmlhttp
loadingImage		image to show during the loading of the data
navigation 			"top" | ["bottom"] | "off"			
displaytabs			true | [false]						if tabs are needed then the prototabs.js file is called to build the tabbed data
displaybody			true | [false]						if true then an additional call is made to load the content of the item
displaydate			[true] | false						show content date
prevlink			text to display for previous link [Previous]
nextlink			text to display for next link [Next]
minicalshow			true | [false] 						allocate widgetcal.js and build/show minical
calContentAreaId	location to place minical
titlelinkable		[true] | false                      is title a hyperlink?
showreadmore		true | [false]						if read more link exists then add to summary
showadditional		true | [false]						if feed tag additional exists then display in it's own div for placement
printoverride		true | [false]						if "printer friendly page" link on page, override onclick

widgetdata = new Widget({
				navigation : "top",
				displaytabs : true,
				displaybody : true,
				displaydate : true,				
				uniqueid : 0,
				callname : "lectdata2",
				sitepath : "/atf/cf/{3482E846-598F-460A-B9A7-386734470EDA}/",
				minicalshow : true,
				prevlink : "Previous",
				nextlink : "Next",
				google : true,
				titlelinkable : true,
				eventsAreaId : "event-widget-area",
				calContentAreaId : "cal-content-widget-area",
				loadingImage : "loading.gif",
				feed : "-- rss url --"
			});

=> classes and id's
#additional 
#additional a 
.additional_text 
.additional_link1
.additional_link2
#additional hr
.date
.title 
.summary 
.summary a 
.body
.leftarrow
.rightarrow
.feature_image
#minical
#show-mini-cal

*/
/* get RSS Feed and return only the record matching today's date */

function Widget(params) {
	/*
	 *	Initializing parameters - get all params from initial call and set values
	 */
	this.createParams = function (params) {
		
				this.params = new Array();
				this.params = params;
				
				if($(params.eventsAreaId)) {
					this.eventsAreaId = params.eventsAreaId;
				} else {
					alert('Error: Events Area not found\nLooking for object with id \''+params.eventsAreaId+'\'');
				}

				if(params.feed) {
					this.feed = params.feed;
				} else {
					alert('Error: Feed not found in initilization\nInclude feed in initilization function');
					return;
				}
				
				if (params.sitepath) 
					this.sitepath = params.sitepath;
				else {
					alert('Error: sitepath not found in initilization\nInclude sitepath in initilization function');
					return;
				}

				if (params.callname) 
					this.callname = params.callname;
				else {
					alert('Error: callname not found in initilization\nInclude callname in initilization function');
					return;
				}
				
				this.google = (params.google != undefined) ? params.google : false;
				this.calContentAreaId = (params.calContentAreaId != undefined) ? params.calContentAreaId : this.eventsAreaId;
				this.loadingImage = (params.loadingImage != undefined) ? params.loadingImage : '';
				this.uniqueid = (params.uniqueid != undefined) ? params.uniqueid : 0;
				this.displaybody = (params.displaybody != undefined) ? params.displaybody : false;
				this.displaytabs = (params.displaytabs != undefined) ? params.displaytabs : false;
				this.displaydate = (params.displaydate != undefined) ? params.displaydate : true;
				this.navigation = (params.navigation != undefined) ? params.navigation : "bottom";
				this.topnode = (params.topnode != undefined) ? params.topnode : "content";
				this.prevlink = (params.prevlink != undefined) ? params.prevlink : "Previous";
				this.nextlink = (params.nextlink != undefined) ? params.nextlink : "Next";
				this.minicalshow = (params.minicalshow != undefined) ? params.minicalshow : false;
				this.titlelinkable = (params.titlelinkable != undefined) ? params.titlelinkable : true;
				this.showreadmore = (params.showreadmore != undefined) ? params.showreadmore : false;				
				this.showadditional = (params.showadditional != undefined) ? params.showadditional : false;
				this.printoverride = (params.printoverride != undefined) ? params.printoverride : false;
				this.lightboxtop = (params.lightboxtop != undefined) ? params.lightboxtop : '160'; //default to 140 pixels from the top

				//allocate minical.js
				if (this.minicalshow)
				    document.write('<script type="text/javascript" src="'+this.sitepath+'/widgetcal.js"><\/script>');
			}

	this.createLoading = function() {
				var loadingId = this.eventsAreaId;
				var loadingNode = document.getElementById(loadingId);
				var html = '';
				html = '<div class="'+this.callname+'-loading">';
				if (this.loadingImage != '')
					html += '<img src="'+this.sitepath+'/'+this.loadingImage+'" /><br />';
				html += 'Loading...';
				html += '</div>';

				loadingNode.innerHTML = html;
			}
	
	this.loadFeedData = function() {
			//get data
			if (this.google)
				var obj = new AjaxRequestGoogle(); //load google feed
			else
				var obj = new AjaxRequest();       //load standard xml httprequest
			obj.rss = this.feed;                   //rss feed
			obj.count = this.uniqueid;             //uniqueid
			obj.init();                            //send request to get data
			this.objRSS = obj;

			/* check status of data retrieval */
			this.checkDataStatus();                 //check data retrieval status
	}
	
	this.checkDataStatus = function() {
		var self = this;
		if (statusobj[self.uniqueid] == "running") { //still running?
			setTimeout(function(){self.checkDataStatus()}, 200); /* check status every 2 seconds */
		} else {
			//data has been retreived
			//store data 
			this.widgetdata = xhrs[this.uniqueid];   /* liturgical data    */

			this.getDates(); //get all dates and store in record

			$(params.eventsAreaId).innerHTML = '';
			if (this.minicalshow) {
				
				//$(params.eventsAreaId).innerHTML = '';
				this.minicaldiv = document.createElement("div");
				this.minicaldiv.id="minical";
				this.minicaldiv.style.display = (this.minicalshow) ? 'block' : 'none';
				$(this.calContentAreaId).insertBefore(this.minicaldiv, $(this.calContentAreaId).firstChild);
				
				this.widgetCalendar = new WidgetCalendar(this); /* calendar display */
				this.widgetCalendar.eventsNavAreaId = this.minicaldiv;
				this.widgetCalendar.sitepath = this.sitepath;
				this.widgetCalendar.daterange = false;
				this.widgetCalendar.init();
				this.rec_date = new Date();
			}
			
			if (this.checkURL("override") == "yes")	{
				var datearray = this.makeDate(this.checkURL("date"));
				if(window.console) {
					//console.log(datestring);
				}
				
				//adjust month:
				
				datearray['month'] = datearray['month'] - 1;
				
				var date = new Date(datearray['year'],datearray['month'],datearray['day']);
				this.getRecByDate(date);
			}			
			else {
			this.displayWidgetData();
			}
		}
	}
	
	this.makeDate = function(date) {
		splitdate = new Array();
	
		splitdate['year'] = date.substr(0,4);
		splitdate['month'] = date.substr(4,2);
		splitdate['day'] = date.substr(6,2);		
		stringdate = splitdate['year'] + ","	+ splitdate['month'] + "," + splitdate['day'];
		return splitdate;
	}

	this.checkURL = function(key) {
	
	
	// Check to see if we have already retrieved the key value pairs
	// if we haven't then we need to retrieve them
	if( window.location.variablePairs == null )
		{
		if( window.location.href.indexOf('?') == -1)
			{
			return false;	
			}
		window.location.variablePairs = window.location.href.substr( window.location.href.indexOf('?') + 1).split('&');
		}
	
	// Search for the key that matches the keyName supplied
	for( var x = 0; x < window.location.variablePairs.length; x++ )
		{
		// If we find the key name then we retun the value associated with it
		
		if( key == window.location.variablePairs[x].substr( 0, window.location.variablePairs[x].indexOf('=')))
			{
			return window.location.variablePairs[x].substr( window.location.variablePairs[x].indexOf('=') + 1);
			}
		}
	
	// If we couldn't find the key in the GET parameters
	// then we return false
	return false;
	
	}

	this.convertPrint = function(itemdata) {
			var self = this;
			if ($('print')) {
				$('print').innerHTML = '';
				var href = document.createElement("a");
				href.href = "#";
				href.innerHTML = 'Printer-friendly page';
				href.data = itemdata.innerHTML;
				href.sitepath = this.sitepath;
				href.onclick = function(){
					var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
					disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
					var docprint=window.open("","",disp_setting); 
					docprint.document.open(); 
					var html = '<html><head><title>Print Content</title>';
					//html +=    '<link href="'+this.sitepath+'print_template.css" rel="stylesheet" type="text/css" />';
					html +=    '</head><body onLoad="self.print()" id="inner">';
					html += 	this.data;
					html += '</body></html>'; 
					docprint.document.write(html);
					docprint.document.close(); 
					docprint.focus(); 
				}
				this.printLink = href;
				$('print').appendChild(href);
			}
		}
	
	/*
	 *	Initialization function - only looking for 1 feed
	 */
	this.displayWidgetData = function(){
			var filterDiv = '';
			var currentDate = new Date();
			
			/* sort descending - put all data in date order */
			this.widgetdata.sort(function (a, b){
						a = a['date'];
						b = b['date'];
						if (a>b) return 1;
						if (a<b) return -1;
						return 0; } );
						
						
			//itemdata.appendChild = buildData(currentDate);
			
			$(params.eventsAreaId).appendChild(this.buildData(currentDate));
			
			if ($("readmoreEXTlink")) $("readmoreEXTlink").innerHTML = "&nbsp;&nbsp;<a href='"+datalink+"'>Read More...</a>";
			/* look for print override - grab before tabs are added */
			
			if (this.displaytabs && this.displaybody) 
				tabs2('inner #tabContainer',this.rec_date);

		}
	
	this.buildData = function(recdate){
			var itemdata = document.createElement("div");
			itemdata.id = "inner-data";
			//find entry = or > than current date - if none found then display last one found.
			var entry_written = false;
			
			for (i=0;i<this.widgetdata.length;i++) {
				if(window.console) {
				console.log(this.widgetdata[i].title);
			}
			
			
				if (dateKey(this.widgetdata[i].date) >= dateKey(recdate)) {
					
					//find record date
					this.rec_date = this.widgetdata[i].date;
					
					for (z=0;z<this.datelist.length;z++) {
						if (dateKey(this.widgetdata[i].date) == this.datelist[z]) {
							this.curr_rec = z;
							break;
						}
					}

					this.writeTop(this.widgetdata[i]) //write top of widget
					this.writeImage(this.widgetdata[i]) //write feature image
					
					//loop through all recs matching date - if no rec found then write last rec found
					var rec = i;
					var rec_date = dateKey(this.widgetdata[i].date);
					while (rec < this.widgetdata.length) {
						if (window.console) {
						console.log("Widget Data:" + this.widgetdata[i]);
					}
						if (dateKey(this.widgetdata[rec].date) == rec_date) {
							this.writeRec(this.widgetdata[rec], rec)
						} else {
							break;
						}
						rec++;
					}
					var itemdetail = document.createElement("div");
					itemdetail.appendChild(this.filterDiv);     
					itemdata.appendChild(itemdetail); 			//write detail recs
					
					entry_written = true;
					
					this.writeBottom(this.widgetdata[i]); 		//write bottom of widget
					this.writeAdditional(this.widgetdata[i]); 	//checks for the additional field and writes whatever is in it
					//if minical selected then update dates on cal with entries found
					if (this.minicalshow) {
						this.widgetCalendar.dateObj.setMonth(this.rec_date.getMonth());
						this.widgetCalendar.changeMonth();
						this.displayEvents();
					}
					break;
				} else {
					
					this.curr_rec = this.datelist.length-1;
				}
			}
			if (!entry_written){
				var i = this.widgetdata.length-1;
				this.rec_date = this.widgetdata[i].date;
				var itemdetail = document.createElement("div");				
				
				this.writeTop(this.widgetdata[i]) //write top of widget
				this.writeImage(this.widgetdata[i], i); //write feature image
				
				this.writeRec(this.widgetdata[i], i);
				
				
				itemdetail.appendChild(this.filterDiv);
				itemdata.appendChild(itemdetail);           //write detail recs
				
				this.writeBottom(this.widgetdata[i]); 		//write bottom of widget
				this.writeAdditional(this.widgetdata[i]); 	//checks for the additional field and writes whatever is in it
				//if minical selected then update dates on cal with entries found
				if (this.minicalshow) {
					this.widgetCalendar.dateObj.setMonth(this.rec_date.getMonth());
					this.widgetCalendar.changeMonth();
					this.displayEvents();
				}
			}
			/* look for print override - grab before tabs are added */
			if (this.printoverride) 
				this.convertPrint(itemdata);

			return itemdata;
		}
	
	this.getDates = function(){
			var datearr = [];
			var datelistarr = [];
			var prevdate = new Date('1/1/1970');
			for (i=0;i<this.widgetdata.length;i++) {	
				if (dateKey(this.widgetdata[i].date) != dateKey(prevdate)) {
					datearr.push(dateKey(this.widgetdata[i].date));
					datelistarr.push(this.widgetdata[i].date);
				}
				prevdate = this.widgetdata[i].date;
			}
			this.datelist = datearr;
			this.datelistactual = datelistarr;
		}
	
	this.getRec = function(rec) {
			$$("."+this.callname)[0].innerHTML = '';
			this.rec_date = this.datelistactual[rec];
			$$("."+this.callname)[0].appendChild(this.buildData(this.rec_date));
			if (this.minicalshow) {
				this.widgetCalendar.dateObj.setMonth(this.rec_date.getMonth());
				this.widgetCalendar.changeMonth();
				this.displayEvents();
			}

			if (this.displaytabs && this.displaybody) 
				tabs2('inner #tabContainer',this.rec_date);
		}
	
	this.getRecByDate = function(date) {
			$(params.eventsAreaId).innerHTML = '';
			this.rec_date = date;
			$(params.eventsAreaId).appendChild(this.buildData(this.rec_date));
			if (this.minicalshow) {
				this.displayEvents();
			}
			if (this.displaytabs && this.displaybody) 
				tabs2('inner #tabContainer',this.rec_date);
		}
	
	this.writeTop = function(widgetdata) {
			var self =this;
			var filterDiv = document.createElement("div");
			filterDiv.id = "inner";
			filterDiv.className = this.callname;
			if (this.navigation == 'top') {
				filterDiv.appendChild(this.writeNav(widgetdata));
			}
				var filterdata = document.createElement("div");
				filterdata.id = "inner-header";
					var filteradd = document.createElement("div")
					filteradd.className = "date"
					if (this.displaydate)
						filteradd.innerHTML = this.formatHeadingDate(widgetdata.date);
					filterdata.appendChild(filteradd);
					if (this.minicalshow) {
						var filteradd = document.createElement("span");
						filteradd.id = "show-mini-cal";
							var filterhref = document.createElement("a");
							filterhref.href = "javascript:void(0)";
							filterhref.onclick = function(){
								self.show_hide_minical(this);
							}
							filterhref.innerHTML = (this.minicaldiv.style.display == 'block') ? '[hide mini cal]' : '[show mini cal]';
						filteradd.appendChild(filterhref);
						//filterDiv.appendChild(filteradd);
					}
				filterdata.appendChild(filteradd);
			filterDiv.appendChild(filterdata);
				var filterdata = document.createElement("div");
				filterdata.className = "clear";
			filterDiv.appendChild(filterdata);
			this.filterDiv = filterDiv;
		}
	
	this.writeBottom = function(widgetdata) {
			if (this.navigation == 'bottom') {
				this.filterDiv.appendChild(this.writeNav(widgetdata));
			}
		}
	
	this.writeImage = function(widgetdata) {
			if (widgetdata.thumbnail != undefined) {
				var filterdata = document.createElement("div");
				filterdata.className = "feature_image";
				filterdata.innerHTML = "<img src='"+widgetdata.thumbnail+"' border=0 />";
				this.filterDiv.appendChild(filterdata);
			}
		}
	
	this.writeAdditional = function(widgetdata) {
			if (this.showadditional) {
				var filterdata = document.createElement("div");
				filterdata.id = "additional";
				if (widgetdata.additional_text != undefined) {
					var filteradd = document.createElement("div");
					filteradd.className = "additional_text";
					filteradd.innerHTML = widgetdata.additional_text;
					filterdata.appendChild(filteradd);
				}
				if (widgetdata.additional_link1 != undefined) {
					var filteradd = document.createElement("div");
					filteradd.className = "additional_link1";
					filteradd.innerHTML = "<hr>"+widgetdata.additional_link1;
					filterdata.appendChild(filteradd);
				}
				if (widgetdata.additional_link2 != undefined) {
					var filteradd = document.createElement("div");
					filteradd.className = "additional_link2";
					filteradd.innerHTML = "<hr>"+widgetdata.additional_link2;
					filterdata.appendChild(filteradd);
				}
				this.filterDiv.appendChild(filterdata);
			}
		}
	
	this.writeRec = function(widgetdata, rec) {
		if (window.console) {
			console.log("this.writeRec");
		}
			var filterContent = document.createElement("div");
			filterContent.id = "contentdata";
			filterContent.setAttribute("class", "clear");
		    var self = this;
			if (!this.displaybody) {
				var self = this;
				if (this.titlelinkable) {
					var filterdata = document.createElement("a");
					filterdata.href = widgetdata.linkurl;
					filterdata.href = "javascript:void(0)";
					filterdata.rec = rec;
					filterdata.title = widgetdata.title;
					filterdata.daterec = widgetdata.date;
					filterdata.summary = widgetdata.description;
					filterdata.bodyurl = widgetdata.linkurl;
					filterdata.onclick = function(){
						var selfinner = this;
						self.createOverlay(self.showBody(this), selfinner.title, selfinner.daterec, selfinner.summary, selfinner.bodyurl);
						//if (this.displaytabs) 
						tabs2("lbContent",selfinner.daterec);
					}
				} else {
					var filterdata = document.createElement("div");
				}
				filterdata.className = "title";
				filterdata.innerHTML = widgetdata.title.replace(/\\\"/gi,'"');
			} else {
				if (this.titlelinkable) {
					var filterdata = document.createElement("a");
					if (widgetdata.read_more_url != undefined)
						filterdata.href = widgetdata.read_more_url;
					else
						filterdata.href = widgetdata.linkurl;
				} else {
					var filterdata = document.createElement("div");
				}
				filterdata.innerHTML = widgetdata.title.replace(/\\\"/gi,'"');
					
				filterdata.className = "title";
			}
			filterContent.appendChild(filterdata);
				var filterdata = document.createElement("hr");
			filterContent.appendChild(filterdata);
				var filterdata = document.createElement("div");
				filterdata.className = "summary";
				filterdata.innerHTML = (widgetdata.description != undefined) ? widgetdata.description : '';
			filterContent.appendChild(filterdata);
				var filterdata = document.createElement("div");
				filterdata.className = "more";
				if (!this.displaybody && this.showreadmore) {
					if (widgetdata.read_more_url != undefined)
						filterdata.innerHTML += "<a href='"+widgetdata.read_more_url+"'>"+((widgetdata.read_more_label != undefined) ? widgetdata.read_more_label : "Read More")+"</a>";
					else
						if (widgetdata.read_more_label != undefined)
							filterdata.innerHTML += "<a href='"+widgetdata.linkurl+"'>"+widgetdata.read_more_label+"</a>";
						else
							filterdata.innerHTML = "<a href='"+widgetdata.linkurl+"'>Read More</a>";
				}
			filterContent.appendChild(filterdata);
			if (this.displaybody) {
				var filterdata = document.createElement("div");
				filterdata.className = "body"
					var obj = new AjaxRequest();
					obj.dataonly = true;
					obj.rss = widgetdata.linkurl;
					obj.count = 50;
					obj.init();
				filterdata.innerHTML = xhrs[50];
				filterContent.appendChild(filterdata);
			} else { //look for read more links
				var filterdata = document.createElement("span");
				
			}
				var filterdata = document.createElement("hr");
			filterContent.appendChild(filterdata)
			this.filterDiv.appendChild(filterContent);
		}
	
	this.writeNav = function(widgetdata){
				var rec = parseInt(this.curr_rec);
				var self = this;
				var filterDiv2 = document.createElement("div");
				filterDiv2.id = "inner_nav";
				if (rec==0) {
					var filterdata = document.createTextNode(this.prevlink);
					filterDiv2.appendChild(filterdata);
				} else {
					var filterdata = document.createElement("a");
					filterdata.innerHTML = this.prevlink;
					filterdata.className = "leftarrow";
					filterdata.date = widgetdata.date;
					filterdata.rec = rec;
					filterdata.href = "javascript:void(0)";
					filterdata.onclick = function() {
						self.getRec(parseInt(this.rec)-1);
					}
					filterDiv2.appendChild(filterdata);
				}
				var filterdata = document.createTextNode(" | ");
				filterDiv2.appendChild(filterdata);

				if (rec == (this.datelist.length-1)) {
					var filterdata = document.createElement("span");
					filterdata.id= "rightarrow-text";
					filterdata.innerHTML = this.nextlink;
					filterDiv2.appendChild(filterdata);
				} else {
					var filterdata = document.createElement("a");
					filterdata.innerHTML = this.nextlink;
					filterdata.href = "javascript:void(0)";
					filterdata.date = widgetdata.date;
					filterdata.rec = rec;
					filterdata.className = "rightarrow";
					filterdata.onclick = function() {
						self.getRec(parseInt(this.rec)+1);
					}
					filterDiv2.appendChild(filterdata);
				}
				return filterDiv2;
		}

	this.showBody = function(e){
			var obj = new AjaxRequest();
			obj.dataonly = true;
			obj.rss = e.bodyurl;
			obj.count = 50;
			obj.init();

		return xhrs[50];
	}
	
	this.show_hide_minical = function(o) {
		this.minicaldiv.style.display = (this.minicaldiv.style.display != 'block') ? 'block' : 'none';
		o.innerHTML = (this.minicaldiv.style.display == 'block') ? '[hide mini cal]' : '[show mini cal]';
	}
	
	this.hideBody = function(){
		$(this.topnode).removeChild(this.widgetdiv);
		document.getElementsByClassName('contentTable')[0].style.display= "block";
	}
	
	this.createOverlay = function(data, title, date, summary, linkurl) {
		if (window.console){
			console.log("this.createOverlay");
		}
			bod 			= document.getElementsByTagName('body')[0];
			overlay 		= document.createElement('div');
			overlay.id		= 'overlay';
			lb				= document.createElement('div');
			lb.id			= 'lightbox';
			//lb.className 	= 'loading';
			var tempdata = '';
			tempdata += '<b><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>'; //removed class "rtop" from leading <b> tag to get rid of rounded corners
			tempdata += "<div id='inner'>";
			var tempinner = "<table width='100%'><tr><td><div class='title'>"+title+"</div><div class='date'>"+this.formatHeadingDate(date)+"</div></td><td align='right' nowrap><a href='javascript:void(0)' id='lbClose'>[X]&nbsp;Close</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br><a href='javascript:void(0)' id='lbPrint'><strong>Print Me</strong></a></td></tr>";
			//tempinner += "<tr><td><div class='date'>"+this.formatHeadingDate(date)+"</div></td></tr>";
			tempinner += "<tr><td><div class='summary'>"+summary+"</div></td></tr></table>";
			tempinner += "<div id='lbContent'>" + data + "</div>";
			tempdata += tempinner + "</div>";
			tempdata += '<b><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>'; //removed class "rbottom" from leading <b> tag to get rid of rounded corners
			//clear out any style sheets
			var remstyle = new RegExp("<(link|LINK).+>","g");
			tempdata = tempdata.replace(remstyle,"<!-- style removed -->");
			lb.innerHTML = tempdata;
			bod.appendChild(overlay);
			bod.appendChild(lb);
			//$('lbContent').style.height = (Position.GetWindowSize().height - 145)+'px';
			$('lbContent').style.maxHeight = (Position.GetWindowSize().height - this.lightboxtop)+'px';
			$('lbClose').onclick = function(){
				overlay.parentNode.removeChild(overlay);
				lb.parentNode.removeChild(lb);
			}
			$('lbPrint').data = escape(tempinner);
			$('lbPrint').sitepath = this.sitepath;
			$('lbPrint').onclick = function(){
				var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
				disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
				var docprint=window.open("","",disp_setting); 
				docprint.document.open(); 
				var html = '<html><head><title>Print Content</title>';
				//html +=    '<link href="'+this.sitepath+'print_template.css" rel="stylesheet" type="text/css" />';
				html +=    '</head><body onLoad="self.print()" id="inner">';
				html += 	unescape(this.data);
				html += '</body></html>'; 
				docprint.document.write(html);
				docprint.document.close(); 
				docprint.focus(); 
			}
			$('lightbox').className = "done";				
			$('overlay').style.display = "block";
			$('lightbox').style.display = "block";
		}

	this.lbClose = function(){
			$('overlay').style.display = "none";
			$('lightbox').style.display = "none";
	}
	
	this.formatHeadingDate = function(date) {
			var months = {0:"January", 1:"February", 2:"March", 3:"April", 4:"May", 5:"June", 6:"July", 7:"August", 8:"September", 9:"October", 10:"November", 11:"December" }
			var string = months[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear();
			return string;
			
		}
	
	/* loop through each day of cal - if an event is found for that day then add hyperlink */
	this.displayEvents = function() {
			var self = this;
			for(var i=0;i<6;i++) {
				for(var j=0; j<7; j++) {
					var day = this.widgetCalendar.dateNodes[i][j];
					if (day.innerHTML != '') {
						if(this.datelist.indexOf(dateKey(day.date)) > -1) {
							day.className = "umc-calendar-day umc-calendar-day-selected";
							if (dateKey(this.rec_date) == dateKey(day.date))
								day.className += " umc-calendar-current-day";
							day.onclick = function () {
									//alert("test");
									if(window.console){
										console.log("clicked: " + this.date);
									}
									self.getRecByDate(this.date);
								}
						} else {
							day.className = "umc-calendar-day";
						}
					} else {
						day.className = day.className.replace('umc-calendar-current-day','');
					}
				}
			}
		}
		
	
	
	this.init = function (params) {
				/* initializing params  */
				this.createParams(params);
				/*display loading image */
				this.createLoading();
				/* get calendar data */
				this.loadFeedData();
				
		}
	
	this.init(params);

}
google.load("feeds", "1");
