var comSvcBaseUrl = "/Community/services";
var comMediaBaseUrl = "/Community/media";
var comSiteName = "Dark Custom";

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: 'Downloads'
		},
	
		// 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();
			});
			
			//Override copy
			HD.SendFriendWidget.templates.sendFriendInstructionalText = this.templates.sendFriend.sendFriendTemplates.sendFriendInstructionalText;
			
			// Initialize the main engine.
			this.engine = new HD.CommunityEngine(this.config);
			
			// 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 | Downloads',
					thumbUrl : '',
					title : 'Dark Custom | Downloads'
			};
			
			this.engine.dao.notifyObservers.call(this.engine.dao, "loadShare_Start", sharedItem);
			this.engine.dao.notifyObservers.call(this.engine.dao, "loadSTAF_Start", sharedItem);
		},
	
		// 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.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)
			}
		}
	};
})();

// Load the page.
HD.util.DOM.onDOMReady(function() {
	DarkCustom.init();
});
