var bookmarks = function()
{
	var lasthash = '';
	var bookmarked = new Array();
	return {
	initialize:function()
        {
            setInterval("bookmarks.checkhash();", 400);
            //setInterval("bookmarks.debug();", 4000);
        },
        sethash:function(hash,func)
        {
            if(lasthash != hash)
            {
                lasthash = hash;
                window.location.hash = hash;
                bookmarked[hash] = func;
            }
        },
        checkhash:function()
        {
	    var obj = window.location.hash;
	    if(obj)
            {
                if(obj!=lasthash)
                {
                    if(lasthash!=undefined)
                    {
	                lasthash = obj;
                        setTimeout(bookmarked[obj], 1);
                    }
	        }
            }
        },
        print_r:function(arr, level)
        {
            var print_red_text = "";
            if(!level) level = 0;
            var level_padding = "";
            for(var j=0; j<level+1; j++) level_padding += "    ";
            if(typeof(arr) == 'object')
            {
                for(var item in arr)
                {
                   var value = arr[item];
                   if(typeof(value) == 'object')
                   {
                      print_red_text += level_padding + "'" + item + "' :\n";
                      print_red_text += print_r(value,level+1);
		   } 
                   else print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
                }
            } 
            else  print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
            return print_red_text;
        },
        debug:function()
        {
            alert(bookmarks.print_r(bookmarked));
            alert(lasthash);
        }
    }
}();
