var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);

if (!isIE) {
    HTMLElement.prototype.__defineGetter__("innerText",
              function() { return (this.textContent); });
    HTMLElement.prototype.__defineSetter__("innerText",
              function(txt) { this.textContent = txt; });
}   

function openWin(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}


function MM_preloadImages() 
{ //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() 
{ //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) 
{ //v3.0
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() 
{ //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showProgress()
{
    var showActivityIndicator;
    showActivityIndicator = 1;

    if (typeof(Page_ClientValidate) == 'function') 
       {
       if (!Page_ClientValidate())
       {
        showActivityIndicator = 0
       }
    }
    
    if (showActivityIndicator==1)
    {
        toggle_div( "divClicked", "show" ) ;
        toggle_div( "divDefault", "hide" ) ;
    }
}

  function toggle_div( divID , showDiv)
  {
	
     var objdiv  ; 
      if ( document.getElementById ) 
        objdiv = document.getElementById( divID) ;
      else 
            objdiv = document.all[divID] ; //older IE include MAC
	  
      if (showDiv=='hide')
      {
        objdiv.style.display = "none" ;
        objdiv.style.visibility = "hidden" ;
      }
      else
      {
        objdiv.style.display = "block" ;
        objdiv.style.visibility = "visible" ;
      }

}
// Flag for species section.
var isSlideshow;
var isSpeciesList;

function setIsSlideshow() {
    isSlideshow = true;
    isSpeciesList = false;
}

function setIsSpeciesList() {
    isSlideshow = false;
    isSpeciesList = true;
}


//slideshow javascripts
var rotate_delay = 3000; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
    if (document.getElementById('Form1').slide[current + 1]) {
        //document.getElementById("MainContent_MainContent_ctlSlideshow_imgSlideshowImage").src = document.getElementById('Form1').slide[current + 1].value;
        crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[current + 1].value, '1', 'cc', document.getElementById('Form1').slide[current + 1].text)
        document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[current + 1].text;
        document.getElementById('Form1').slide.selectedIndex = ++current;
    }
    else first();
}
function previous() {
    if (current - 1 >= 0) {
        //  document.images.show.src = document.getElementById('Form1').slide[current - 1].value;
        crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[current - 1].value, '1', 'cc', document.getElementById('Form1').slide[current - 1].text)
        document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[current - 1].text;
        document.getElementById('Form1').slide.selectedIndex = --current;
    }
    else last();
}
function first() {
    current = 0;
    //document.getElementById("MainContent_MainContent_ctlSlideshow_imgSlideshowImage").src = document.getElementById('Form1').slide[0].value;
    crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[0].value, '1', 'cc', document.getElementById('Form1').slide[0].text)
    document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[0].text;
    document.getElementById('Form1').slide.selectedIndex = 0;
}
function last() {
    current = document.getElementById('Form1').slide.length - 1;
    // document.getElementById("MainContent_MainContent_ctlSlideshow_imgSlideshowImage").src = document.getElementById('Form1').slide[current].value;
    crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[current].value, '1', 'cc', document.getElementById('Form1').slide[current].text)
    document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[current].text;
    document.getElementById('Form1').slide.selectedIndex = current;
}
function ap(text) {
    document.getElementById('Form1').slidebutton.value = (text == "Stop") ? "Start Slideshow" : "Stop";
    rotate();
}
function rotate() {
    if (document.getElementById('Form1').slidebutton.value == "Stop") {
        current = (current == document.getElementById('Form1').slide.length - 1) ? 0 : current + 1;
        // document.getElementById("MainContent_MainContent_ctlSlideshow_imgSlideshowImage").src = document.getElementById('Form1').slide[current].value;
        crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[current].value, '1', 'cc', document.getElementById('Form1').slide[current].text)
        document.getElementById('Form1').slide.selectedIndex = current;
        document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[current].text;
        window.setTimeout("rotate()", rotate_delay);
    }
}
function imageClicked(imageNumber) {
    current = imageNumber;
    /// document.getElementById("MainContent_MainContent_ctlSlideshow_imgSlideshowImage").src = document.getElementById('Form1').slide[current].value;
    crosswipe(document.getElementById('MainContent_MainContent_ctlSlideshow_imgSlideshowImage'), document.getElementById('Form1').slide[current].value, '1', 'cc', document.getElementById('Form1').slide[current].text)
    document.getElementById('Form1').slide.selectedIndex = current;
    document.getElementById("MainContent_MainContent_ctlSlideshow_lblImageCaption").innerText = document.getElementById('Form1').slide[current].text;
}




/*******************************************************************************
IXW1.11 :: Image cross-wipe 
------------------------------------------------------------------------------
Copyright (c) 2004 James Edwards (brothercake)          <cake@brothercake.com>
BSD License                          See license.txt for licensing information
Info/Docs       http://www.brothercake.com/site/resources/scripts/transitions/
------------------------------------------------------------------------------
*******************************************************************************/
//global object
var ixw = { 'clock': null, 'count': 1 }

//crosswipe setup function
function crosswipe() {
    //if the timer is not already going
    if (ixw.clock == null) {
        //copy the image object 
        ixw.obj = arguments[0];

        //get its dimensions
        ixw.size = { 'w': ixw.obj.width, 'h': ixw.obj.height };

        //copy the image src argument 
        ixw.src = arguments[1];

        //change the image alt text if defined
        if (typeof arguments[4] != 'undefined' && arguments[4] != '') {
            ixw.obj.alt = arguments[4];
        }

        //if dynamic element creation is supported
        if (typeof document.createElementNS != 'undefined' || typeof document.createElement != 'undefined') {
            //create a new image object and append it to body
            //detecting support for namespaced element creation, in case we're in the XML DOM
            ixw.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));

            //set positioning classname
            ixw.newimg.className = 'idupe';

            //set src to new image src
            ixw.newimg.src = ixw.src

            //move it to superimpose original image
            ixw.newimg.style.left = ixw.getRealPosition(ixw.obj, 'x') + 'px';
            ixw.newimg.style.top = ixw.getRealPosition(ixw.obj, 'y') + 'px';

            //set it to be completely hidden with clip
            ixw.newimg.style.clip = 'rect(0, 0, 0, 0)';

            //show the image 
            ixw.newimg.style.visibility = 'visible';

            //copy and convert fade duration argument 
            ixw.length = parseInt(arguments[2], 10) * 1000;

            //create fade resolution argument as 20 steps per transition
            ixw.resolution = parseInt(arguments[2], 10) * 20;

            //copy slide direction argument
            ixw.dir = arguments[3];

            //start the timer
            ixw.clock = setInterval('ixw.crosswipe()', ixw.length / ixw.resolution);
        }

        //otherwise if dynamic element creation is not supported
        else {
            //just do the image swap
            ixw.obj.src = ixw.src;
        }

    }
};


//crosswipe timer function
ixw.crosswipe = function () {
    //decrease the counter on a linear scale
    ixw.count -= (1 / ixw.resolution);

    //if the counter has reached the bottom
    if (ixw.count < (1 / ixw.resolution)) {
        //clear the timer
        clearInterval(ixw.clock);
        ixw.clock = null;

        //reset the counter
        ixw.count = 1;

        //set the original image to the src of the new image
        ixw.obj.src = ixw.src;
    }

    //animate the clip of the new image
    //using the width and height properties we saved earlier
    ixw.newimg.style.clip = 'rect('
		+ ((/bt|bltr|brtl/.test(ixw.dir)) ? (ixw.size.h * ixw.count) : (/che|cc/.test(ixw.dir)) ? ((ixw.size.h * ixw.count) / 2) : (0))
		+ 'px, '
		+ ((/lr|tlbr|bltr/.test(ixw.dir)) ? (ixw.size.w - (ixw.size.w * ixw.count)) : (/cve|cc/.test(ixw.dir)) ? (ixw.size.w - ((ixw.size.w * ixw.count) / 2)) : (ixw.size.w))
		+ 'px, '
		+ ((/tb|tlbr|trbl/.test(ixw.dir)) ? (ixw.size.h - (ixw.size.h * ixw.count)) : (/che|cc/.test(ixw.dir)) ? (ixw.size.h - ((ixw.size.h * ixw.count) / 2)) : (ixw.size.h))
		+ 'px, '
		+ ((/lr|tlbr|bltr/.test(ixw.dir)) ? (0) : (/tb|bt|che/.test(ixw.dir)) ? (0) : (/cve|cc/.test(ixw.dir)) ? ((ixw.size.w * ixw.count) / 2) : (ixw.size.w * ixw.count))
		+ 'px)';

    //keep new image in position with original image
    //in case text size changes mid transition or something
    ixw.newimg.style.left = ixw.getRealPosition(ixw.obj, 'x') + 'px';
    ixw.newimg.style.top = ixw.getRealPosition(ixw.obj, 'y') + 'px';

    //if the counter is at the top, which is just after the timer has finished
    if (ixw.count == 1) {
        //remove the duplicate image
        ixw.newimg.parentNode.removeChild(ixw.newimg);
    }
};

//get real position method
ixw.getRealPosition = function () {
    this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
    this.tmp = arguments[0].offsetParent;
    while (this.tmp != null) {
        this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
        this.tmp = this.tmp.offsetParent;
    }

    return this.pos;
};

