function imageViewer(myLink)
{
	windowName = "imagewindow";
	if(!window.focus) return;
   var myWin=window.open("",windowName,"width=840,height=690,resizable=yes,dependent=no,scrollbars=1,menubar=no,toolbar=no,status=yes,location=no");
   myWin.focus();
   myLink.target=windowName;
}

function getParameter(key,output)
{
	var retval = "";
	var ref = null;
	if (opener != null)
		ref = opener.document.imgForm;
	if (ref != null && ref != "") {
		if (key == "headline") 
			retval = ref.headline.value;
		else if (key == "basePath")
			retval = ref.basePath.value;
		else if (key == "allImgs")
			retval = ref.allImgs.value;		
		
		if (output) 
			document.write(retval);				
		else
			return retval;
	}
	return null;
}

function getNumberOfObjects() {
	var allImgsString = getParameter('allImgs',false);
	if ( allImgsString != null && allImgsString != "" ) {
		var allImgsArray = allImgsString.split(",");
		return allImgsArray.length;
	}
	return "?";
}

function getCurrentIndex() {
	var allImgsArray = getImgsArray();
	var selectedObj = getSelectedObjectName();
	if ( allImgsArray != null ) {
		for (i=0; i<allImgsArray.length; i++) {
			if ( allImgsArray[i] == selectedObj ) 
				break;
		}
		return i;
	}
	return null;
}

function getImgsArray() {
	var allImgsString = getParameter('allImgs',false);
	if ( allImgsString != null && allImgsString != "" )
		return allImgsString.split(",");
	return null;
}

function getObjectAtIndex(idx) {
	var allImgsArray = getImgsArray();
	var currentIndex = getCurrentIndex();
	
	if ( allImgsArray != null ) {
		if (idx == null)
			nextImage = allImgsArray[allImgsArray.length-1]; // go to end
		else if (idx == 0)
			nextImage = allImgsArray[0];	// go to start
		else {
			newIndex = currentIndex+idx;
			if (newIndex == allImgsArray.length)
				newIndex = 0;	
			else if (newIndex < 0)
				newIndex = allImgsArray.length-1;	
			nextImage = allImgsArray[newIndex];
		}
		document.location.href = "view.html?img=" + nextImage;
	}
}

function getSelectedObjectName() {
	FORM_DATA = createRequestObject();
	return FORM_DATA['img'];
}	

/*
   This popUp window needs to be called with:
   <A HREF="file.html" onClick="popUp(this,'windowName','width','height','scroll')">this is a popup</A>
*/

function popUpWin(myLink,windowName,myWidth,myHeight,myScroll)
{
   if(myScroll == '')
      myScroll ='no';
   
   if(!window.focus) return;
   var myWin=window.open("",windowName,"height=" + myHeight + ",width=" + myWidth + ",resizable=yes,dependent=no,scrollbars=" + myScroll + ",menubar=no,toolbar=no,status=yes");
   myWin.focus();
   myLink.target=windowName;
}

/* global init */
theImages  = new Array();
imageNames = new Array( 'road','events','geocaching','skate','bike','skydiving','snowboard','waterski','wakeboard','climbing','kite');

function preload()
{
	if (document.images && imageNames)
	{ 
	   for ( i=0; i<imageNames.length; i++ )	
	   {
   		theImages[imageNames[i]] = new Image();
			theImages[imageNames[i]].src = imageNames[i] + '/header.jpg';
		}
	}
}

function setHeader(cat)
{
	if (document.images && document.images.header && cat && theImages && theImages[cat]) {
		document.images['header'].src = theImages[cat].src;
	}
}

function setRandomHeader()
{
	i = Math.round(Math.random() * imageNames.length);
	setHeader(imageNames[i]);
}

function mark(imgName)
{
   if (document.images)
   {
 	  // unmark all images
      for ( i=0; i<theImages.length; i++ ) 
      {   
		 document.images[theImages[i]].src = eval( theImages[i] + '.src');
      }

	  if (imgName)
	  {
		// if image was not a marked image hilight it
	      if (document.images[imgName].src.indexOf('vi.') == -1)
	         document.images[imgName].src = eval(imgName + '_vi.src');
	  }
   }
}

function unmark(imgName)
{ 
   if (document.images)
   { 	document.images[imgName].src = eval(imgName + '.src');
   }
}

// used in footer of each page
function genMail() {
	document.write('<u><a href="/about.html">www.spe'+'edfreak.info</a></u>');
	//	genMailLink('info','speedfreak','info');
}

function genMailWeb() {
	document.write('<a href="mailto:' + 'info' + '@' + 'speedfreak' + '.' + 'info' + '?subject=broken link to page: [please paste url here]">email</a>');
}

function genMailFooter() {
	document.write('<u><a href="mailto:' + 'info' + '@' + 'speedfreak' + '.' + 'info' + '">www.sp'+'eedfreak.info</a></u>');
}

// about page
function genMailPurchase() {
	document.write('<a href="mailto:' + 'info' + '@' + 'speedfreak' + '.' + 'info' + '">' + 'info' + '@' + 'speedfreak' + '.' + 'info' + '</a>');
}

function genMailLink(name,domain,ext,title) {
	if(name!="" && domain!="") {
		document.write('<u><a href="mailto:' + name + '@' + domain + '.' + ext + '">'
		 + (title == null ? 	domain + '.' + ext : title)
		 + '</a></u>');
	}
}

// startpage
function genAboutLinkStart() {
	document.write('<span class="copyright">&copy; 2001-' + ((new Date()).getYear() < 1000 ? (new Date()).getYear() + 1900 : (new Date()).getYear()) + ' by ');
	genMail();
	document.write('</span>');
}


// view.html
function genFooter()
{
	// document.write('<a href="../index.html"><img src="/p.gif" class="backbutton" width="12" height="12" border="0"><span class="text">up one level</span></a><br>');
	document.write('<span class="copyright">&copy; 2001-' + ((new Date()).getYear() < 1000 ? (new Date()).getYear() + 1900 : (new Date()).getYear()) + ' by ');
	genMailFooter();
	document.write(' - All rights reserved.</span>');
}

function counterTAC()
{
	var eventdate = new Date("July 16, 2005 00:00:00 GMT");
	d=new Date();
	count=Math.floor((eventdate.getTime()-d.getTime())/1000);
	count=Math.floor(count/(60*60*24));
	return count;
}        

function createRequestObject() {
  
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  
  separator = ',';
    // The token used to separate data from multi-select inputs
  
  query = '' + this.location;
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
    
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
    
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }

  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.
  
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
      
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }

  return FORM_DATA;
}