//simple image flipping script
//created by Jameson Bennett
//for use in Minor/Hentz site

//global data members
imagepath = new Array();
imagedescr = new Array();
imagetitle = new Array();
imagewidth = new Array();
imageheight = new Array();
idx = new Number();
default_imageheight= new Number();
default_imagewidth = new Number();

//set the default global values used by this script
default_imageheight= 262;
default_imagewidth= 383;

//GLOBAL FUNCTIONS
//initializes page data
function init()
{
	idx = getURLValue("id");
	if (idx < 1) idx=1;
}

//writes the image tag into the document
function writeImagePath()
{
	var wd = default_imagewidth;
	var ht = default_imageheight;
	if(imagewidth[idx])
	{
		wd= imagewidth[idx];
	}
	if (imageheight[idx])
	{
		ht = imageheight[idx];
	}
	document.write('<img src="'+imagepath[idx]+'" width="' +wd+'" height="' +ht+ '"><br><span class="photocredit">Photo Credit: Ralph Gabriner</span>');
}

//writes the image description into the document
function writeImageDescription()
{
	document.write(imagedescr[idx]);
}

//writes the image title
function writeImageTitle()
{
	document.write(imagetitle[idx]);
}

//open this page with image data at this index
function openWithImage(index)
{
	var url = getBaseURL() + "?id=" + index;
	window.open(url, "_self");
}

//returns a base url for the site
function getBaseURL(){
  var url = window.location.href;
  var qparts = url.split("?");
  return qparts[0];
}

//returns the url decoded value with the var name passed in
function getURLValue(varname)
{

  var url = window.location.href;
  var qparts = url.split("?");

  if (qparts.length < 2)
  {
    return -1;
  }

  var query = qparts[1];
  var vars = query.split("&");
  var value = -1;
  
  for (i=0;i<vars.length;i++)
  {
    var parts = vars[i].split("=");
    if (parts[0] == varname)
    {
      value = parts[1];
      break;
    }
  }
  value = unescape(value);
  // Convert "+"s to " "s
  value.replace(/\+/g," ");
  return value;
}


