var metersPerMile = 1609.344;
var milesPerDegree = 69.172;

(function($) {

  $.fn.zventsMonthlyWidget = function(url,settings) {
	settings = $.extend({
		type: 'reg'
	},settings);

	var zObject = this;
	zObject.zDiv = $(this);
	zObject.zUrl = url.substring(0,(url.lastIndexOf('/')==url.length-1)?url.lastIndexOf('/'):url.length);
	zObject.settings = settings;
	zObject.today = new Date();
	zObject.currentDate = zObject.today;
	zObject.currentDate.setDate(1);
	zObject.fullHeight = 0;
	zObject.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

	if(settings.type=='sm') zObject.zDiv.addClass('zventsMonthlySm');
	zObject.zDiv.append('<div class="zMiddle"><div class="zCal"><div class="zMonthStripe"><div class="zPrevMonth"><!-- --></div><div class="zMonthArea"></div><div class="zNextMonth"><!-- --></div></div><div class="zCalDays"><div>SUN</div><div>MON</div><div>TUE</div><div>WED</div><div>THU</div><div>FRI</div><div>SAT</div></div></div></div>');
	zObject.zDiv.find('.zPrevMonth, .zNextMonth').css('opacity',0.8).hover(function(){$(this).css('opacity',1);},function(){$(this).css('opacity',0.8);});
	zObject.zDiv.find('.zPrevMonth').bind('click',{testObj:zObject},function(e){
		generateMonth(e.data.testObj,moveMonth(e.data.testObj.currentDate,-1));
	});
	zObject.zDiv.find('.zNextMonth').bind('click',{testObj:zObject},function(e){
		generateMonth(e.data.testObj,moveMonth(e.data.testObj.currentDate,1));
	});
	
	generateMonth(zObject, zObject.currentDate);
	zObject.zDiv.find('.zLoading').hide();
	
	return zObject;
  };
  
  
  $.fn.zventsTop5Widget = function(url,settings) {
	settings = $.extend({
		partnerID: '',
		type: 'reg',
		cat: ''
	},settings);

	var zObject = this;
	zObject.zDiv = $(this);
	zObject.zUrl = url.substring(0,(url.lastIndexOf('/')==url.length-1)?url.lastIndexOf('/'):url.length);
	zObject.settings = settings;	  
	
	if(settings.type=='sm') zObject.zDiv.addClass('zventsTop5Sm');
	if (zObject.settings.type!='panel') zObject.zDiv.prepend('<div class="zHeader"><a href="' + zObject.zUrl + '"></a></div>');
	zObject.zDiv.append('<div class="zLinkRight"><a href="' + zObject.zUrl + '/events/new"><span class="zPlus"></span>Add a Listing</a></div><div class="zLinkLeft"><a href="' + zObject.zUrl + '">All Events</a></div>');

	(function(Z) {
		Z.partner = zObject.settings.partnerID;
		Z.site =  zObject.zUrl;
		Z.widget.eventList({
			container: zObject.zDiv.find('.zEventArea'),
			load: 
				(zObject.settings.cat=='')?({
					p: Z.partner,
					search: true,
					st: 'event',
					limit: 5,
					srss: 5,
					fields: 'id,images,name,zurl,startTime'+((zObject.settings.type!='panel')?'':',summary,description')
				}):({
					search: true,
					st: 'event',
					sort: 1,
					limit: 5,
					srss: 5,
					cat: zObject.settings.cat,
					fields: 'id,images,name,zurl,startTime'+((zObject.settings.type!='panel')?'':',summary,description')
				})
			, 
			maxTitle: (zObject.settings.type=='sm')?20:28,
			showDate: true,
			images: true,
			image:function(event){
				return !event.images[0] ? '' : [
					'<a class="ZventsImageLink" href="', zObject.zUrl + event.zurl, '" target="_blank">',
						'<img class="ZventsImage" alt="Image" border="0" align="left" ',
							'src="', Z.imgThumb(event.images[0].url), '" ',
						'/>',
					'</a>'
				].join('');				
			},
			date:function(event){
				if(this.showDate==false) return '';
				return Z.Date(event.date).format( ((zObject.settings.type=='sm')?'{Jan}':'{January}') + ' {D}, {Y} <div class="zCalIcon"><span class="shortDt">{Sun}</span><span class="shortD">{D}</span></div>' );
			},
			time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}, ');},
			events:function(events){return events.map(this.event,this).join('');},
			event:function(event){
				if ( zObject.settings.type=='panel' && $('#event_story').html() == '' ) {
					featuredStr = !event.images[0]?'':([
						'<div class="event_pic">',
							'<img class="ZventsImage" alt="Image" border="0" ',
								'src="', event.images[0].url.replace( /_thumb\./, '.' ).replace( /\.([^.]+)$/, '_primary.$1' ), '" ',
							'/>',
						'</div>'
					].join(''));
					featuredStr = [
						featuredStr,
						'<div class="event_info"', (event.images[0]?'':' style="width:300px;"'), '>',
							'<h1>',
								'<a href="' , zObject.zUrl + event.zurl, '" target="_blank">', Z.String.truncate(event.name,(event.images[0]?39:60)), '</a>',
							'</h1>',
							'<em>',
								this.time( event ),
								this.date( event ),
							'</em>',
							Z.String.truncate( ((event.summary)?(event.summary+' '):'') + event.description, (event.images[0]?90:190)),
							'<a href="' , zObject.zUrl + event.zurl, '" class="event_more" target="_blank">&raquo; More Details</a>',
						'</div>'
					].join('');
					$('#event_story').html(featuredStr);
				}
				var date = (!this.date(event)) ? '' : [
					'<span class="ZventsEventDate">',
						this.date( event ),
					'</span>'
				].join('');
				return [
					'<div class="ZventsEvent">',
						this.images?this.image(event) : '',
						'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '" target="_blank">',
							Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6) || 36),
						'</a><br />',
						'<span class="ZventsEventTime">',
							this.time( event ),
						'</span>',
						date,
					'</div>',
					'<div class="zEventStripe" style="margin: 0 8px;"><!-- --></div>'
				].join('');
			}
		});
		zObject.zDiv.change();
	})( ZventsMini );

	

	return zObject;
  };


  $.fn.zventsWidget = function(url,settings) {
	settings = $.extend({
		partnerID: '',
		resLimit: 5,
		typeOf: 'event',
		dateForm: '{M}/{D}/{Y}',
		maxTitle: 0,
		editorsPick: false,
		kidFriendly: false,
		cats: '',
		tags: '',
		searchTerm: '',
		homepageSel : false,
		swhere: '',
		venueMap: false,
		venueMapLong: -77.4605636597,
		venueMapLat: 37.5536117554,
		venueMapZoom: 11,
		venueMapRadius: 4,
		topPanel: false
	},settings);

	var zObject = this;
	zObject.zDiv = $(this);
	zObject.zUrl = url.substring(0,(url.lastIndexOf('/')==url.length-1)?url.lastIndexOf('/'):url.length);
	zObject.settings = settings;
	zObject.settings.editorsPick = (zObject.settings.editorsPick)?zObject.settings.partnerID:'';
	zObject.settings.kidFriendly = (zObject.settings.kidFriendly)?1:0;
	
	if (zObject.settings.typeOf == 'event') {
		if (zObject.settings.editorsPick != '') {
			//IF EDITORS PICK WITH OR WITHOUT CATEGORY
			(function(Z) {
				var CountMyResults=0;
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				Z.widget.eventList({
					container: zObject.zDiv,
					load: {
						search: true,
						what: zObject.settings.searchTerm,
						st: zObject.settings.typeOf,
						sort: 1,
						limit: zObject.settings.resLimit,
						srss: zObject.settings.resLimit,
						cat: zObject.settings.cats,
						has_editors_pick: zObject.settings.editorsPick,
						swhere: zObject.settings.swhere,
						fields: 'id,images,name,zurl,startTime,vid'+((!zObject.settings.topPanel)?'':',summary,description')
					},
					maxTitle: zObject.settings.maxTitle,
					showDate: true,
					images: true,
					date:function(event){
						if(this.showDate==false) return '';
						return Z.Date(event.date).format(zObject.settings.dateForm);
					},
					time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}');},
					event:function(event){
						CountMyResults++;
						
						if ( zObject.settings.topPanel && $('.event_story').html() == '' ) {
							featuredStr = !event.images[0]?'':([
								'<div class="event_pic">',
									'<img class="ZventsImage" alt="Image" border="0" ',
										'src="', event.images[0].url.replace( /_thumb\./, '.' ).replace( /\.([^.]+)$/, '_primary.$1' ), '" ',
									'/>',
								'</div>'
							].join(''));
							featuredStr = [
								featuredStr,
								'<div class="event_info"', (event.images[0]?'':' style="width:300px;"'), '>',
									'<h1>',
										'<a href="' , zObject.zUrl + event.zurl, '" target="_blank">', Z.String.truncate(event.name,(event.images[0]?39:60)), '</a>',
									'</h1>',
									'<em>',
										this.time( event ),', ',
										this.date( event ),
									'</em>',
									Z.String.truncate( ((event.summary)?(event.summary+' '):'') + event.description, (event.images[0]?90:190)),
									'<a href="' , zObject.zUrl + event.zurl, '" class="event_more" target="_blank">&raquo; More Details</a>',
								'</div>'
							].join('');
							$('.event_story').html(featuredStr);
						}
						
						return [
							'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
								this.images?this.image(event) : '',
								'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
									Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6)),
								'</a>',
								'<span class="ZventsWhen"><span class="ZventsWhenTitle">When:</span>',
									this.date( event ), ' ',
									this.time( event ),
								'</span>',
								'<span class="ZventsWhere"><span class="ZventsWhereTitle">Where:</span>',
									'<a href="', zObject.zUrl + event.venue.zurl, '">', event.venue.name, '</a>',
								'</span>',
							'</div>'
						].join('');
					}
				});
				zObject.zDiv.change();
			})( ZventsMini );
		} else if (zObject.settings.kidFriendly != 0) {
			//IF KID FRIENDLY IS CHOOSEN
			(function(Z) {
				var CountMyResults=0;
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				Z.widget.eventList({
					container: zObject.zDiv,
					load: {
						search: true,
						what: zObject.settings.searchTerm,
						has_kids: zObject.settings.kidFriendly,
						st: zObject.settings.typeOf,
						limit: zObject.settings.resLimit,
						srss: zObject.settings.resLimit,
						cat: zObject.settings.cats,
						has_editors_pick: zObject.settings.editorsPick,
						swhere: zObject.settings.swhere,
						fields: 'id,images,name,zurl,startTime,vid'+((!zObject.settings.topPanel)?'':',summary,description')
					},
					maxTitle: zObject.settings.maxTitle,
					showDate: true,
					images: true,
					date:function(event){
						if(this.showDate==false) return '';
						return Z.Date(event.date).format(zObject.settings.dateForm);
					},
					time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}');},
					event:function(event){
						CountMyResults++;

						if ( zObject.settings.topPanel && $('.event_story').html() == '' ) {
							featuredStr = !event.images[0]?'':([
								'<div class="event_pic">',
									'<img class="ZventsImage" alt="Image" border="0" ',
										'src="', event.images[0].url.replace( /_thumb\./, '.' ).replace( /\.([^.]+)$/, '_primary.$1' ), '" ',
									'/>',
								'</div>'
							].join(''));
							featuredStr = [
								featuredStr,
								'<div class="event_info"', (event.images[0]?'':' style="width:300px;"'), '>',
									'<h1>',
										'<a href="' , zObject.zUrl + event.zurl, '" target="_blank">', Z.String.truncate(event.name,(event.images[0]?39:60)), '</a>',
									'</h1>',
									'<em>',
										this.time( event ),', ',
										this.date( event ),
									'</em>',
									Z.String.truncate( ((event.summary)?(event.summary+' '):'') + event.description, (event.images[0]?90:190)),
									'<a href="' , zObject.zUrl + event.zurl, '" class="event_more" target="_blank">&raquo; More Details</a>',
								'</div>'
							].join('');
							$('.event_story').html(featuredStr);
						}

						return [
							'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
								this.images?this.image(event) : '',
								'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
									Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6)),
								'</a>',
								'<span class="ZventsWhen"><span class="ZventsWhenTitle">When:</span>',
									this.date( event ), ' ',
									this.time( event ),
								'</span>',
								'<span class="ZventsWhere"><span class="ZventsWhereTitle">Where:</span>',
									'<a href="', zObject.zUrl + event.venue.zurl, '">', event.venue.name, '</a>',
								'</span>',
							'</div>'
						].join('');
					}
				});
				zObject.zDiv.change();
			})( ZventsMini );
		} else if (zObject.settings.homepageSel) {
			//IF HOMEPAGE SELECTIONS ARE DESIRED
			(function(Z) {
				var CountMyResults=0;
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				Z.widget.eventList({
					container: zObject.zDiv,
					load: {
						search: true,
						p: zObject.settings.partnerID,
						st: zObject.settings.typeOf,
						limit: zObject.settings.resLimit,
						srss: zObject.settings.resLimit,
						swhere: zObject.settings.swhere,
						fields: 'id,images,name,zurl,startTime,vid'+((!zObject.settings.topPanel)?'':',summary,description')
					},
					maxTitle: zObject.settings.maxTitle,
					showDate: true,
					images: true,
					date:function(event){
						if(this.showDate==false) return '';
						return Z.Date(event.date).format(zObject.settings.dateForm);
					},
					time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}');},
					event:function(event){
						CountMyResults++;

						if ( zObject.settings.topPanel && $('.event_story').html() == '' ) {
							featuredStr = !event.images[0]?'':([
								'<div class="event_pic">',
									'<img class="ZventsImage" alt="Image" border="0" ',
										'src="', event.images[0].url.replace( /_thumb\./, '.' ).replace( /\.([^.]+)$/, '_primary.$1' ), '" ',
									'/>',
								'</div>'
							].join(''));
							featuredStr = [
								featuredStr,
								'<div class="event_info"', (event.images[0]?'':' style="width:300px;"'), '>',
									'<h1>',
										'<a href="' , zObject.zUrl + event.zurl, '" target="_blank">', Z.String.truncate(event.name,(event.images[0]?39:60)), '</a>',
									'</h1>',
									'<em>',
										this.time( event ),', ',
										this.date( event ),
									'</em>',
									Z.String.truncate( ((event.summary)?(event.summary+' '):'') + event.description, (event.images[0]?90:190)),
									'<a href="' , zObject.zUrl + event.zurl, '" class="event_more" target="_blank">&raquo; More Details</a>',
								'</div>'
							].join('');
							$('.event_story').html(featuredStr);
						}
						
						return [
							'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
								this.images?this.image(event) : '',
								'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
									Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6)),
								'</a>',
								'<span class="ZventsWhen"><span class="ZventsWhenTitle">When:</span>',
									this.date( event ), ' ',
									this.time( event ),
								'</span>',
								'<span class="ZventsWhere"><span class="ZventsWhereTitle">Where:</span>',
									'<a href="', zObject.zUrl + event.venue.zurl, '">', event.venue.name,
								'</a></span>',
							'</div>'
						].join('');
					}
				});
				zObject.zDiv.change();
			})( ZventsMini );			
		} else {
			//IF NOT AN EDITORS PICK SELECTOR
			(function(Z) {
				var CountMyResults=0;
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				Z.widget.eventList({
					container: zObject.zDiv,
					load: {
						search: true,
						what: zObject.settings.searchTerm,
						st: zObject.settings.typeOf,
						sort: 1,
						limit: zObject.settings.resLimit,
						srss: zObject.settings.resLimit,
						cat: zObject.settings.cats,
						tag: zObject.settings.tags,
						swhere: zObject.settings.swhere,
						fields: 'id,images,name,zurl,startTime,vid'+((!zObject.settings.topPanel)?'':',summary,description')
					},
					maxTitle: zObject.settings.maxTitle,
					showDate: true,
					images: true,
					date:function(event){
						if(this.showDate==false) return '';
						return Z.Date(event.date).format(zObject.settings.dateForm);
					},
					time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}');},
					event:function(event){
						CountMyResults++;
						
						if ( zObject.settings.topPanel && $('.event_story').html() == '' ) {
							featuredStr = !event.images[0]?'':([
								'<div class="event_pic">',
									'<img class="ZventsImage" alt="Image" border="0" ',
										'src="', event.images[0].url.replace( /_thumb\./, '.' ).replace( /\.([^.]+)$/, '_primary.$1' ), '" ',
									'/>',
								'</div>'
							].join(''));
							featuredStr = [
								featuredStr,
								'<div class="event_info"', (event.images[0]?'':' style="width:300px;"'), '>',
									'<h1>',
										'<a href="' , zObject.zUrl + event.zurl, '" target="_blank">', Z.String.truncate(event.name,(event.images[0]?39:60)), '</a>',
									'</h1>',
									'<em>',
										this.time( event ),', ',
										this.date( event ),
									'</em>',
									Z.String.truncate( ((event.summary)?(event.summary+' '):'') + event.description, (event.images[0]?90:190)),
									'<a href="' , zObject.zUrl + event.zurl, '" class="event_more" target="_blank">&raquo; More Details</a>',
								'</div>'
							].join('');
							$('.event_story').html(featuredStr);
						}
						
						return [
							'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
								this.images?this.image(event) : '',
								'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
									Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6)),
								'</a>',
								'<span class="ZventsWhen"><span class="ZventsWhenTitle">When:</span>',
									this.date( event ), ' ',
									this.time( event ),
								'</span>',
								'<span class="ZventsWhere"><span class="ZventsWhereTitle">Where:</span>',
									'<a href="', zObject.zUrl + event.venue.zurl, '">', event.venue.name,
								'</a></span>',
							'</div>'
						].join('');
					}
				});
				zObject.zDiv.change();
			})( ZventsMini );
		}	
	} else if (zObject.settings.typeOf == 'movie') {
		// HEY COOL THIS IS THE 'RANDOM' MOVIES PART
		rand2 = Math.floor(Math.random()*(15-zObject.settings.resLimit)+1);
		(function(Z) {
			var CountMyResults=0;
			Z.partner = zObject.settings.partnerID;
			Z.site =  zObject.zUrl;
			Z.widget.eventList({
				container: zObject.zDiv,
				load: {
					search: true,
					what: zObject.settings.searchTerm,
					st: zObject.settings.typeOf,
					offset: rand2,
					when: 'today',
					limit: zObject.settings.resLimit,
					srss: zObject.settings.resLimit,
					cat: zObject.settings.cats,
					tag: zObject.settings.tags,
					swhere: zObject.settings.swhere,
					fields: 'id,images,name,zurl,vid,description'

				},
				maxTitle: zObject.settings.maxTitle,
				showDate: true,
				images: true,
				date:function(event){
					if(this.showDate==false) return '';
					return Z.Date(event.date).format(zObject.settings.dateForm);
				},
				time:function(event){return Z.Date(event.startTime).format('{h}:{mm} {am}');},
				event:function(event){
					CountMyResults++;
					return [
						'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
							this.images?this.image(event) : '',
							'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
								Z.String.truncate(event.name, this.maxTitle + ((event.images[0])?0:6)),
							'</a>',
							'<span class="ZventsWhat"><span class="ZventsWhenTitle">What:</span>',
								Z.String.truncate(event.description, 2*(this.maxTitle + ((event.images[0])?0:6))),
							'</span>',
						'</div>'
					].join('');
				} 
			});
			zObject.zDiv.change();
		})( ZventsMini );	
	} else if (zObject.settings.typeOf == 'venue') {
		if (!zObject.settings.venueMap) {
			/*			GENERAL VENUE LISTER		*/
			(function(Z) {
				var CountMyResults=0;
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				Z.widget.eventList({
					container: zObject.zDiv,
					load: {
						search: true,
						st: zObject.settings.typeOf,
						limit: zObject.settings.resLimit,
						srss: zObject.settings.resLimit,
						venue_type: zObject.settings.cats,
						tag: zObject.settings.tags,
						swhere: zObject.settings.swhere,
						fields: 'id,name,zurl,address,city,state,phone,images'
					},
					maxTitle: zObject.settings.maxTitle,
					images: true,
					event:function(event){
						CountMyResults++;
						return [
							'<div class="ZventsEvent'+((CountMyResults==zObject.settings.resLimit)?' z-last':'')+'">',
								this.images?this.image(event) : '',
								'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
									Z.String.truncate(event.name, this.maxTitle),
								'</a>',
								'<span class="ZventsWhere"><span class="ZventsWhereTitle">Where:</span>',
									event.address, ', ', event.city, ', ', event.state,
									'<span class="ZventsWherePhone">', event.phone, '</span>',
								'</a></span>',
							'</div>'
						].join('');
					}
				});
				zObject.zDiv.change();
			})( ZventsMini );
			

		} else {
			/*			GENERAL VENUE LISTER WITH MAP OMG		*/
			mashupName = "ZventsMap";
			$('#ZventsMap', zObject.zDiv).googleMap(zObject.settings.venueMapLat,zObject.settings.venueMapLong,zObject.settings.venueMapZoom, {
					controls: ["GSmallMapControl"], 
					setup: [2,15]
			});
			(function( Z ) {
				Z.partner = zObject.settings.partnerID;
				Z.site =  zObject.zUrl;
				ZventsLoadMap = function(nLat,nLng,nRadius) {	
					removePoints();
					var CountMyResults = 0;
					Z.widget.eventList({
						id: 'ZventsEventMap',
						load: {
							where: nLng+':BY:'+nLat,
							st: zObject.settings.typeOf,
							limit: zObject.settings.resLimit,
							srss: zObject.settings.resLimit,
							radius: nRadius,
							venue_type: zObject.settings.cats,
							tag: zObject.settings.tags,
							fields: 'id,name,zurl,latitude,longitude'
						},
						maxTitle: zObject.settings.maxTitle,
						event:function(event){
							CountMyResults++;
							loadPoints(CountMyResults,event.latitude,event.longitude,event.name,zObject.zUrl+event.zurl);
							return [
								'<div class="ZventsEvent">',
									Z.getImg(CountMyResults),'&nbsp;',
									'<a class="ZventsEventName" href="', zObject.zUrl + event.zurl, '">',
										Z.String.truncate(event.name, this.maxTitle),
									'</a>',
								'</div>'
							].join('');
						}
					});
					return false;
				};
				ZventsLoadMap(zObject.settings.venueMapLat,zObject.settings.venueMapLong,zObject.settings.venueMapRadius);
			})( ZventsMini );	
		}
	}
	return zObject;
  };


})(jQuery);

/*		FUNCTIONS FOR MONTHLY WIDGET		*/
function moveMonth(curDate,m) {
	if (m<0) {
		if (curDate.getMonth()+m<0) {
			curDate.setMonth((curDate.getMonth()+12)+m);
			curDate.setFullYear(curDate.getFullYear()-1);
		}
		else curDate.setMonth(curDate.getMonth()+m);
	}
	else if (m>0) {
		if (curDate.getMonth()+m>0) {
			curDate.setMonth((curDate.getMonth()+m)-12);
			curDate.setFullYear(curDate.getFullYear()+1);
		}
		else curDate.setMonth(curDate.getMonth()+m);
	}
	return curDate;
}
function generateMonth(calObj,curDate) {
	calObj.currentDate = curDate;
	calObj.zDiv.find('.zCalWeek').remove();
	calObj.zDiv.find('.zMonthArea').text(calObj.months[curDate.getMonth()] + ' ' + curDate.getFullYear());
	
	beginPos = curDate.getDay();
	calGrid = '<div class="zCalWeek">';
	for (i=0;i<beginPos;i++) calGrid += '<div class="zNone"></div>';
	newPos = beginPos;
	weekCount = 1;
	for (i=1;i<=getDaysMonth(curDate.getMonth(),curDate.getFullYear());i++) {
		if (newPos==0&&i!=1) {
			calGrid+='<div class="zCalWeek">';
			weekCount++;
		}
		calGrid+='<div><span>' + i + '</span><div class="zDayBg"></div></div>';		
		if (newPos==6) {
			calGrid += "</div>";
			newPos = 0; }
		else newPos++;
	}
	if (weekCount==4) calGrid += ((newPos!=0)?'</div>':'') + '<div class="zCalWeek"></div><div class="zCalWeek"><div class="zNone"></div><div class="zNone"></div>';
	if (weekCount==5) calGrid += ((newPos!=0)?'</div>':'') + '<div class="zCalWeek"><div class="zNone"></div><div class="zNone"></div>';
	if (weekCount==6) while (newPos<2) {
		calGrid+='<div class="zNone"></div>';
		newPos++;
	}
	calGrid+='<div class="zLinkArea"><a href="' + calObj.zUrl + '/events/new">Add a Listing</a></div></div>';
	
	calObj.zDiv.find('.zCal').append(calGrid);
	calObj.zDiv.find('.zCalWeek div:not(.zNone, .zLinkArea)').hover(function(){$(this).find('.zDayBg').addClass('zDayBgHover');},function(){$(this).find('.zDayBg').removeClass('zDayBgHover');}).bind('click',{testObj:calObj},function(e){
		location.href = calObj.zUrl + '/search?swhat=&swhen=' + (e.data.testObj.currentDate.getMonth()+1) + '%2F' + $(this).find('span').text() + '%2F' + e.data.testObj.currentDate.getFullYear();
	});
}
function getDaysMonth(m,y) {
	day_totals = [31,28,31,30,31,30,31,31,30,31,30,31];
	if (m != 1) return day_totals[m];
	else if ((y % 4) != 0) return 28;
	else if ((y % 400) == 0) return 29;
	else if ((y % 100) == 0) return 28;
	else return 29;
}



/*       ZVENTS CUSTOM LIBRARY		*/
(function(Z){
	if(typeof zventsPartnerId=="undefined"){
		if(typeof partner_id!="undefined"){zventsPartnerId=partner_id}
		else{zventsPartnerId=null}
	}
	if(typeof zventsBaseUrl=="undefined"){
		if(typeof base_url!="undefined"){zventsBaseUrl=base_url}
		else{zventsBaseUrl='http://www.zvents.com'}
	}
	Z.partner=zventsPartnerId;
	Z.site=zventsBaseUrl;
	Z.listNumber = true;
	var today=Z.Date.today();
	var base={
		date:function(event){
			if(this.showDate===false)return'';
			if(event.date==today)return this.showDate===true?'today':'';
			if(event.date==today+Z.Date.oneDay)return'tomorrow';
			return Z.Date(event.date).format(event.date<today+Z.Date.oneDay*7?'{Sunday}':'{M}/{DD}')
		},
		events:function(events){
			return[
				'<div class="ZventsEventList">',
					events.map(this.event,this).join(''),
				'</div>'
			].join('')
		},
		event:function(event){
			var date=this.date(event);
			if(date){
				date=[
					'<span class="ZventsEventDate">',
						this.date(event),
					'</span>',
					' '
				].join('')
			}			
			return[
				'<div class="ZventsEvent">',
					this.images?this.image(event):'',
					'<span class="ZventsEventTime">',
						this.time(event),
					'</span>',
					' ',
					date,
					'<a class="ZventsEventName" href="',event.zurl,'">',
						Z.String.truncate(event.name,this.maxTitle||40),
					'</a>',
				'</div>'
			].join('')
		},
		image:function(event){
			var image=event.images[0];
			return!image?'':[
				'<a class="ZventsImageLink" href="',event.zurl,'">',
					'<img class="ZventsImage" alt="Image" border="0" ','src="',Z.imgThumb(image.url),'" ','/>',
				'</a>'
			].join('')
		},
		loading:function(){
			return[
				'<div class="ZventsLoading">',
					'<img src="http://images.zvents.com/images/spinner16.gif" />',
					'<span class="ZventsTT"> Loading&#8230;</span>',
				'</div>'
			].join('')
		},
		time:function(event){
			if(this.showTime===false)return'';
			var start=Z.Date(event.startTime),date=start.date;
			var hours=date.getUTCHours(),minutes=date.getUTCMinutes();
			return start.format(minutes?'{h}:{mm} {am}':{0:'Midnight',12:'Noon'}[hours]||'{h} {am}')
		}
	};
	function Widget(args){
		Z.Object.update(this,base,args,args.render)
	}
	var idNext=1;
	Z.widget.eventList=function(args){
		var widget=new Widget(args);
		if (args.container) {
			args.id='ZventsWidget'+idNext++;
			$(args.container).html([
				'<div id="',args.id,'">',
					widget.loading(),
				'</div>'
			].join(''))	
		}else if(!args.id){
			args.id='ZventsWidget'+idNext++;
			document.write([
				'<div id="',args.id,'">',
					widget.loading(),
				'</div>'
			].join(''));
		}
		if(args.load){
			Z.call(Z.EventList,{
				yields:function(events){
					if(widget.sort!==false)events.sort('starttime');
					var div=document.getElementById(args.id);
					div.innerHTML=widget.events(events);
					if(args.id == "ZventsEventMap"){
						for(i=1;i<marker.length;++i){
							addPoints(marker[i]);
						}
					}
				}
			},args)
		}
		return args.id
	};
	Z.widget.venueList=function(args){
		var widget=new Widget(args);
		if (args.container) {
			args.id='ZventsWidget'+idNext++;
			$(args.container).html([
				'<div id="',args.id,'">',
					widget.loading(),
				'</div>'
			].join(''))	
		}else if(!args.id){
			args.id='ZventsWidget'+idNext++;
			document.write([
				'<div id="',args.id,'">',
					widget.loading(),
				'</div>'
			].join(''))
		}
		if(args.load){
			Z.call(Z.VenueList,{
				yields:function(venues){
					var div=document.getElementById(args.id);
					div.innerHTML=widget.venues(venues)
					if(args.id == "ZventsEventMap"){
						for(i=1;i<marker.length;++i){
							addPoints(marker[i]);
						}
					}
				}
			},args)
		}
		return args.id
	};
	tabber={
		click:function(clicked){
			var ul=clicked.parentNode.parentNode;
			var tabs=ul.getElementsByTagName('a');
			for(i=0;i<tabs.length;++i){
				var a=tabs[i],on=(a==clicked);
				a.className=(on?'active':'');
				tabber.show(a.id.replace(/^tab/,'div'),on)
			}
		},
		zclick:function(clicked,when){
			tabber.click(clicked);
			tabber.show('zventsFooter',when);
			if(ZventsTomorrowID&&when=='Tomorrow'){
				Z.widget.popular({id:ZventsTomorrowID,load:{when:when}});
				ZventsTomorrowID=null
			}
		},
		show:function(id,show){
			document.getElementById(id).style.display=show?'block':'none'
		}
	}
})(ZventsMini);


/*       ZVENTS GOOGLE MAP - FROM TBO / MODIFIED FOR MEDIAGENERAL		*/
/* Declaring valid date character, minimum year and maximum year */
var dtCh= "-";
//window.onunload = unloadPage;
function unloadPage(){GUnload();}
$.googleMap = {
	maps: {},
	mapNum: 1
};
$.fn.googleMap = function(lat, lng, zoom, options) {
	// If we aren't supported, we're done
	if (!window.GBrowserIsCompatible || !GBrowserIsCompatible()) return this;
	// Default values make for easy debugging
	if (lat == null) lat = 37.5536117554;
	if (lng == null) lng = -77.4605636597;
	if (!zoom) zoom = 14;
	// Sanitize options
	if (!options || typeof options != 'object')	options = {};
	options.mapOptions = options.mapOptions || {};
	options.setup = options.setup || [];
	options.controls = options.controls || {};
	// Map all our elements
	return this.each(function() {
		// Make sure we have a valid id
		if (!this.id) this.id = "gMap" + $.googleMap.mapNum++;
		// Create a map and a shortcut to it at the same time
		var map = $.googleMap.maps[this.id] = new GMap2(this, options.mapOptions);
		// Center and zoom the map
       	map.setCenter(new GLatLng(lat, lng), zoom);
       	// Add controls to our map
       	for (var i = 0; i < options.controls.length; i++) {
	       	var c = options.controls[i];
	       	eval("map.addControl(new " + c + "());");
       	} 
       	$.googleMap.zoomMax = options.setup[1];
       	$.googleMap.zoomMin = options.setup[0];
		GEvent.addListener(map,"movestart",function() {});
		GEvent.addListener(map,"moveend", function() {
			$.googleMap.Bounds = $.googleMap.maps[mashupName].getBounds();
			$.googleMap.Center = $.googleMap.maps[mashupName].getCenter();
			//Change list
			var pix = Math.min( 240, 250 ) - 40;
			if( pix <= 40 ) pix = 40;
			var factor = pix / 250;
			var ne = $.googleMap.Bounds.getNorthEast();
			var sw = $.googleMap.Bounds.getSouthWest();
			var degrees = Math.abs( ne.lat() - sw.lat() ) * factor;
			var miles = degrees * milesPerDegree;
			ZventsRadius = miles / 2;
			ZventsLat = $.googleMap.Center.lat();
			ZventsLong = $.googleMap.Center.lng();
			ZventsLoadMap(ZventsLat,ZventsLong,ZventsRadius);
			//$.googleMap.SouthWest = $.googleMap.maps[mashupName].getBounds().getSouthWest();
			//$.googleMap.NorthEast = $.googleMap.maps[mashupName].getBounds().getNorthEast();
			$.googleMap.newZoom = $.googleMap.maps[mashupName].getZoom();
			if ($.googleMap.encodedPolyline){
				if ($.googleMap.newZoom > 10){
					 $.googleMap.maps[mashupName].removeOverlay($.googleMap.encodedPolyline);     
				}else{
					 $.googleMap.maps[mashupName].addOverlay($.googleMap.encodedPolyline);     
				}
			}
			if ($.googleMap.newZoom < $.googleMap.zoomMin){
				$.googleMap.maps[mashupName].setZoom($.googleMap.zoomMin);
			}
			if ($.googleMap.newZoom > $.googleMap.zoomMax){
				$.googleMap.maps[mashupName].setZoom($.googleMap.zoomMax);
			}
					
		});		
    });
};
// Create our marker icon	 
function makeIcon (myicon) {
	myicon ='http://cssimages.tbo.com/tboextra/dot_'+ myicon+ '_select.png';
	//myicon ='http://www.zvents.com/images/map/dot_'+ myicon+ '_select.png';
	var baseIcon = new GIcon();
	baseIcon.iconSize=new GSize(16,16);
	baseIcon.iconAnchor=new GPoint(16,16);	
	baseIcon.infoWindowAnchor=new GPoint(16,0);          
	var Newicon = new GIcon(baseIcon, myicon, null, "");
	return Newicon;	
}	
var marker =[];
var myEventListener =[];
var markerURL =[];
function loadPoints(num,nLat,nLng,sName,sURL){
	var _icon = makeIcon (num);
	var point = new GLatLng(nLat,nLng);
	marker[num] = new GMarker(point, {icon:_icon, title:sName});
	markerURL[num] = sURL;

	myEventListener[num] = GEvent.addListener(marker[num], "click", function() {
		window.open(markerURL[num],'mapwindow');
	});
}
function addPoints(myMarker){
	$.googleMap.maps[mashupName].addOverlay(myMarker);
}
function removePoints(){
	for( i = 1;  i < marker.length;  ++i ) {
		$.googleMap.maps[mashupName].removeOverlay(marker[i]); 
		GEvent.removeListener(myEventListener[i]);
	}
	marker =[];
	myEventListener =[];
	markerURL =[];
}