var zvents = {
	options: {
			limit: 1,
			when: '',
			cat: 0,
			images: true,
			kids: false //,
			// editors_pick: true
		},
	eventsFinder : function(Z, config) {
		if(config) {
			for(prop in config){
				zvents.options[prop] = config[prop];
			}
		}
		limit = zvents.options.limit;
		when = zvents.options.when;
		cat = zvents.options.cat;
		kids = zvents.options.kids;
		images = zvents.options.images;
		/* if (zvents.options.editors_pick == true) {
			editors_pick = 1065;
		}
		else {
			editors_pick = 0;
		} */
		if (zvents.options.kids == true) {
			kids = 1;
		}
		else {
			kids = 0;
		}
		var offset = Math.ceil(limit*Math.random()) -1;
		var srss = limit + 1;
		Z.site = 'http://listings.dfw.com';
		Z.partner = 1065;
		Z.widget.eventList({
			load: {
			  p: Z.partner,
			  search: true,
			  sort: '',
			  when: when,
			  cat: cat,
			  offset: offset,
			  st: 'event',
			  has_kids: kids,
			  limit: limit,
			  // overrides default thumb image size, none == full size image
			  image_size: 'none',
			  // has_editors_pick: editors_pick,
			  srss: srss // ,
			  // fields: 'id,name,zurl,starttime, venue.name, venue.city, venue.state, site, images'                            
			},
			images: images,
			// Example custom render function for event list
			events: function( events ) {
				return [
					'<div class="ZventsEventList"><ul>',
						events.map(this.event,this).join(''),
					'</ul></div>'
				].join('');
			},
			image: function( event ) {
				var image = event.images[0];
				return ! image ? '' : [
					'<div class="zvents-image">',
					'<a class="ZventsImageLink" href="', event.zurl, '">',
						'<img class="ZventsImage" alt="Image" border="0" ',
							'src="', image.url, '" ',   //note that I changed out Z.imgThumb(image.url) and it still has the same URL
							'width="130"', // image.width, '" height="', image.height, '" ',
						'/>',
					'</a>',
					'</div>'
				].join('');
			},
			event: function( event ) {
				var date = this.date( event );
				var time = this.time( event );
				// isoDate = dfw.utils.getISODate(date + time);
				// console.log(isoDate);
				if( date ) {
				  date = [
					'<span class="ZventsEventDate"><abbr class="dtstart">',
					  this.date( event ),
					'</abbr></span>',
					' '
				  ].join('');
				}
				return [
					'<li 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>',
					'</li>'
				].join('');
			}
		});			
	},
	calendar : function(nDays) {
		// EDIT HERE: partner calendar base URL, search URL template,
		// number of days to display
		var partner = 'http://listings.dfw.com/';
		var searchUrl = partner + 'search?swhat=&amp;swhen={day}&amp;st=event';
		var nDays = nDays ? nDays : '7';
		
		var dayNames = [
			'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
		];
		var monthNames = [
			'January', 'February', 'March', 'April', 'May', 'June',
			'July', 'August', 'September', 'October', 'November', 'December'
		];
		
		var todayClass = ' ZventsDayButtonToday';
		var today = new Date( (new Date).setHours( 0, 0, 0, 0 ) );
		for( var i = 1;  i <= nDays;  ++i ) {
			var year = today.getFullYear();
			var month = monthNames[ today.getMonth() ];
			var date = today.getDate();
			var day = today.getDay();
			var weekend = ( day == 0  ||  day == 6 );
			var weekendClass = weekend ? ' ZventsDayButtonWeekend' : '';
			var dayName = dayNames[ today.getDay() ];
			var search = searchUrl.replace( /{day}/, i == 1 ? 'Today' : i == 2 ? 'Tomorrow' : dayName );
			
			button( date, dayName.slice(0,3), search,
				dayName + ', ' + month + ' ' + date + ', ' + year );
			
			todayClass = '';
			today.setDate( date + 1 );
		}
		
		// these add the All events link, which we don't want to do write here
		// weekendClass = ' ZventsDayButtonAll';
		// button( 'All', 'Events', partner, 'any day' );
		
		function button( date, day, url, title, clas ) {
			document.write( [
				
				/* '<li class="z_primary"><a href="', url, '" ',
					'class="ZventsDayButton', todayClass, weekendClass, '" ',
					'title="View events for ', title, '" ',
				'>', day,'</a></li>' */
				
				'<span class="ZventsDay">',
					'<a href="', url, '" ',
						'class="ZventsDayButton', todayClass, weekendClass, '" ',
						'title="View events for ', title, '" ',
					'>',
					// '<span class="ZventsDayButtonDate">',
					// 	'&nbsp;', date, '&nbsp;',
					// '</span>',
					'<span class="ZventsDayButtonDay">',
						day,
					'</span>',
					'</a>',
				'</span>'
			].join('') );
		}		
	},
	restaurantFinder : function( Z ) {
		Z.site = 'http://listings.dfw.com';
		Z.partner = 1065;
		var limit = 2;
		var offset = Math.ceil(limit*Math.random()) -1;
		Z.widget.venueList({
			load: {
				p: Z.partner,
				st: 'restaurant',
				search: true,
				limit: 1,
				srss: 2,
				tag: 'bestofdfw',
				image_size: 'none',
				offset: offset,
				//choose cuisines.  See the Cuisine ID in the URL on your co-brand site
				// cuisine: '133', 
				//Options include: ['id', 'name', 'address', 'parent_id', 'phone', 'city', 'country', 'zip', 'latitude', 'longitude', 'state', 'timezone', 'url', 'zurl', 'private', 'description', 'images', 'types', 'showtimes', 'movies', 'cuisines']
				fields: 'id,address,name,zurl,phone,city,state,images'
			},
			// images: true,
			// Example custom render function for venue list
			venues: function( venues ) {
				return [
					'<div class="ZventsEventList">',
						venues.map(this.venue,this).join(''),
					'</div>'
				].join('');
			},
			// Render the image(s) for an event
			image: function( venue ) {
				var image = venue.images[0];
				return ! image ? '' : [
					'<div class="zvents-image">',
					'<a class="ZventsImageLink" href="', Z.site, venue.zurl, '">',
						'<img class="ZventsImage" alt="Image" border="0" ',
						'src="', image.url, '" ',
						'width="130"', // image.width, '" height="', image.height, '" ',
						'/>',
					'</a>',
					'</div>'
				].join('');
			},
			//Override Date Rendering
			//    Changed the date order and style           
			venue: function( venue ) {
				//Best Place to set the output order.  Rearrange these as needed
				//'date' is the Date
				//this.time(event) is the time
				//venue.zurl is the venue URL
				//venue.name is the name of the event            
				//  Other options include event.phone, event.description, etc. 
				//  ***Remember to set the "fields:" parameter if you add sources  
				return [
				  '<div class="zvents-listing">',
					this.image ? this.image( venue ) : '',
					'<h2><a class="ZventsEventName" href="',  Z.site, venue.zurl, '">',
					  Z.String.truncate( venue.name, this.maxTitle || 40 ),
					'</a></h2>',
					'<p>',
					venue.address,
					'</p><p> ',
					venue.city,
					'</p><p>',
					venue.phone,    
					'</p>',
				  '</div>'
				].join('');
			  }
		});
	}
}
