function MyContent($element,userID) {
	MyContent.baseConstructor.call(this, null, "MyContent"); 
	
	this.$resultlist_element=$element;
	this.userID=userID;

	this.getBookmarksURL=MACEConstants.rootURL+"pages/mypage/php/get_bookmarks.php";
	this.getBookmarksForTagURL=MACEConstants.rootURL+"pages/mypage/php/get_bookmarksForTag.php";
	// /* to few info comes back*/	this.getBookmarksForTagURL=MACEConstants.rootURL+"components/search/php/ServiceConnectorAloe.php";
	
	this.bookmarks=[];
	
	this.currentPage=1;
	this.itemsPerPage = 12;
	this.contentsObj=null;
	
	this.contents="all";
	
    this.initDOMElems();
}
MyContent.extend(Component);
			
MyContent.prototype.initDOMElems = function(){
    
	this.resultList=new ResultList(this.$resultlist_element);
	
	this.resultList.setListElementTemplate(ResultList.bookmarkListElementTemplate);

	this.resultList.displayMessage("<span class='.loadingMessage'>"+mypage_dialogs.Loading_Contents+"...</span>");
	
	var _this=this;
	this.resultList.onPageChanged=function(pageNum){
	   	_this.goToPage(pageNum);
   	}

   this.searchResults=[];
   this.loadResults();
}


MyContent.prototype.goToPage = function(pageNum){
	console.log("MyContent onGoToPage "+pageNum);
	this.currentPage=pageNum;
	this.keepCurrentPage=true;
	this.loadResults();
}

MyContent.prototype.loadResults = function() {
    console.log("MyContent loadResults "+this.currentPage);
    //this.contents
    if(this.contents == "all" ){
        this.getResults( this.currentPage, this.itemsPerPage,"all");
    }
    else{
        this.getNextpageresults();
    }


}

MyContent.prototype.getNextpageresults = function (){
	
	this.displaySearchResults=new Array();

	var start = (this.currentPage*this.itemsPerPage) - this.itemsPerPage;
	var end = this.currentPage*this.itemsPerPage;
	if(end > this.numResults)
		end = this.numResults;
	for(i=start;i < end;i++){
		this.displaySearchResults.push(this.searchResults[i]);
	}
	
	this.displayResults();
}

MyContent.prototype.getResults = function( currentPage, itemsPerPage,task){

    this.contents="all";
    
    
//   this.resultList.reset();
//   this.resultList.displayMessage("Loading Contents...");

	var o={};
	// index of first result
	o.count=1+(currentPage-1)*itemsPerPage;	
	o.itemsPerPage=itemsPerPage;
	o.userID=this.userID;
	



	//task for type filtering
	o.task=task;
		
	var _this = this;

	// load results
	$.getJSON(this.getBookmarksURL, o, function(results){
			if(!results.success){
				_this.onError(results);
			} else {
				_this.searchResults	=results.resultList;
		
				var msg = results.numResults + mypage_dialogs.Contents_found;
				_this.onResult(results.resultList,results.numResults,msg);
				_this.contentsObj=results.resultList;
			}
		}
		,this.onError);
}
/******************************************/

in_array = function ( check ,arr) {
	var len = arr.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		
	
		if ( arr[x] == check ) return true;
	}
	return false;
}
/******************************************/
/*
MyContent.prototype.filterTaggedResults = function(){

	this.getResults( this.currentPage, this.itemsPerPage,"tagged");

}


MyContent.prototype.filterCommentedResults = function(){

	this.getResults( this.currentPage, this.itemsPerPage,"comment");

}

MyContent.prototype.filterGoodResults = function(){

this.getResults( this.currentPage, this.itemsPerPage,"goodstuff");

}

MyContent.prototype.filterBadResults = function(){
	this.getResults( this.currentPage, this.itemsPerPage,"badstuff");

}

  */

MyContent.prototype.filterResultsByTag = function(tag){
	
	this.contents="tagged";
	
	var o={};
	
	o.userID=this.userID;
	o.count=1+(this.currentPage-1)* this.itemsPerPage;	
	o.itemsPerPage=this.itemsPerPage;
	//tag filtering
	if(tag !="")
		o.tag=tag;
	
	var _this = this;
	
	// load results
	$.getJSON(this.getBookmarksForTagURL, o, function(results){
			if(!results.success){
				_this.onError(results);
			} else {
			    
			    if(results.numResults ==0){
			        _this.resultList.displayResults({}, mypage_dialogs.No_Contents_found, 1, 1);
			    }
		        else{	
				    _this.searchResults	=results.resultList;
	    			var msg = results.numResults + mypage_dialogs.Contents_found_tagged_with+" "+tag
	    			_this.onResult(results.resultList,results.numResults,msg);
				
				}
			}
		}
		,this.onError);


}

MyContent.prototype.reset = function(){
  
		var msg = this.contentsObj.length + mypage_dialogs.Contents_found;
		this.onResult(this.contentsObj,this.contentsObj.length,msg);
	
}

MyContent.prototype.onResult = function (searchResults, numTotal,msg){

	var _this=this;	
	this.numResults	=	numTotal;

	this.resultList_msg	=	msg;
	
	this.displaySearchResults=new Array();
	$.each(searchResults, function(i,obj) {
		// Creates catalog as object from string
		obj.catalog = LOM.guessCatalog(obj.catalog);

		if(i< _this.itemsPerPage){
			_this.displaySearchResults.push(obj);
				
		}
	});
	//if(numTotal > 0){
		
		this.displayResults();
	//}
}

MyContent.prototype.onError = function() {
	this.displayMessage("No results");
	this.numResults=0;
	this.searchResults=[];
	this.displayResults();
}

MyContent.prototype.displayResults = function() {
	if(!this.keepCurrentPage){
		this.currentPage=1;
	}
	if(this.resultList_msg==undefined){
		this.resultList_msg="<span class=\".loadingMessage\">"+mypage_dialogs.Loading_Contents+"...</span>";
	//
	}
	
	this.resultList.displayResults(this.displaySearchResults, this.resultList_msg, this.currentPage, Math.ceil(this.numResults/this.itemsPerPage));		

}

MyContent.prototype.displayMessage = function(msg){
	this.resultList.displayMessage(msg);
}


