dojo.declare("dojom.data.Entity", null, 
{
	id 			: null,
	name 		: null,
	images		: null,
    author 		: null,
    author_info : null,
    author_id	: null,
    store		: null,
    url 		: null,
    price 		: null,
    category 	: null,
    keywords 	: null,
    description : null,
    modifyDate  : null,
    rate		: null,   
    comments	: null,
    
    log			: null,
    
    
	constructor: function ()	
	{
		this.log = LOG.addClass('Entity');
	},
	
	getLoaderNode : function()
	{
		try{
			var table = document.createElement("table");			  	
			table.setAttribute('style','width:100%; height:100%;');
			table.appendChild(document.createElement('tr')).appendChild(function(){
		  		var td = document.createElement('td');
				td.setAttribute('align','center');
				td.setAttribute('valign','middle');
				td.appendChild(function(){
					var img = document.createElement('img');
					img.src = 'images/loading.gif';
					return img;
				}());
				td.appendChild(document.createElement('br'))
				td.appendChild(document.createElement('br'))
				td.appendChild(function(){
					var span = document.createElement('span');
					span.setAttribute('style','font-style: italic; font-size: smaller');
					span.innerHTML = 'Loading...';
					return span;
				}());
				return td;
		  	}());
		  	return table;
		}catch(ex){this.log.error('getLoaderNode.'+ex)}
	},
	
	getImageNode: function(){
		var entity = this;
		try{
			var div = document.createElement('div');
			div.setAttribute('id','div_main_preview_img');
			
			div.appendChild(function(){
	  		    	var img = document.createElement('img');
	  		    	if(entity['images']!=null && entity['images'].length > 0 )
	   		    	img.src = entity['images'][0];
	   		    else
	   		    	img.src = 'images/availble.jpg';
	  		    	img.setAttribute('style','border:1px; solid: #ccc;');
	  		    	
	  		    	return img;
	  		    }());	
	  		//copyright info
	  		div.appendChild(document.createElement('br'));
	  		div.appendChild(function(){
	  			var _copyrightSpan = document.createElement('span');
				_copyrightSpan.setAttribute('style','font-size:10px;font-color:#eeeeee;font-style:italic;text-align:center;');
				_copyrightSpan.innerHTML="Image may be subject to copyright.";
				return _copyrightSpan;
	  		}())
			//eo copyright info
	  				   		
			
			return div;
		}catch(ex){this.log.error('getImageNode. '+ex)}
	},
	
	getNameNode: function(){
		var entity = this;
		try{
			var p = document.createElement('p');
	    	p.className = 'p_header_name';	    	
	    	if(entity['name'] != null)
	    		p.innerHTML = entity['name'];	    	
	    	return p;
		}catch(ex){this.log.error('getImageNode. '+ex)}
	},
	
	getDetailsNode: function()
	{
		var entity = this;
		try{
			var ul = document.createElement('ul');
			ul.childs = {};
			    			   		    			   		    	
			if(entity['price'] != null)
				ul.childs['price'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Price: ';
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = '$'+entity['price'];
						return span;
					}());									
					return li;
				}());
			
			if(entity['category'] != null)
				ul.childs['category'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Category: ';	
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['category'];
						return span;
					}());							
					return li;
				}());
			
			if(entity['author'] != null)
			{
				ul.childs['author'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Author: ';	
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['author'];
						return span;
					}());							
					return li;
				}());
				
				ul.childs['author_info'] = ul.appendChild(function(){
					var li = document.createElement('li');										
					return li;
				}());	
			}
			
			if(entity['store'] != null)
				ul.childs['store'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Published at: ';
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['store'];
						return span;
					}());								
					return li;
				}());
			
			if(entity['url'] != null)
				ul.childs['url'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.setAttribute('style','list-style-type: square; margin-left: 1.2em;');
					li.innerHTML = '<a href="/servlets/redirect.htm?id='+entity['id']+'" target="_blank">Content link</a>';								
					return li;
				}());
				    	
			if(entity['rate'] != null)
				ul.childs['rate'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Rating: ';
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['rate']+' of 10';
						return span;
					}());									
					return li;
				}());
			
			if(entity['keywords'] != null)					
				ul.childs['keywords'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Keywords: ';								
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['keywords'];
						return span;
					}());								
					return li;
				}());
			
			if(entity['modifyDate'] != null)
				ul.childs['modifyDate'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.innerHTML = 'Last modify: ';
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = entity['modifyDate'];
						return span;
					}());									
					return li;
				}());
				    
			if(entity['comments'] != null)
				ul.childs['comments'] = ul.appendChild(function(){
					var li = document.createElement('li');
					li.setAttribute('style','list-style-type: square; margin-left: 1.2em;');	
					li.appendChild(function(){
						var span = document.createElement('span');
						span.innerHTML = 'Comments('+entity['comments'].length+')';
						return span;
					}());								
					return li;
				}());		   		   	 			   		    	
	    	return ul;
	    }catch(ex){this.log.error("getDetailsNode. "+ex)}
    },
    
    getDescriptionNode : function()
    {
    	var entity = this;
    	try{
			var div = document.createElement('div');
			div.setAttribute('style','margin: 0.2em; clear: left; width: auto; height: auto;');														
			div.innerHTML = '<p class="p_header_desc">Description: ';	
			div.appendChild(function(){
				var span = document.createElement('span');
				span.innerHTML = entity['description'];
				return span;
			}());							
			return div;
		}catch(ex){this.log.error('getDescriptionNode.'+ex)}
	},
	
	getCommentsNode : function()
	{
		var entity = this;
		try{			
			var ul = document.createElement('ul');			
			
			for(var i=0;i< entity['comments'].length;i++)
			{							
				var li = document.createElement('li');
				var div = document.createElement('div');
				div.appendChild(document.createElement('div')).appendChild(function(){
					var span = document.createElement('span');
					span.setAttribute('style','font-weight:bold;');
					span.innerHTML = '<b>'+entity['comments'][i]['user']+'</b>';
					return span;
				}());
				div.appendChild(function(){
					var span = document.createElement('span');
					span.setAttribute('style','width:400px;');
					span.innerHTML = '<b>'+entity['comments'][i]['comment']+'</b>';
					return span;
				}());
				div.appendChild(document.createElement('div')).appendChild(function(){
					var span = document.createElement('span');
					span.setAttribute('style','font-style:italic;');
					span.innerHTML = '<b>'+entity['comments'][i]['created']+'</b>';
					return span;
				}());
				li.appendChild(div);
				ul.appendChild(li);
			}			
			
			return ul;
		}catch(ex){this.log.error('getCommentsNode.'+ex)}
	}
});

