
/* Author: Roy Ronalds


*/




// Debugging functions.


function simple_var_dump(obj) {
		
	try { 
		console.log('simple_var_dump: ', obj);
	} catch(e) { 
		alert("You don't have Firebug enabled!");
		dump = ''; 
		if(typeof obj == "object") {
			dump += "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
		} else {
		    dump += "Type: "+typeof(obj)+"\nValue: "+obj;
		}
		alert(dump);
	}
	
	/*Simple array:
	var myVar = { 
	    key1 : 'value1', 
	    key2 : 'value2', 
	    key3 : ['a', 'b', 'c'] 
	}; */ 
}//end function var_dump


/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}



/**
 * Concatenates the values of a variable into an easily readable string
 * by Matt Hackett [scriptnode.com]
 * @param {Object} x The variable to debug
 * @param {Number} max The maximum number of recursions allowed (keep low, around 5 for HTML elements to prevent errors) [default: 10]
 * @param {String} sep The separator to use between [default: a single space ' ']
 * @param {Number} l The current level deep (amount of recursion). Do not use this parameter: it's for the function's own use
 */
function print_r(x, max, sep, l) {

	l = l || 0;
	max = max || 10;
	sep = sep || ' ';

	if (l > max) {
		return "[WARNING: Too much recursion]\n";
	}

	var
		i,
		r = '',
		t = typeof x,
		tab = '';

	if (x === null) {
		r += "(null)\n";
	} else if (t == 'object') {

		l++;

		for (i = 0; i < l; i++) {
			tab += sep;
		}

		if (x && x.length) {
			t = 'array';
		}

		r += '(' + t + ") :\n";

		for (i in x) {
			try {
				r += tab + '[' + i + '] : ' + print_r(x[i], max, sep, (l + 1));
			} catch(e) {
				return "[ERROR: " + e + "]\n";
			}
		}

	} else {

		if (t == 'string') {
			if (x == '') {
				x = '(empty)';
			}
		}

		r += '(' + t + ') ' + x + "\n";

	}

	return r;

};
var_dump = simple_var_dump; // Alias for another debugging function.

/*
Not yet needed
function repositoryLoad() {
    var limit = 20        // how many repos to list
    var login = 'tchalvak' // your username

    $.getJSON('http://github.com/api/v1/json/' + login + '?callback=?', function(data) {
        var repos = $.grep(data.user.repositories, function() {
        return !this.fork
        })
        


        repos.sort(function(a, b) {
        return b.watchers - a.watchers
        })

        $.each(repos.slice(0, limit), function() {
        $('#repos').append('<li><a href="' + this.url + '">' + this.name + '</a></li>')
        })
    })

	$("#waiting").hide(); // Hide the not yet loaded message.
	
	
} // End of repositoryLoad function.

function loadLastCommitMessage(){
var login = 'tchalvak' // your username
        
    $.getJSON('http://github.com/api/v1/json/' + login + '/ninjawars/commit/master/?callback=?', function(data) {
    var unknown = $.grep(data.commit, function() {
        return true;
    })
    
        // Load latest commit message.
	$('#latest-commit').html(data.commit.message);
	$('#latest-commit').append("<div id='commit-author'>--"+data.commit.author.name+"</div>");
	$('#latest-commit-title').show();        
	$('#latest-commit').show();
    
    });
    
}        
*/

