/*
    Dynamic Links "you're on this page" highlight thingy.
    Geordan Rosario, Media Net Link, Inc. (geordanr@mnl.com)
    Don't be a hoser.

    $Id: dynamic-links.js,v 1.1.1.1 2005/11/21 22:27:56 bradd Exp $

    USAGE:

    In the include file:

	    // === EXAMPLE FILE content-nav.js ===
	    // 
	    // Tokens of the form
	    // 
	    //	    __class:token_name:__
	    // 
	    // will be substituted out with the class specified by
	    // set_selected_class() if the named token is the argument
	    // to select_link(); otherwise it is replaced with the class 
	    // specified by set_default_class().
	    //
	    // Tokens of the form
	    // 
	    //	    __img:token_name.jpg:__
	    // 
	    // will be substituted with "token_name-ov.jpg" if
	    // appropriate, and "token_name.jpg" otherwise.  The image
	    // extensions .jpg, .gif, and .png are supported.
	    // 
	    // The colon (':') character is not allowed in token_name or
	    // token_name.jpg.

	    var incltext = '<td class="__class:link1:__">'      +
			   '	<img src="__img:link1.jpg:__">' +
			   '</td>'                              +
	    		   '<td class="__class:link2:__">'      +
			   '	<img src="__img:link2.jpg:__">' +
			   '</td>';

    In the main HTML file:

	<!-- 
	    Declare the incltext variable with contents set to
	    the include file stuff.
	-->
	<script src="content-nav.js"></script>

	<!-- Load up the navbar generating script... -->
	<script src="dynamic-links.js></script>
	<script>
	    // Specify the classes for selected and default stuff...
	    set_selected_class("selected");
	    set_default_class("unselected");

	    // Specify which link is selected.
	    select_link("link2");

	    // ...and write out the navbar.
	    write_include_file();
	</script>

*/

var selclass;
var defclass;
var sellink;

function set_selected_class(c) {
    selclass = c;
}

function set_default_class(c) {
    defclass = c;
}

function select_link(link) {
    sellink = link;
}

// Maybe this should be inline
function choose_class(link) {
    return link==sellink?selclass:defclass;
}

// And this too
function choose_image(link,ext) {
    return link + (link==sellink?'-ov':'') + '.' + ext;
}

function write_include_file() {
    var out = incltext;

    // Replace the classes:
    var re = /__class:([^:]+):__/i;
    while (out.search(re) >= 0) {
	out = out.replace(re, choose_class(RegExp.$1));
    }

    // Replace the images:
    var re = /__img:([^:]+)\.(jpg|gif|png):__/i;
    while (out.search(re) >= 0) {
	out = out.replace(re, choose_image(RegExp.$1,RegExp.$2));
    }

    document.write(out);
}
