function worktop(){

	this.MyRequests = null;
	this.SecondarySubscription = null;
	this.PrimarySubscription = null;
	this.teamGraph = null;


	this.locateLayoutTemplate = function(){
		return "/static/jstl/worktop/worktop.jstl";
	}

	this.locateViewTemplates = function(){
		var viewTemplates = new Array();
		viewTemplates['my_inbox'] ="/static/jstl/worktop/views/worktop.my_inbox.jstl";
		viewTemplates['team_inbox'] ="/static/jstl/worktop/views/worktop.team_inbox.jstl";
		viewTemplates['search'] ="/static/jstl/worktop/views/worktop.search.jstl";
		viewTemplates['my_requests'] ="/static/jstl/worktop/views/worktop.my_requests.jstl";
		return viewTemplates;
	}

	this.start = function()
	{
		var sheetMetadataId = this.url.split('=')[1]
		this.resetPseudoGraph()
		urlList = this.url.split('/')
		this.sheetMetadataId = urlList[3];
		this.activityDefinitionId = urlList[4];
		this.applicationId = urlList[1];
		this.metadatatype = urlList[2];
		this.search('PrimarySubscription',sheetMetadataId)
		this.search('SecondarySubscription',sheetMetadataId)
		//this.search('MyRequests',sheetMetadataId)
	}

	//Override search method in editor.js
	this.search = function(searchType,sheetMetadataId)
	{
		searchUrl = this.constructBaseUrl()+'/'+this.getRoot().getValue('SheetId')+"/"+searchType+"/search"
		if (sheetMetadataId)
			searchUrl = searchUrl+"?MetadataId="+sheetMetadataId
		var controller = this
		selectData = jQuery.ajaxQueue({type:'GET', url:searchUrl, dataType: "json", async:true,
			success: function(data){
						if(searchType=='PrimarySubscription')
							controller.PrimarySubscription = controller.getAggregateData(data)
						else if(searchType=='SecondarySubscription')
							controller.SecondarySubscription = controller.getAggregateData(data)
						else if(searchType=='MyRequests')
							controller.MyRequests = controller.getAggregateData(data)
						controller.render()
				}
		});
		return selectData;
	}

	this.getAggregateData = function(data)
	{
		var sheetMetadataList= {}
		processInstances = data[data['root']]['ModifiedBy.ProcessInstance']
		for (sheet in processInstances) {
			val = processInstances[sheet]
			var stringSplitArray = val.split('~')
			var sheetMetadata = stringSplitArray[0];
			var sheetMetadataId = stringSplitArray[1]
			var activityMetadata = stringSplitArray[2];
			var activityMetadataId = stringSplitArray[3];
			if (!sheetMetadataList[sheetMetadata]) {
				sheetMetadataList[sheetMetadata] = {};
				sheetMetadataList[sheetMetadata][activityMetadata] = {}
				sheetMetadataList[sheetMetadata][activityMetadata]['ActivityId'] = activityMetadataId;
				sheetMetadataList[sheetMetadata][activityMetadata]['count'] = 1;
				sheetMetadataList[sheetMetadata]['SheetId'] = sheetMetadataId;
			}
			else {
				if (!sheetMetadataList[sheetMetadata][activityMetadata]) {

					sheetMetadataList[sheetMetadata][activityMetadata] = {}
					sheetMetadataList[sheetMetadata][activityMetadata]['count'] = 1;
					sheetMetadataList[sheetMetadata][activityMetadata]['ActivityId'] = activityMetadataId;
				}
				else {
					sheetMetadataList[sheetMetadata][activityMetadata]['count']++;
				}
			}
		}
		return sheetMetadataList
	}

}
worktop.prototype = new runtime_controller;