/***** Image Processor *****
Copyright 2007, Axletree Media, Inc. All rights reserved.
ImageProcessor loads an array of selected links from a menu DOM id and accepts a list of possible matches.

var obj = new ImageProcessor("menu");
obj.Add("t1:u1")	adds a new search title and (optionally) url
obj.Randomize()	returns a random item
obj.Compare()	performs search for selected link title that matches item title
obj.HasMatch	returns true if a match was found
obj.Match		returns the matching item's URL
****************************/

function ImageProcessor (dom_id) {
	this.Links		= new Array();
	this.Titles		= new Array();
	this.Match		= null;
	this.HasMatch	= false;
	this.LoadLinks	= LoadLinks;
	this.Add		= AddItem;
	this.Randomize	= GetRandomItem;
	this.Compare	= CompareTree;
	this.LoadLinks(dom_id);
}
function LoadLinks(dom_id){if(document.getElementById&&document.getElementById(dom_id)){var links=(document.getElementById(dom_id)).getElementsByTagName("a");var a=links.length-1;for(var i=a;i>=0;i--){var linkClass=(links[i].className!=undefined)?links[i].className:links[i].getAttribute("class");if(linkClass!=null&&linkClass.indexOf("selected")!=-1){this.Links[this.Links.length]=((links[i].innerHTML).replace(/\W/g,"")).toLowerCase();}}}}
function CompareTree(){for(var j=0;j<this.Links.length;j++){for(var k=0;k< this.Titles.length;k++){if(this.Links[j]==this.Titles[k].Title&&this.HasMatch==false){this.HasMatch=true;this.Match=this.Titles[k].URL;break;}}}}
function AddItem(item){if(item!=null){item=item.split(":");if(item.length==1){item[1]=item[0];}this.Titles[this.Titles.length]=new IItem(item[0].toLowerCase(),item[1]);}}
function GetRandomItem(){this.HasMatch=true;this.Match=this.Titles[Randomize(this.Titles)].URL;}
function IItem(title,url){this.Title=title;this.URL=url;}
function Randomize(ary){var s=1;if(ary!=null){s=ary.length;}return(((new Date()).getSeconds())%s);}
