function splitString(theString, theSeparator)
{
	var retval = new Array();
	a = theString.indexOf(theSeparator);
	var i = 0;
	while (a != -1) {
		retval[i++] = theString.substring(0, a);
		theString = theString.substring(a + 1, theString.length);
		a = theString.indexOf(theSeparator);
	}
	retval[i] = theString;
	return retval;
}

function writeSectionTab(linkTo, aname, adesc)
{
	if (
		(aname == "home" && 
			(
			loclist[sectidx].toLowerCase() == "www.giancarlobagnulo.com" 
			|| 
			loclist[sectidx].toLowerCase() == "main.php")
			)
		||
		(loclist[sectidx] == aname)
	) {
		document.write('<td><center>');
		document.write('<img class="noborder" src="' + baseurl + 'img/' + aname + '_lite.gif" name="' + aname + '"/>');
		document.write('</center></td>');
	}
	else {
		document.write('<td><center>');
		document.write('<a href="' + baseurl + linkTo + '"> ');
		document.write('<img class="noborder" border="0" ');
		document.write('src="' + baseurl + 'img/' + aname + '.gif"/>');
		document.write('</a></center></td>');
		document.write('</center></td>');
	}
}

var loclist = splitString(document.location.href, "/");
var innerval = 0;
var baseurl = "";
var sectidx = loclist.length - 2;
for (var i = loclist.length - 2; i > 0; i--) {
	if (loclist[i].toLowerCase() == "www.giancarlobagnulo.com") break;
	baseurl = baseurl + "../";
	sectidx--;
}
sectidx++;

document.write('<center>');
var imgindex = Math.floor(Math.random() * 5)+1;
document.write('<img style="background: white; border: 1px solid black" src="' + baseurl + 'img/title-' + imgindex + '.jpg"/>');
document.write('<a href="' + baseurl + 'main.php">');
document.write('<img class="noborder" src="' + baseurl + 'title.jpg"/>');
document.write('</a>');
imgindex = Math.floor(Math.random() * 5)+1;
document.write('<img style="background: white; border: 1px solid black" src="' + baseurl + 'img/title-' + imgindex + '.jpg"/>');

document.write('<br/>');

document.write('<table border="0" cellspacing="10" width="100%"><tr>');
writeSectionTab("main.php", "home", "Homepage");
writeSectionTab("jujitsu/index.html", "jujitsu", "Il Ju-Jitsu");
writeSectionTab("didattica/index.html", "didattica", "Didattica");
writeSectionTab("attivita/index.html", "attivita", "Attivitā");
writeSectionTab("dojo/index.html", "dojo", "Dojo e Palestre");
writeSectionTab("gallery/index.php", "photogallery", "Galleria Fotografica");
writeSectionTab("links/index.html", "links", "Links");
document.write('</tr></table>');


document.write('<table border="0" cellspacing="10" width="100%">');
document.write('<tr><td class="navigation" width="150" valign="top" style="text-align: left; background-repeat: no-repeat; background-attachment: fixed; background-image: url(' + baseurl + 'img/bamboo.jpg)">');

function menuItem(alt, page)
{
	document.write('<a href="' + page + '">');
    document.write('<div class="menuItem">' + alt + '</div>');
	document.write('</a>');
}

var onlyThumbnails = false;

function showOnlyThumbnails()
{
    document.write('<center><b>Attenzione, in questa pagina le immagini sono disponibili soltanto ');
    document.write('sotto forma di miniature, cliccandovi sopra non č possibile visualizzare l\'immagine ');
    document.write('ingrandita: se si č interessati alla visione delle immagini a grandezza naturale, ');
    document.write('contattare il M° Bagnulo.');
    onlyThumbnails = true;
}

function thumbnail(path, imagename, caption)
{
	document.write('<center><a href="' + path + '/' + imagename + '">');
	document.write('<img src="' + path + '/t_' + imagename + '" border="0"/>');
	document.write('</a><br/>' + caption + '</center>');
}

function thumbnailn(path, imagename, caption)
{
	document.write('<center>');
	document.write('<img src="' + path + '/t_' + imagename + '" border="0"/>');
	document.write('<br/>' + caption + '</center>');
}

var thumbcount = 0;
var thumbsperrow = 3;

function thumbtd(folder, imgname, desc)
{
    if (onlyThumbnails == true) thumbtdn(folder, imgname, desc);
    else {
        if (thumbcount > 0 && thumbcount % thumbsperrow == 0) {
            document.write('</tr><tr>');
        }
        document.write('<td>');
        thumbnail(folder, imgname, desc);
        document.write('</td>');
        thumbcount++;
    }
}

function thumbtdn(folder, imgname, desc)
{
	if (thumbcount > 0 && thumbcount % thumbsperrow == 0) {
		document.write('</tr><tr>');
	}
	document.write('<td>');
	thumbnailn(folder, imgname, desc);
	document.write('</td>');
	thumbcount++;
}

function thumbtitle(title)
{
    startthumbs(3);
    document.write('<br/><center><p><b>' + title + '</b></p></center>');
    document.write('<table class="photos">');
}

function startthumbs(tpr)
{
	thumbsperrow = tpr;
	thumbcount = 0;
}
