function twit(ident) {
    
    this.ident = ident;
   /* this.url = "http://www.twitter.com/search.json";
    this.params = {q:"from%3Aeddjc",
                    rpp: 20,
                    callback:"foo"}
    this.params = Array();
    this.loadObject = new JSONLoader(this.ident + "Loader", this, this.url, this.params);*/
   
    this.target = document.getElementById(ident);
    
    
    this.result;
    
    this.init = function() {
        
        /*this.loadObject.init();
        
        objectTracker.trackObject(this);
        
        this.loadObject.load();*/
        
    }
    this.loadData = function (data) {
        this.result = data;
        this.display();
    }
    
    this.onSuccess = function(paramsArray) {
        this.result = paramsArray;
        //this.display();
        //alert("loaded");
        
    }
    this.notify = function (message) {
        //alert(message);
        
    }
    
    this.display = function () {
        
        for (j=0; j < 1; j++) {
            current = this.result.results[j];
            
            li = document.createElement("li");
            li.innerHTML = this.format(current.text) + " <br /><span>" + this.dateFormat(current.created_at) + "</span>";
            
            this.target.appendChild(li);
        }
    }
    
    this.dateFormat = function (dateString) {
        function addzeros(date)  {
            if (date < 10 ) return "0" + date;
            else return date;
        }
        
        function twelvehr (date) {
            if (date > 12) return date - 12;
            else return date;
        }
        
        function meridian(date) {
            if (date > 12) return "pm";
            else return "am";
        }
        
        console.log(dateString);
        
        var d = new Date(dateString);
        
        var result = "" + d.getDate() + "/" + d.getMonth() + "/" + d.getFullYear() + " " + twelvehr(d.getHours()) + ":" + addzeros(d.getMinutes()) + meridian(d.getHours());
        
        return result;
    
        
    }
    
    this.format = function(text) {
        var result = "";
        
        var httpArray = this.searchString(text, /http:\/\/[a-zA-Z0-9\/.?&%_=]*/);
        
        if (httpArray.length > 0 ) {
            
        
            currentBit = 0;
            
            for (x = 0; x < httpArray.length; x++) {
                
                result += text.substring(currentBit, httpArray[x].start)+ "<a href = \"" + httpArray[x].text + "\" target=\"_blank\" class=\"link\">" + httpArray[x].text + "</a>";
                
                currentBit = httpArray[x].end;
            }
            
            result += text.substring(httpArray[httpArray.length - 1].end, text.length);
        }
        else result = text;
        
        var hashTagArray = this.searchString(result, /#[\d\w]*/);
        
        if (hashTagArray.length > 0 ) {
            
            var newResult = "";
            
            currentBit = 0;
            
            for (x = 0; x < hashTagArray.length; x++) {
                
                newResult += result.substring(currentBit, hashTagArray[x].start)+ "<a href = \"http://twitter.com/#search?q=%23" + hashTagArray[x].text.substring(1, hashTagArray[x].text.length) + "\" target=\"_blank\" class=\"hash\">" + hashTagArray[x].text + "</a>";
                
                currentBit = hashTagArray[x].end;
            }
            
            newResult += result.substring(hashTagArray[hashTagArray.length - 1].end, result.length);
            result = newResult;
            
        }
        
        
        
        var atArray = this.searchString(text, /@[\d\w]*/);
        if (atArray.length > 0 ) {
            
            var newResult2 = "";
            
            currentBit = 0;
            
            for (x = 0; x < atArray.length; x++) {
                
                
                newResult2 += result.substring(currentBit, atArray[x].start)+ "<a href = \"http://www.twitter.com/" + atArray[x].text.substring(1, atArray[x].text.length) + "\" target=\"_blank\" class=\"at\">" + atArray[x].text + "</a>";
                
                currentBit = atArray[x].end;
                
            }
            
            newResult2 += result.substring(atArray[atArray.length - 1].end, result.length);
            
            result = newResult2;
            
        }
        
        return result;
        
        
    }
    
    this.searchString = function (string, regExp) {
	
	result = Array();
		
	for (x = 0; x < string.length; x++) {
		
	    start = string.substring(x, string.length).search(regExp);
            
            if (start != -1) {
                
                start += x;
                
                middle = string.substring(start, string.length).match(regExp);
                
                end = start + middle[0].length;
                
                x = end;
                
                result[result.length] = {"start": start, "end": end, "text": middle[0]};
                
            }
            else break;
            
			
	}
		
	return result;
    }
}

function JSONLoader(ident, caller, url, params) {
    
    this.ident = ident;
    this.xhr;
    this.caller = caller;
    
    this.url = url;
    this.params = params;
    
    
    this.init = function () {

        if (window.XMLHttpRequest)
        {
            this.xhr = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }

        this.xhr.onreadystatechange = function () {

            if(this.readyState == 4) {
            
                if(this.status == 200) { objectTracker.tracking.loadObject.doLoad(); }
                else window.console.log("Loader: Loader Error code " + this.status);
            }
        }
    }

    this.load = function () {
        this.loadGet(this.url, this.params, this.caller);
    }
    
    this.loadPost = function (file, params, caller) {
    
        this.caller = caller;
        
        this.caller.notify("Processing...");
        

	this.xhr.open('POST', file, false);
        this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        this.xhr.setRequestHeader("Content-length", this.formatParams(params).length);
        this.xhr.setRequestHeader("Connection", "close");
        
        this.xhr.send(this.formatParams(params));
		
	
    }
        
        
        
    this.loadGet = function (file, params, caller) {
	
        
        
       
	filestring = file + "?" + this.formatParams(params);
	this.caller.notify(filestring);
       
	this.xhr.open('GET', filestring, true);
	this.xhr.send(null);
	
	
    }
    
    this.formatParams = function (array) {
        var result = "";
        var x = 0;
        
        for (key in array) {
            if (x != 0) result += "&";
            
            result += key + "=" + array[key];
            
            x++;
        }
        
        
        return result;
    }
    
    
    this.doLoad = function () {
        
        if (this.xhr.responseText != '') {
            
            var paramsArray = Array();
            paramsArray = eval("(" + this.xhr.responseText + ")");
            this.caller.onSuccess(paramsArray);
        }
	else alert("Error loading");
        
	

	
    }

}