
var myPropertyArray = new Array();
var myMethodArray = new Array();

function ObjectMethod(name,description,prefix,parameters,sampleParameters){
	this.prefix = prefix||"Object";
	this.name = name||"Name";
	this.description = description;
	this.parameters = parameters||"NONE";
	this.sampleParameters = sampleParameters;
	this.usage = function(){
		if(!this.sampleParameters)return null;		
		if(this.sampleParameters.length<1)return null;			
		return '<small>Usage:</small> <code>' + this.prefix +'.'+ this.name + 
			'('+ this.sampleParameters + ')</code>';
	};				
	this.explanation = function(){
		var v = this.description;
		if(this.usage())v += "<br>" + this.usage();
		return v;
	};
}

function ObjectProperty(name,type,description,defaultValue,sampleValue,prefix){
	this.prefix = prefix||"Object";
	this.name = name;
	this.type = type;
	this.description = description;
	this.defaultValue = defaultValue;
	this.sampleValue = sampleValue;
	this.usage = function(){
		if(!this.sampleValue)return null;
		if(this.sampleValue.length<1)return null;
		var v;			
		if(this.type=="String") v='"'+this.sampleValue+'"';
		else v = this.sampleValue;
		return '<small>Usage:</small> <code>' + this.prefix +'.'+ this.name + ' = ' +
			'<font class="'+ this.type +'">'+ v + '</font></code>';
	};				
	this.explanation = function(){
		var v = this.description;
		if(this.defaultValue)v += " - <i>Default is</i> <code><font class=\""+this.type+"\">"+ this.defaultValue +"</font></code>"
		if(this.usage())v += "<br>" + this.usage();
		return v;
	};
}

function setProperty(name,type,description,defaultValue,usage,prefix) {
	myPropertyArray[myPropertyArray.length] = new ObjectProperty(name,type,description,defaultValue,usage,prefix);
}

function setMethod(name,description,prefix,parameters,sampleParameters) {
	myMethodArray[myMethodArray.length] = new ObjectMethod(name,description,prefix,parameters,sampleParameters);
}

function printObjectTOC(myArray,url,title){
	document.write('<table class="toc" border="0" cellpadding="1" cellspacing="0"><tr><th colspan="2">'+title+'</th></tr>');
	for(var i=0;i<myArray.length;i++){					
		var p = myArray[i]; 
		document.write('<tr><td><a href="'+url+'#'+p.name+'">'+ p.name+'</a></td><td>&nbsp;'); 
		if((i+1)<myArray.length){
			var p = myArray[i+1];
			document.write('<a href="'+url+'#'+p.name+'">'+ p.name+'</a>'); 
		}
		document.write('</td></tr>');
		i++;
	}
	document.write('</table>');
}

function printObjectProperties(toc,url){
	
	if(myPropertyArray.length<1){
		loadObjectProperties();
	}	
	myPropertyArray.sort(compareName);
	
	document.write('<div class="api">');
	if(toc){
		printObjectTOC(myPropertyArray,url,"Properties");
	}else{
		document.write('<div class="title">Properties</div><table class="description" border="0" cellpadding="2" cellspacing="1" bgcolor="gray">');
		document.write('<tr bgcolor="#cccccc"><th>Property</th><th>Explanation</th><th>Type</th></tr>');
		for(var i=0;i<myPropertyArray.length;i++){					
			var p = myPropertyArray[i]; 
			document.write('<tr bgcolor="#ffffff"><td valign="top" nowrap="true">'+
				'<a name="'+p.name+'"></a>'+ p.name+'</td><td>'+p.explanation()+
				'</td><td valign="top"><code class="keyword">'+p.type+'</code></td></tr>'); 
		}
		document.write('</table>');
	}
	document.write('</div>');
}

function printObjectMethods(toc,url){
	
	if(myMethodArray.length<1){
		loadObjectMethods();
	}	
	myMethodArray.sort(compareName);
	
	document.write('<div class="api">');
	if(toc){
		printObjectTOC(myMethodArray,url,"Methods")
	}else{
		document.write('<div class="title">Methods</div><table class="description" border="0" cellpadding="2" cellspacing="1" bgcolor="gray">');
		document.write('<tr bgcolor="#cccccc"><th>Method</th><th>Explanation</th><th>Parameters</th></tr>');
		for(var i=0;i<myMethodArray.length;i++){					
			var p = myMethodArray[i]; 
			document.write('<tr bgcolor="#ffffff"><td valign="top" nowrap="true">'+
				'<a name="'+p.name+'"></a>'+ p.name+'</td><td>'+p.explanation()+
				'</td><td valign="top"><code>'+p.parameters+'</code></td></tr>'); 
		}
		document.write('</table>');
	}
	document.write('</div>');
}

function compareName(a,b){
	if(!a.name)return 1;
	if(!b.name)return -1;
	if(a.name < b.name)return -1;
	else if(a.name > b.name)return 1;
	else return 0;
}
