/*

	Class: VIEWZI.dataproc

	The Viewzi dataproc class is for client side data manipulation.

*/

/*
	Function: VIEWZI.dataproc.createTagCloud

		Create a tag cloud of supplied data objects
		
	Parameters:
		
		dataObj		- the dataObj returned from the server or data store
		useTitles	- use titles for nodes that do not have tag fields
		dataCloud	- an existing tag cloud to move new tags into

	Returns:

		Array
*/

	VIEWZI.dataproc.createTagCloud = function(dataObj, useTitles, dataCloud)
	{
		var tagArray	= [];
		var finalTags	= [];
		var useTitles	= (useTitles==null) ? true : useTitles;
		var excludeList	= "the,and,for,of,but,he,she,we,to,in,there,their,our,is,are,it,a,be";
		var charList	= ["\"", "'", "`", "?", ";", "<", ">"];

		for (var t in dataObj) {
			for (var x=0; x<dataObj[t].length; x++) {
				
				/* clear the tags yo */
				delete tags;
				
				/* create tags from obj or list on metadata */
				if (dataObj[t][x].metadata.tags) {
					var tags	=  (typeof(dataObj[t][x].metadata.tags) == "object") ? dataObj[t][x].metadata.tags : dataObj[t][x].metadata.tags.split(",");
				/* or from the titles if they have indicated to do so */
				} else if (useTitles) {
					var tags	= dataObj[t][x].title.split(" ");
				}
				
				if (tags) {
					/* clean em and increment the list */
					for (var y in tags) {
						/* change em to all lowercase */
						tags[y] = tags[y].toString().toLowerCase();
						for (var c in charList) {
							/* clear out any unwanted chars, esp from tags from titles */
							if (tags[y].indexOf(charList[c])>=0) tags[y] = tags[y].split(charList[c]).join("");
						}
						/* increment the tag list */
						tagArray[tags[y].toString().toLowerCase()] = (tagArray[tags[y].toString().toLowerCase()]==undefined) ? 1 : tagArray[tags[y].toString().toLowerCase()]+1;
					}
				}
			}
		}
		
		for (var x in tagArray) {
			/* plop them into the final list as objs, if they are valid tags */
			if (tagArray[x] > 0 && x.toString().length > 1 && excludeList.indexOf(x) < 0) finalTags.push({tag:x, val:tagArray[x], active:true});
		}
		
		/* sort the final list */
		finalTags.sort(function(a,b) {return(a.val - b.val);});
		finalTags.reverse();
		
		/* debug trace */
		VIEWZI.trace.fire({module:"DATAPROC",msg:"createTagCloud found "+finalTags.length+" tags"});
		
		return finalTags;
	};
	
/*
	Function: VIEWZI.dataproc.dedupe

		Create a deduplicated list from 2 seperate data source returns

	Parameters:

		dataObj1	- the source data object
		dataObj2	- the compare data object
		 
	Returns:

		Array
*/
	
	VIEWZI.dataproc.dedupe = function (dataObj1, dataObj2)
	{
		// TODO : MOVE THIS OVER FROM AS3
		return dataObj1;
	};
	