// JavaScript for Petr Vojtechovsky Homepage
// (c) Petr Vojtechovsky 2008

// spam-proof email address display

function email( address ) {
	var plainChars =    "abcdefghijklmnopqrstuvwxyz0123456789.@-";
	var cipheredChars = "bcdefghijklmnopqrstuvwxyza1234567890*!-";
	
	var s = "";
	for (var i=0; i<address.length; i++) {
		s += plainChars.charAt( cipheredChars.indexOf( address.charAt( i ) ) );
	}
	document.write("<a href='mailto:" + s + "'>" + s + "</a>");
}

// menu tree structure

var menu = new Array();

function addItem( parent, item, description, itemType, iconType, path ) {
// adds a new item <item> with description <description> to the menu so that it is a child of <parent>
    var n = menu.length;
    menu[ n ] = new Array;
    menu[ n ][ 0 ] = parent;
    menu[ n ][ 1 ] = item;
    menu[ n ][ 2 ] = description;
    menu[ n ][ 3 ] = itemType;
    menu[ n ][ 4 ] = iconType;
    menu[ n ][ 5 ] = path;
    return true;
}

// auxiliary functions for menu traversing

function getParent( item ) {
// finds the parent of <item>
    for( var i=0; i<menu.length; i++ ) {
        if ( menu[ i ][ 1 ] == item ) {
            return menu[ i ][ 0 ];
        }
    }
    return false; // parent not found
}

function hasChildren( item ) {
// returns true if <item> has children
    for( var i=0; i<menu.length; i++ ) {
        if ( menu[ i ][ 0 ] == item ) {
            return true;
        }
    }
    return false;
}

// displaying the menu

function sanitizedPath( path ) {
// sanitizes path (no upper case letters, replace spaces and '-' with underscores, deletes apostrophes and commas)
	path = path.toLowerCase();
	path = path.replace(/ /g, "_");
	path = path.replace(/-/g, "_");
	path = path.replace(/,/g, "");
	path = path.replace(/'/g, "");
	return path;	
}

function addPath( i ) {
// displays path to menu[ i ]
// the path is calculated depending on the type of link

	var s = "";
	var path = sanitizedPath( menu[ i ][ 1 ] );
	if ( menu[ i ][ 3 ] == "" ) { s += path + ".html"; }
	if ( menu[ i ][ 3 ] == "restricted" ) { s += "restricted/" + path + "/index.html"; } 
	if ( menu[ i ][ 3 ] == "direct" ) { s += menu[ i ][ 5 ]; }
	if ( menu[ i ][ 3 ] == "photo" ) { s += "photographs/" + path +"/index.html"; }
	return s;
}

function addIcon( i ) {
// icons assigned to menu links depend on the type of link
	var s = "";
	if ( menu[ i ][ 3 ] == "" ) { // default link
        	if ( hasChildren( menu[ i ][ 1 ] ) ) { s += "folder"; }
                else { s += "page"; }                 
        } 
	if ( menu[ i ][ 3 ] == "restricted" ) { s += "restricted"; }
	if ( menu[ i ][ 3 ] == "direct" ) { s += menu[ i ][ 4 ]; }
	if ( menu[ i ][ 3 ] == "photo" ) { s += "photo"; }
	return s+".png";
}

function addSubmenuLink( i ) {
// adds an entire menu link (icon + page name ) but not the tagline
	var s =  "<tr valign=top><td align=right><a href='";
	s += addPath( i );
	s += "'><img src='icons/";
	s += addIcon( i );
        s += "'/></a></td><td><a href='";
	s += addPath( i );
	s += "'>" + menu[ i ][ 1 ] + "</a>";
	return s;
}

// display header, branch menu, tagline, and menu

function displayMenu( item, pathOffset ) {
// displays submenu rooted at <item>
    if (pathOffset == undefined) { 
	   pathOffset = "";
    }
    // display children of <item> if <item> is not a leaf
    if ( hasChildren( item ) ) {
        var s = "<table class='submenu' width=100%>";
        for ( var i=0; i<menu.length; i++ ) {
            if ( menu[ i ][ 0 ] == item ) {
                s += addSubmenuLink( i );
                s += "<br/>" + menu[ i ][ 2 ] + "</td></tr>";
            }
        }
        s += "</table>";
        document.write( s );
    }    
}

function displayBranchAndTagline( item, pathOffset ) {
// displays branch of the menu leading to <item>
// <pathOffset> is used for webpages not in the same directory as this script

    // locating item
    var itemIndex = 0;
    for ( var i=0; i<menu.length; i++ ) {
	   if ( menu[ i ][ 1 ] == item ) {
	       itemIndex = i;
	   }
    }

    // calculating and displaying the branch leading to <item>
    var currentItem = item;
    document.write( "<img src='" + pathOffset + "icons/dot.gif' width=100% height=1/><br/>" );
    var s="";
    do {
        if ( currentItem == item ) { // no hyperlink
            s = "<span class='section'>" + currentItem + "</span>";
        } else { // hyperlink 
            var s2 = "<span class='menu'><a href = '" + pathOffset;
            if ( currentItem == "Home" ) { // redirect path to "index"
                s2 += "index";
            } else {
                s2 += sanitizedPath( currentItem );
            }
            s2 += ".html'>" + currentItem + "</a></span>";
            s2 += " &nbsp;&nbsp;<img src='" + pathOffset +  "icons/arrow.png'/>&nbsp;&nbsp; ";
            s = s2 + s;
        }
        currentItem = getParent( currentItem );
    } while  ( currentItem != false );       
    s = "&nbsp;<img src='" + pathOffset + "icons/arrow.png'/>&nbsp;&nbsp; " + s;
    document.write( s );
    document.write( "<br/><img src='" + pathOffset + "icons/dot.gif' width=100% height=1/><br/><br/>" );
    
    // display tagline
    if ( item != "Home" ) {
	   document.write( "<span class='tagline'>" + menu[ itemIndex ][ 2 ] + "</span><br/><br/>" );
    }       
}
    
function displayHeader( item, pathOffset ) {
    if (pathOffset == undefined) { 
	   pathOffset = "";
    }
    var s = "";
    s += "<table width=100% cellpadding=0 cellspacing=0><tr valign='bottom'>";
    // title
    s += "<td id='title'>Petr Vojt&#283;chovsk&#253;</td>";
    // address
    s += "<td width=200></td>";
    s += "<td class='address' align='right'>John Greene Hall 214<br/>2360 S Gaylord St<br/>Denver, Colorado 80208</td>";
    s += "<td width=20></td>";
    s += "<td class='address' align='right'>001 303 871 3314<br/>petr at math.du.edu<br/>www.math.du.edu/~petr</td>";
    s += "</tr><tr height=8></tr><td colspan=5></td></tr></table>";
    document.write( s );
    
    displayBranchAndTagline( item, pathOffset );
}

function displayHeaderAndMenu( item, pathOffset ) {
    displayHeader( item, pathOffset );
    displayMenu( item, pathOffset );
}

// display site map

function displaySiteMap() { 
	var s = "<table class='submenu'>";
	for ( var i=0; i<menu.length; i++ ) {		
		if ( !hasChildren( menu[ i ][ 1 ] ) ) { // content page
			s += addSubmenuLink( i );			
            s += "</td><td>" + menu[ i ][ 2 ] + "</td></tr>";
		}
	}
	s += "</table>";
	document.write( s );
}

// defining the menu

addItem( "Home",    "Curriculum vitae", "My resume.", "direct", "pdf", "data/online_cv.pdf" );
addItem( "Home",    "Site map", "Navigation info and direct links to all pages.", "", "", "" );
addItem( "Home",    "Research", "Publications, software and research related activities.", "", "", "" );
addItem( 	        "Research", "Research areas", "A short description of research areas I like.", "", "", "" );
addItem(            "Research", "Publications", "All my mathematical publications and preprints.", "", "", "" );
addItem(                        "Publications", "In research journals", "Papers that appeared or will appear in research journals, excluding conference proceedings.", "", "", "")
addItem(                        "Publications", "In conference proceedings", "Papers that appeared or will appear in refereed conference proceedings.", "", "", "");
addItem(                        "Publications", "Submitted", "All currently submitted papers.", "", "", "");
addItem(                        "Publications", "In preparation", "List of manuscripts in preparation and some preprints.", "", "", "");
addItem(                        "Publications", "Theses", "My M.S. and Ph.D. theses.", "", "", "");
addItem(                        "Publications", "Trifles", "Small and sometimes mildly entertaining mathematical works not intended for publication.", "", "", "" );
addItem(                  	"Publications", "TeX source files", "TeX source files of all my papers.", "restricted", "", "" );
addItem(            "Research", "Computing", "Computational packages and developed software.", "", "", "" );
addItem(                  	"Computing", "LOOPS package", "The LOOPS package for GAP (with Gabor P. Nagy).", "direct", "external", "http://www.math.du.edu/loops" );
addItem(                  	"Computing", "Cryptographer's toolkit", "A web-based resource for teaching introductory cryptography.", "direct", "external", "http://www.math.du.edu/data/online_resources/cryptographers_toolkit/cryptographers_toolkit.html" );
addItem(                        "Computing", "GAP routines", "Routines for GAP.", "", "", "");
addItem(                        "Computing", "WinGroup", "The program WinGroup.", "", "", "");
addItem(            "Research", "Talks", "Mathematical talks I delivered at conferences, workshops and seminars.", "", "", "" );
addItem(                        "Talks", "Conference talks", "Talks delivered at mathematical conferences.", "", "", "" );
addItem(                        "Talks", "Seminar talks", "Seminar talks delivered at universities around the world (mostly in Colorado and Central Europe).", "", "", "" );
addItem(                        "Talks", "Local talks", "Talks given at local (DU) seminars.", "", "", "" );
addItem(            "Research", "Meetings", "A complete list of conferences and workshops I attended.", "", "", "" );
addItem(            "Research", "Mathematicians", "List of mathematicians I am in occasional contact with.", "", "", "");
addItem(            "Research", "Journals", "List of mathematical journals in my sphere of interest.", "", "", "");
addItem(      	    "Research", "Citations", "An attempt to collect citations about my work.", "restricted", "", "" );
addItem( "Home",    "Teaching", "Current courses, PhD students, coursed taught, and teaching resources.", "", "", "" );
addItem(            "Teaching", "Calculus I", "Web page for MATH 1951 Calculus I.", "", "", "");
addItem(            "Teaching", "Calculus III", "Web page for MATH 1953 Calculus III.", "", "", "");
addItem(            "Teaching", "Cryptography", "Web page for MATC 1150 Cryptography.", "", "", "");
addItem(            "Teaching", "PhD students", "My PhD students.", "", "", "");
addItem(            "Teaching", "Previous teaching", "Classes I taught in the past.", "", "", "" );
addItem(	        "Teaching", "Teaching resources", "Lecture notes, databases, projects, etc.", "direct", "restricted", "restricted/teaching_resources" );
addItem( "Home",    "Personal", "Items not related to my research and teaching.", "", "", "" );
addItem(            "Personal", "Photographs", "Collections of photographs taken around the world.", "", "", "");
addItem(	    		"Photographs", "Tenmile-Mosquito Range", "Two hikes into Tenmile-Mosquito Range in Colorado (July 2007).", "photo", "", "" );
addItem(	    		"Photographs", "El Salvador and Guatemala", "Two week vacation in El Salvador and Guatemala (December 2006).", "photo", "", "" );
addItem(	    		"Photographs", "Mt Falcon Park in Jefferson County", "A September hike in Mt Falcon Park (September 2006).", "photo", "", "" );
addItem(	    		"Photographs", "Longs Peak", "Climbing Longs Peak via Keyhole Route with David and Jeronym (July 2006).", "photo", "", "" );
addItem(	    		"Photographs", "Barr Lake, Waterton Canyon and Roxborough", "Day hikes near Denver (October 2005 - March 2006", "photo", "", "" );
addItem(	    		"Photographs", "Mt Evans Wilderness", "Hiking trip with Ales Drapal. Mt Evans Wilderness, Meridian Pass, Roosevelt Lake, Abyss Lake (June 2005).", "photo", "", "" );
addItem(	    		"Photographs", "Wildlife in Rocky Mountain NP", "A day trip to Rocky Mountain NP during elk season (2004).", "photo", "", "" );
addItem(	    		"Photographs", "Castlewood Canyon State Park", "Hiking in Castlewood Canyon near Franktown (September 2004)", "photo", "", "" );
addItem(	    		"Photographs", "Wedding", "Wedding in Buchlovice (June 2004)", "restricted", "", "" );
addItem(	    		"Photographs", "Hiking in Colorado", "Around St Mary's glacier, in Rocky Mountains National Park (Fall 2003).", "photo", "", "" );
addItem(	    		"Photographs", "Our House", "House, yard, trees, some interior (2003).", "restricted", "", "" );
addItem(	    		"Photographs", "Western USA Trip", "Denver, Rocky Mountains national park, Great Sand Dunes, Mesa Verde, Hovenweep, Natural Bridges, Monument Valley, Zion, Las Vegas, Joshua Tree, Pacific coast, Bryce Canyon, Arches (Summer 2003).", "photo", "", "" );
addItem(	    		"Photographs", "Denver Blizzard", "Englewood, Denver (March 2003).", "photo", "", "" );
addItem(	    		"Photographs", "Croatia", "St Filip i Jakov, Kornati Islands, Adriatic Sea, Silver Lake, Plitvicka n.p. (August 2002).", "photo", "", "" );
addItem(	    		"Photographs", "Czech Republic", "Jeseniky Mountains, Stramberk, Roznov, Jestrabice, Kromeriz, Buchlovice, Brno, Mysliborice, Prague (August 2002).", "photo", "", "" );
addItem(	    		"Photographs", "San Diego and San Diego Zoo", "San Diego Bay, Zoo fauna, Zoo flora (January 2002).", "photo", "", "" );
addItem(	    		"Photographs", "Brushy Creek State Park", "Bike trip in Brushy Creek, Iowa, puffballs (Fall 2001)", "photo", "", "" );
addItem(	    		"Photographs", "London and Oxford", "Greenwich, Tower bridge, Parliament, Millenium Eye, The Monument, Christ's College, London (Summer 2001).", "photo", "", "" );
addItem(	    		"Photographs", "Central Mexico", "Mexico City, Morelia, Taxco, Popocatepetl, Teotihuacan (Summer 2001).", "photo", "", "" );
addItem(	    		"Photographs", "Czech Republic and Austria", "    Prague, Konopiste, Kutna Hora, Hluboka, Cesky Krumlov, Zelena Hora, Jeseniky Mountains, Chriby Mountains, Buchlov, rock Kozel, Vienna (Winter 2000).", "photo", "", "" );
addItem(	    		"Photographs", "USA Trip", "    Voyagers national park, North Dakota, Roosevelt n.p., Yellowstone n.p., Grand Teton n.p., Glaciers n.p., Northern Cascades n.p., Seattle, Mt Rainier n.p., Crater Lake n.p., Redwoods n.p., San Francisco, Los Angeles, Sequoia n.p., Mt St Helens, Death Valley, Nevada, Grand Canyon n.p. (Summer 2000).", "photo", "", "" );
addItem(	    		"Photographs", "Bohemian and Moravian Mountains", "Chriby Mountains, Vysocina Mountains, rock Kozel, Kremesnik Mt (Winter 1999).", "photo", "", "" );
addItem(	    		"Photographs", "Southern Moravia", "Lednice, Palava, Divci Hrady, Jestrabice, Brno (Winter 1998).", "photo", "", "" );
addItem(            "Personal", "Family tree builder", "A JavaScript application for building and publishing online family trees.", "", "", "");
addItem(            "Personal", "Skyscrapers", "Links to skyscraper resources.", "", "", "" );
addItem( 	    "Personal", "Family trees", "The Vojtechovsky and Topinka family trees.", "restricted", "", "" );
