
function imageLink(image, alt, onClick, url)
{
	document.write("<li>");
	document.write("<a ");
	document.write("title=\"" + alt + "\" ");
	document.write("onClick=\"" + onClick + "\" ");
	document.write("href=\"" + url + "\">"); 
	document.write("<img src=\"" + image + "\" />");
	document.write("</a></li>\n");
}

function entry(tag, text, ext)
{
    if (ext == undefined)
    {
        ext = "html";
    }
    
	document.write("<li>");
	document.write("<a id=\"" + tag + "_a\" ");
	document.write("title=\"" + text + "\" ");
	document.write("onClick=\"navigate('" + tag + "', '" + ext + "'); return false;\" ");
	document.write("href=\"#\">"); 
	document.write("<img src=\"thumbnails/" + tag + ".png\" />");
	document.write("</a></li>\n");
}

var current_expanded = undefined;
function global_toggle(toggle_id) 
{
	if (current_expanded != undefined) 
	{
		current_expanded.hide('fast', function() {});
		current_expanded = undefined;
	}
	
	to_expand = $('#' + toggle_id);
    if (to_expand != current_expanded)
	{
		current_expanded = to_expand;
		current_expanded.show('fast', function() {});
    }
}

function sleep(milliseconds)
{
    var date = new Date();
    var curDate = null;
    
    do
    {
        curDate = new Date();
    }
    while (curDate - date < milliseconds);
}

function loadPageAJAX(url, containerid)
{
    var do_cache_killer = 1;

    cache_killer = '';
    if (do_cache_killer > 0)
    {
        cache_killer = (url.indexOf('?') < 0 ? '?' : '&') + new Date().getTime();
    }
    
    var element = $('#' + containerid);
    
    $('#loadingbar').show();
    
    element.fadeOut(200, function() 
        { 
            element.load(url + cache_killer, function() 
                {
                    // Emulate a slow connection for testing purposes
                    //sleep(800);
                    
                    $('#loadingbar').hide();
                    element.fadeIn(200);
                });
        });
}

function navigate(tag, ext)
{
    loadPageAJAX(tag + '.' + ext, 'content_window');
    //global_toggle(tag);
}
