var GLSpace = 10; //necessary space that must appear between my side-links and the ad
var GLWide = 125; //ad width
var GLHi = 125; //ad height

function ShowSide(code) {
	if (code=="x") {
		var mainLoc = parent.main.location.href;
		if ((mainLoc.indexOf(".intro.html") != -1) || (mainLoc.indexOf(".itinerary.html") != -1) || (mainLoc.indexOf(".pictures.html") != -1)) {
			code=mainLoc.slice(mainLoc.lastIndexOf("/"),mainLoc.lastIndexOf("."));
			code=code.slice(1,code.lastIndexOf("."));
		}
//		if (mainLoc.indexOf(".intro.html") != -1) code=mainLoc.substr(mainLoc.indexOf(".intro.html")-4,4);
//		else if (mainLoc.indexOf(".itinerary.html") != -1) code=mainLoc.substr(mainLoc.indexOf(".itinerary.html")-4,4);
//		else if (mainLoc.indexOf(".pictures.html") != -1) code=mainLoc.substr(mainLoc.indexOf(".pictures.html")-4,4);
	}
	i=0;

	do {
		//alert(code);
		if (tour[i].tourCode == "t11p") document.writeln("<br clear=left><a href='side.html' onClick='top.main.location="+unescape("%22")+"tours.html#t11p"+unescape("%22")+";' class='divider' title='Jump to Pacific region October to December 2010 tours'>PACIFIC 2010</a>");
		else if (tour[i].tourCode == "t11y") document.writeln("<br clear=left><a href='side.html' onClick='top.main.location="+unescape("%22")+"tours.html#t11y"+unescape("%22")+";' class='divider' title='Jump to Yucatan January to February 2011 tours'>YUCATAN 2011</a>");
		else if (tour[i].tourCode == "t11o") document.writeln("<br clear=left><a href='side.html' onClick='top.main.location="+unescape("%22")+"tours.html#t11o"+unescape("%22")+";' class='divider' title='Jump to Oaxaca February 2011 tours'>OAXACA 2011</a>");

		else if (tour[i].tourCode == code) {
			document.writeln("<br clear=left><br>");
			document.writeln("<span class='title'>"+tour[i].tourNameLong+"</span><br>");
			document.writeln("<a href='"+tour[i].tourCode+".intro.html' target='main'><div class='indent' title='Route map, distances, dates, highlights.'>Introduction</div></a>");
			document.writeln("<a href='"+tour[i].tourCode+".itinerary.html' target='main' title='Full day to day tour itinerary'><div class='indent'>Itinerary</div></a>");
			document.writeln("<a href='"+tour[i].tourCode+".pictures.html' target='main' title='The sights you&#39;ll see along this route'><div class='indent'>Photo Album</div></a>");
		}

		else if (tour[i].spaceLeft==-99) document.writeln("<br><a href='side.html' onclick='mw("+unescape("%22")+i+unescape("%22")+","+unescape("%22")+code+unescape("%22")+");' title='This tour has&#10;been completed'>"+tour[i].tourNameShort+"</a>");
		else if (tour[i].spaceLeft==-999) document.writeln("<br><a href='side.html' onclick='mw("+unescape("%22")+i+unescape("%22")+","+unescape("%22")+code+unescape("%22")+");' title='This tour is&#10;in progress'>"+tour[i].tourNameShort+"</a>");
		else if (tour[i].spaceLeft==-9999) document.writeln("<br><a href='side.html' onclick='top.main.location="+unescape("%22")+"tours.html#"+tour[i].tourCode+unescape("%22")+";' title='"+tour[i].tourSummary+"Tentative start: "+tour[i].startDate+"&#10;'>"+tour[i].tourNameShort+"</a>");
		else document.writeln("<br><a href='side.html' onclick='mw("+unescape("%22")+i+unescape("%22")+","+unescape("%22")+code+unescape("%22")+");' title='"+tour[i].tourSummary+"Starts on "+tour[i].startDate+"&#10; and there are "+tour[i].spaceLeft+" spaces left'>"+tour[i].tourNameShort+"</a>");
	}
	while (++i<tour.length);
	document.writeln("</p>");

	document.writeln("<p>");
	if (code == "x") {
		document.writeln("<a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"costs.html"+unescape("%22")+";' title='Cost &amp; Registration &amp; Payment &amp; Info-Packs'>Cost &amp; Registration</a>");
		document.writeln("<br><a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"pictures.html"+unescape("%22")+";' title='Pictures of Mexico &amp; an archive of past tour pictures'>Pictures</a>");
		document.writeln("| <a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"movies.html"+unescape("%22")+";' title='Short movie clips'>Movie Clips</a>");
		document.writeln("<br><a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"reviews.html"+unescape("%22")+";' title='See what our clients have to say'>Feedback &amp; Reviews</a>");
		document.writeln("<br><a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"faq.html"+unescape("%22")+";' title='Frequently Asked Questions'>FAQ</a>");
		document.writeln("| <a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"links.html"+unescape("%22")+";' title='links...links...links...'>Links</a>");
		document.writeln("| <a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"search.html"+unescape("%22")+";' title='Search BikeMexico.com or the web'>Search</a>");
		document.writeln("<br><a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"travelogues.html"+unescape("%22")+";' title='Trip reports, travelogues, articles'>Trip Reports &amp; Articles</a>");
		document.writeln("<br><a href='javascript:void(0)' onClick='top.main.location="+unescape("%22")+"about_us.html"+unescape("%22")+";' title='Get to know your guides'>About Us</a>");
		document.writeln("| <a href='http://www.facebook.com/bikemexico' target='facebook' title='Our Facebook Fan Page'>Facebook</a>");
	}
	else {
		document.writeln("<a href='side.html' onClick='top.main.location="+unescape("%22")+"costs.html"+unescape("%22")+";' title='Cost &amp; Registration &amp; Payment &amp; Info-Packs'>Cost &amp; Registration</a>");
		document.writeln("<br><a href='side.html' onClick='top.main.location="+unescape("%22")+"pictures.html"+unescape("%22")+";' title='Pictures of Mexico &amp; an archive of past tour pictures'>Pictures</a>");
		document.writeln("| <a href='side.html' onClick='top.main.location="+unescape("%22")+"movies.html"+unescape("%22")+";' title='Short movie clips'>Movie Clips</a>");
		document.writeln("<br><a href='side.html' onClick='top.main.location="+unescape("%22")+"reviews.html"+unescape("%22")+";' title='See what our clients have to say'>Feedback &amp; Reviews</a>");
		document.writeln("<br><a href='side.html' onClick='top.main.location="+unescape("%22")+"faq.html"+unescape("%22")+";' title='Frequently Asked Questions'>FAQ</a>");
		document.writeln("| <a href='side.html' onClick='top.main.location="+unescape("%22")+"links.html"+unescape("%22")+";' title='links...links...links...'>Links</a>");
		document.writeln("| <a href='side.html' onClick='top.main.location="+unescape("%22")+"search.html"+unescape("%22")+";' title='Search BikeMexico.com or the web'>Search</a>");
		document.writeln("<br><a href='side.html' onClick='top.main.location="+unescape("%22")+"travelogues.html"+unescape("%22")+";' title='Trip reports, travelogues, articles'>Trip Reports &amp; Articles</a>");
		document.writeln("<br><a href='side.html' onClick='top.main.location="+unescape("%22")+"about_us.html"+unescape("%22")+";' title='Get to know your guides'>About Us</a>");
		document.writeln("| <a href='http://www.facebook.com/bikemexico' target='facebook' title='Our Facebook Fan Page'>Facebook</a>");
	}
}

function displayAd() {
	//to display an ad or not?
	if (getWindowHeight() >= (document.getElementById('main').offsetHeight+GLSpace+GLHi)) {
		document.getElementById("sideAdDiv").style.display = "block";
	}
	if (document.body.clientWidth!=125 && document.body.clientWidth!=0) ResizeSide();
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number')
		windowHeight = window.innerHeight;
	else {
		if (document.documentElement && document.documentElement.clientHeight)
			windowHeight = document.documentElement.clientHeight;
		else {
			if (document.body && document.body.clientHeight)
				windowHeight = document.body.clientHeight;
		}
	}
	return windowHeight;
}

function mw(i,code) {
	mwss = "intro";
	if (code != "x") {
		mwh = top.main.location.href;
		mwss = mwh.substring(0,mwh.lastIndexOf("."));
		mwss = mwss.substring(mwss.lastIndexOf(".")+1);
	}
	top.main.location=tour[i].tourCode+"."+mwss+".html";
}

function ResizeSide() {
//	if((navigator.userAgent.indexOf("AppleWebKit")==-1) && (navigator.userAgent.indexOf("Safari")==-1))  //Dont do with Safari!
//	{
//		var delta = 125 - document.body.clientWidth;
//		var newWidth = 125 + delta;
//		if (newWidth<125) newWidth=125;
//		var newCols = newWidth+',*';
//		top.document.body.cols = newCols;
//		self.location.reload();
//	}
}
