var comSvcBaseUrl = "/Community/services";
var comMediaBaseUrl = "/Community/media";
var comSiteName = "Dark Custom";
var comPageUrl = "events.html";

var login = null;

var DarkCustom = (function() {
	// Base configuration.
	var itemsX = 4;
	var itemsY = 3;
	var startIndex = 1;
	var classes = HD.CSS_CLASSES;
	var dateFormat = "d mmm yyyy 'at' hh:MM tt";
	var services = HD.ShareWidget.SERVICES;
	
	return {
		// #darkCustom (the parent container).
		containerEl: null,
		// Categories config.
		categories: [],
		// Analytics settings.
		analytics: {
			section: 'Events'
		},
	
		// Initialize the page.
		init: function() {
			var self = this;
		
			// Preselect common elements.
			this.containerEl = HD.get('darkCustom');
			
			// Update config.
			
			// Initialize the session.
			HD.util.DWR.initSession();
			HD.util.DWR.setErrorHandler();
			login = new HD.Login({siteName : comSiteName});
			login.model.init(function() {
				login.model.getUser();
			});
			
			HD.TwitterFeedWidget.templates.twitterLabel = '<h5><img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/hdr_latest_twitter.gif" /></h5>';
			HD.TwitterFeedWidget.templates.twitterFollowText = '<img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/icon_twitter.gif">&nbsp;<a href="${twitterFollowURL}" target="_blank">Follow Dark Custom on Twitter</a>&nbsp;<img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/icon_popup.gif">';
			HD.FacebookEventsWidget.templates.rsvpText = '<img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/btn_rsvp_facebook_popup_sm.gif" />';
			HD.FacebookEventsWidget.templates.facebookLinkText = '<img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/icon_facebook.gif">&nbsp;<a href="${facebookURL}" target="_blank">See more events on our Facebook page</a>&nbsp;<img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/icon_popup.gif">';
			HD.FacebookEventsWidget.templates.facebookURL = 'http://www.facebook.com/harley-davidson';
			HD.FacebookEventsWidget.templates.noneLabel = '<div class="noEventsContainer"><img src="/en_US/Media/images/Content/Pictorial/dark_custom_v3/events_noneicon.gif"> Please check back later for upcoming events.</div>';
			HD.SendFriendWidget.templates.sendFriendInstructionalText = this.templates.sendFriend.sendFriendTemplates.sendFriendInstructionalText;
			
			// Initialize the main engine.
			this.engine = new HD.CommunityEngine(this.config);
			
			// Attach widget observers.
			this.setObservers();
			
			// Attach DOM event listeners.
			this.setListeners();
			
			// Set global templates.
			this.setTemplates();
			
			// Set analytics
			if (this.setAnalytics) {
				this.setAnalytics();
			}

			
			
			// Create the object to be shared here
			var sharedItem = {
					author : "Dark Custom",
					category : "Dark Custom",
					description : 'Dark Custom | Events',
					thumbUrl : '',
					title : 'Dark Custom | Events'
			};
			
			this.engine.dao.notifyObservers.call(this.engine.dao, "loadShare_Start", sharedItem);
			this.engine.dao.notifyObservers.call(this.engine.dao, "loadSTAF_Start", sharedItem);
			
			// Get media.
			this.engine.dao.getFutureFacebookEvents();
			//this.engine.dao.getTwitterFeed();

		},
	
		// Engine/widget config.
		config: {
			dao: {
				baseUrl : comSvcBaseUrl,
				siteName : comSiteName,
				contentType : 'both',
				categories : [],
				startIndex : startIndex,
				pageSize : itemsX * itemsY
			},
			cluster: {
				baseUrl : comMediaBaseUrl
			},
			view: {
				navigation : 'nav',
				canvas : 'canvas'
			},
			widgets: {
				share: {
					parent: 'share',
					type: 'hd_share_widget',
					getPermalink: function(media) {
						return window.location.href;
					},
					services: [services.FACEBOOK, services.TWITTER, services.MYSPACE, services.BLOGGER, services.WORDPRESS],
					callback: function(service, title, description, thumbnail, permalink) {
						
					},
					standaloneMode: true
				},
				sendFriend: HD.merge({
					parent: 'sendFriend',
					type: 'hd_send_friend_widget',
					standaloneMode : true
				}, sendFriendConfig),
				facebookEvents: {
					parent: 'facebookEventsDiv', 
					type: 'hd_facebook_events_widget' ,
					dateFormat : dateFormat
				},
				twitter: {
					parent: 'eventsLatest', 
					type: 'hd_twitter_feed_widget' 
				}
			}
		},
		
		// Attach observer methods to widgets.
		setObservers: function() {
			var self = this;
		
		},
		
		// Attach DOM event listeners.
		setListeners: function() {
			var self = this;
			
		},
		
		// Retrieve the current navigation location.
		getNavigation: function() {
			return window.location.href;
		},
		
		// Set custom templates.
		setTemplates: function() {
			// Custom templates as necessary.
		}

	};
})();

// Load the page.
HD.util.DOM.onDOMReady(function() {
	DarkCustom.init();
});

