HD.util.DOM.onDOMReady(init);

var comSvcBaseUrl = "/Community/services";
var comMediaBaseUrl = "/Community/media";
//var comSiteName = "Harley-Davidson";
var comSiteName = "Harlista";

var login = null;
var widgetCluster = null;

function init() {
	try {
	var itemsX = 1;
	var itemsY = 3;
	var startIndex = 1;
	
	HD.util.DWR.initSession();
	HD.util.DWR.setErrorHandler();
	
	var classes = HD.CSS_CLASSES;
	
	var daoConfig = {
		baseUrl : comSvcBaseUrl,
		siteName : comSiteName,
		contentType : 'both',
		categories : ['Harlistas'],
		startIndex : startIndex,
		pageSize : itemsX * itemsY,
		thumbWidth : 100,
		mediaWidth : 420
	};
	
	var communityDao = new HD.CommunityDAO(daoConfig);
	
	var clusterConfig = {
		baseUrl : comMediaBaseUrl
	};
	
	var widgetCluster = new HD.WidgetCluster(communityDao, null, clusterConfig);
	
	var clusterWidgets = [
		{
			parent: 'featureStoriesDiv',
			type: 'hd_feature_stories_widget',
			contentType: 'both',
			pageSize: 3,
			previewLength: 30
		}
	];
	
	// initialize widget controller
	widgetCluster.init(clusterWidgets);
	
	var isDateRangeSet = false;
	// setup listeners to respond to various events
	var viewObserver = {
		update : function(eventName, eventData) {
		
			if (eventName == 'viewFeatureStory') {
				window.location.href = '/wcm/Content/Pages/harlistas/harlistas_UGC.jsp?locale=en_US#loc=' + 'detail/' + eventData.contentType + '/' + eventData.mediaId;
			} 
			
			else if (eventName == 'viewAllFeatureStories') {
				window.location.href = '/wcm/Content/Pages/harlistas/harlistas_UGC.jsp?locale=en_US';	
			}
			else if (eventName == 'getPopular_Finish'){
				widgetLoaded.fire();
			}
		}
	};
	
	var popularWidget = widgetCluster.getWidget(0);
	popularWidget.addObserver(viewObserver);
	
	// add listeners to signaling objects
	communityDao.addObserver(viewObserver);
	
	communityDao.getPopular(clusterWidgets[0].pageSize, HD.SORTS.NEW_TO_OLD);
	
	login = new HD.Login({siteName : comSiteName});
	
	}
	catch(e) {
		//console.error(e);
	}
	

};
