function CommunityApp() {

	CommunityApp.baseConstructor.call(this, null, "communityApp"); 
	this.componentController = new ComponentController();
	
	// Registers this app itself to subscribe to events
		this.componentController.register(this);

		this.loginComponent = new LoginComponent($("#loginComponent"));
		this.componentController.register(this.loginComponent);
		//tracker		
    	this.SessionTracker = new Tracker();
    	this.componentController.register(this.SessionTracker);
    	
		this.componentController.init();
		
		this.searchUserURL	=	MACEConstants.rootURL+"pages/community/php/searchUser.php";
		
		this.initDOMElems();
}
CommunityApp.extend(Component);


	/******************************************/		
	
		
	CommunityApp.prototype.initDOMElems = function(){

		this.$searchForm=$("#memberSearchForm");
		this.$keywordInputField=$("#searchBox");
		this.$usergroups=$("#usergroups");
		this.$foundUsers=$("#foundUsers");
		this.$usergroups.show();
		this.$foundUsers.hide();
		this.$memberListe=$("#memberListe");
	
		var _this = this;
		this.$searchForm.submit(
			function(){
					_this.$usergroups.hide();	
					_this.$foundUsers.show();
					
					_this.searchUser(_this.$keywordInputField.val());
				return false;
			}
		);
	     //tipsy
        //	$(".memberListLink").tipsy({fade: true, gravity:"s"});
        
	}
	/******************************************/	

	
	CommunityApp.prototype.onError = function(results) {
		
		if(results.notlogged)
			this.$memberListe.html('<span>Due to privacy issues you should log in to perform a user search</span>');
		else
			this.$memberListe.html('<span>Nobody found</span>');

	}


	/******************************************/	
	CommunityApp.prototype.searchUser = function(term ){

		 var o={};
		 o.searchterm=term;
		 o.searchConstraint=	$("input[@name='searchConstraint']:checked").val();
    
    
		 var _this = this;
    
		 // load results
		 $.getJSON(this.searchUserURL, o, function(results){
		 		if(!results.success){
		 			_this.onError(results);
		 		} else {
					_this.$memberListe.html("");
					var members=results.resultList;
					if(results.numResults >0){
						
					  for (var i = 0; i < members.length; i++) {
				  
					  	_this.$memberListe.append("<li class='memListElement'><a  class='memberListLink' href='"+MACEConstants.rootURL+"user/"+members[i].nickName+"' > <div class='userTile' style='background-image: url("+members[i].icon+"); height: 104px; width:130px; margin-bottom: 36px;'><div class='userTile_name'>"+members[i].fullname+"</div></div></a></li>");
			
					  }
	 
	    			}
					else{
						_this.$memberListe.append('<span>Nobody found</span>');
				
					}
		 		}
		 	}
		 	,this.onError);
	}

	