var Name = 'dgs1';
var Domain = 'delawarewildflowers.org';
var Query = replace(location.search.substring(1),"+"," ");


var IsIE = /*@cc_on!@*/false;


function WriteMto( Show)
{
if (Show==null) {Show = Name +'&#064;'+ Domain}
document.write('<a href="mailto:'+ Name +'&#064;'+ Domain +'">'+ Show +'</a>.')
}


function IsValue( S)
{
var startPos = Query.indexOf(S + "=");
return (startPos > -1)
}

function GetValue( S) {
    var startPos = Query.indexOf(S + "=");
    if (startPos > -1) {
        startPos = startPos + S.length + 1;
        var endPos = Query.indexOf("&",startPos);
        if (endPos == -1)
            endPos = Query.length;
        return unescape(Query.substring(startPos,endPos));
    }
    return '';
}

function replace(string,text,by) {
    // Replaces text with by in string
    var i = string.indexOf(text), newstr = '';
    if ((!i) || (i == -1))
        return string;
    newstr += string.substring(0,i) + by;
    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);
    return newstr;
}


function ShowPlant( ImgFile, ComName, SciName, Family, Width, Link)
{
if (Width==null)
   Width = 600;
document.write('<div class="pic-center" style="width: '+ Width +'px">')
document.write('<img src="'+ ImgFile +'" alt="'+ SciName +'">')
if (ComName != '')
	{
	if (Link==null)
      document.write('<br><i>'+ SciName +'</i>')
	else
      document.write('<br><a href="'+ Link +'"><i>'+ SciName +'</i></a>')
	}
document.write('<br>'+ ComName)
if (Family != null)
	document.write('<br>'+ Family)
document.write('</div>')
document.write('<p style="clear: both" class="noprint">')
}


function USDA_p_link( Symbol, SciName, ComName)
{
if (ComName==null)
   return '<a href="http://plants.usda.gov/java/profile?symbol='+ Symbol +'"><i>'+ SciName +'</i></a>'
else
   return '<a href="http://plants.usda.gov/java/profile?symbol='+ Symbol +'"><i>'+ SciName +',</i> </a><span class="plain-text"> '+ ComName +', </span>'
}


function p_link( PlantID, SciName, ComName)
{
return '<a href="'+ PlantID +'"><i>'+ SciName +',</i></a> <span class="plain-text"> '+ ComName +', </span>'
}

function li( Img, Link, Text)
{
if (Img=='')
   document.write( '<li>'+ Link + Text +'</li>')
else
   document.write( '<li><img src="'+ Img +'">'+ Link + Text +'</li>')
}


function ShowDef( Term)
{
Handle = window.open("glossary.html#"+Term, "", "toolbar=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=300")
Handle.focus()
}


function def( Term)
{
QTerm = "'"+ Term +"'"
return '<a href="JavaScript:ShowDef('+ QTerm +')">'+ Term +'</a>'
}

function wdef( Term)
{
document.write( def( Term))
}

var CP = '&nbsp; <i>'+ def('CP') +'</i>'

var PD = '&nbsp; <i>'+ def('PD') +'</i>'



function goto( href)
{
window.location.replace( href)
}


function goto_link( href, link, accesskey)
{
if (accesskey==null)
	document.write('<a href="javascript:goto(\''+ href +'\')">'+ link +'</a>')
else
	document.write('<a href="javascript:goto(\''+ href +'\')" accesskey="'+ accesskey +'">'+ link +'</a>')
}



/*----------------------------------------------------------------------------
 Opacity
----------------------------------------------------------------------------*/
// http://www.codeproject.com/KB/scripting/jscript_animation.aspx
function getOpacity(id)
{
var element = document.getElementById( id);
var opacity = null;

if (IsIE)
  {
  filter = element.style.filter;
  if(filter)
	  {
    alpha = filter.split("alpha(opacity=");
    opacity = alpha[1].substr(0,(alpha[1].length-1))/100;
    }
  }
else
  opacity = element.style.opacity;

return opacity;
}


function setOpacity( id, value)
{
if (IsIE)
	document.getElementById( id).style.filter = 'alpha(opacity='+ value*100 +')';
else
	document.getElementById( id).style.opacity = value;
}



/*----------------------------------------------------------------------------
 Slideshow
----------------------------------------------------------------------------*/
var ssPicNum;
var ssImage;
var ssStop;
var ssTop=70;
var ssHideMsec=400;
var ssShowMsec=500;

function ssShowImg()
{
// ssImg1 is the one we see
// ssImg2 is the old one, now hidden
// ssImage is the new one
Img1 = document.getElementById('ssImg1');
Img2 = document.getElementById('ssImg2');
// Copy Img1 to Img2
Img2.style.top = Img1.style.top;
Img2.style.left = Img1.style.left;
Img2.height = Img1.height;
Img2.src = Img1.src;
// Make Img2 visible, then hide Img1
setOpacity( 'ssImg2', 1);
setOpacity( 'ssImg1', 0);
// Get the new display size
h = Math.min( 600, ssImage.height);
w = h * ssImage.width / ssImage.height;
// Set up Img1
Img1.src = ssImage.src;
Img1.height = h;
Img1.style.top = (ssTop + (600-h) / 2) +'px';
Img1.style.left = ((document.body.clientWidth-w) / 2) +'px';
// Show Img1, and hide Img2
for(i = 0; i <= 50; i++)
  {
	if (!ssStop)
  	setTimeout("setOpacity('ssImg1', " + i/50 + ")",(i / 50 * ssShowMsec));
  setTimeout("setOpacity('ssImg2', " + (50-i)/50 + ")",(i / 50 * ssHideMsec));
  }
// Done, don't loop
if (ssStop)
	setTimeout("goto(location.href.substring(0,location.href.indexOf('?')))", ssShowMsec);
  //return;
// Next picture
ssPicNum++;
if (ssPicNum == ssPics.length)
  {
	// Stop at the first one
  ssStop = true;
  ssPicNum = 0
  }
// Load the next one
setTimeout( 'ssLoadImg()', 4000);
}


function ssLoadImg()
{
ssImage.src = ssPics[ ssPicNum];  // When the image is loaded it will call ssShowImg()
}


function slideshow()
{
setOpacity( 'ssImg2', 0);
setOpacity( 'ssImg1', 0);
ssPicNum = 0;
ssStop = false;
ssImage = new Image();
ssImage.onload=ssShowImg;
ssLoadImg();
}


/*----------------------------------------------------------------------------
 For the pre-PHP "other" pages
----------------------------------------------------------------------------*/

var DefaultWidth = 600

function ShowPlant( ImgFile, ComName, SciName, Family, Width, Link)
{
if (ImgFile.search('/') == -1)
	ImgFile = 'images/'+ ImgFile;
if ((Link != null) && (Link.slice(4) == '.html'))
	Link = 'plant.php?id='+ Link.slice( 0, 4);
if (Width==null)
   Width = DefaultWidth;
document.write('<div class="pic-center" style="width: '+ Width +'px">')
document.write('<img src="'+ ImgFile +'" alt="'+ SciName +'">')
if (SciName != null)
   if (Link==null)
      document.write('<br><i>'+ SciName +'</i>')
   else
      document.write('<br><a href="'+ Link +'"><i>'+ SciName +'</i></a>')
if (ComName != '')
	{
   if ((Link!=null) && (SciName == null))
      document.write('<br><a href="'+ Link +'">'+ ComName +'</a>')
   else
	   document.write('<br>'+ ComName)
	}
if (Family != null)
	document.write('<br>'+ Family)
document.write('</div>')
document.write('<p style="clear: both" class="noprint">')
}



function ShowPic( ImgFile, Caption, Width)
{
if (Width==null)
   Width = DefaultWidth;
if (Caption==null)
   Caption = '';
if (ImgFile.search('/') == -1)
	ImgFile = 'images/'+ ImgFile;
document.write('<div class="pic-center" style="width: '+ Width +'px">')
document.write('<img src="'+ ImgFile +'" alt="'+ Caption +'">')
document.write('<br>'+ Caption)
document.write('</div>')
document.write('<p style="clear: both" class="noprint">')
}


function ShowLink( PlantID, SciName, ComName)
{
if (PlantID.slice(4) == '.html')
	PlantID = 'plant.php?id='+ PlantID.slice( 0, 4);
document.write( '<a href="'+ PlantID +'"><i>'+ SciName +',</i></a> <span class="plain-text"> '+ ComName +'</span><br>')
}


