// JavaScript Document


// FEATURE CONTROLS

var timer;
var current = "slide1";
	
function controlSelect (current, next) {
	var deselect = "";
	var doSelect = "";
	
	if(document.getElementById("slide_up1")) {
		deselect = current.substring(0, 5) + "_up" + current.substring(5);
		document.getElementById(deselect).src = "/images/" + deselect + "_deselect.gif";
		doSelect = next.substring(0, 5) + "_up" + next.substring(5);
		document.getElementById(doSelect).src = "/images/" + doSelect + "_select.gif";
		}
	else if (document.getElementById("slide_down1")) {
		deselect = current.substring(0, 5) + "_down" + current.substring(5);
		document.getElementById(deselect).src="/images/" + deselect + "_deselect.gif";
		doSelect = next.substring(0, 5) + "_down" + next.substring(5);
		document.getElementById(doSelect).src="/images/" + doSelect + "_select.gif";
	}
	else {
		return;
	}
}
	
function slideFade (current, next) {
	
	current = "#" + current;
	next = "#" + next;
	
	
	/*var element1 = current.substring(1);
	var element2 = next.substring(1);
	document.getElementById(element1).style.display = "none";
	document.getElementById(element2).style.display = "block";*/
	
	//$(current).fadeOut("fast", function(){$(next).fadeIn("slow");} );
	$(current).animate({opacity:'hide'}, "fast", function(){$(next).animate({opacity:'show'}, "slow");} )
	//$(current).slideUp("fast", function(){$(next).slideDown("slow");} );
	
}
		
function supportUpdate(current, next) {
	var supportCurrent =  "support-info" + current.substring(5);
	var supportNext =  "support-info" + next.substring(5);
	slideFade(supportCurrent, supportNext); //currently support info uses the same function as the main slide to transition.  Change here, if desired.
}
		
function slideForward (ifWaitFirst) {
	var nextNumber = current.substring(5)*1;
	var next;
	var temp = function () { slideForward(0); };	
			
	if(ifWaitFirst == 1)
	{
		timer = window.setTimeout(temp, 30000); //change slide delay here
	}
	else
	{
		clearTimeout(timer);
				
		nextNumber++;
		next = "slide" + nextNumber;

				
		//if there isn't another image, starts from the beginning
		if(!document.getElementById(next)) {
			next = "slide1";
		}
				
		//old slide fades out, new fades in.  Updates current
		controlSelect(current, next); // update controls
		slideFade(current, next); //update slide
		//tests to see if there is support information, if so, update
		if (document.getElementById("support-info1")) {
			supportUpdate(current, next);
		}
		
		current = next;
	
		//calls temp--slideForward(0)--after 15 seconds
		timer = window.setTimeout(temp, 15000); //change slide delay here
	}
}

//basically the same as slideForward(0), except that the new slide is not necessarily the slide after the old one
function controlClick (nextNumber) {
	var next = "slide" + nextNumber;
	var temp = function () { slideForward(0); };
	
	clearTimeout(timer);
	
	//old slide fades out, new fades in.  Updates current
	controlSelect(current, next);
	slideFade(current, next);
	if (document.getElementById("support-info1")) {
		supportUpdate(current, next);
	}
	current = next;
				
	//calls temp--slideForward(0)--after 15 seconds
	timer = window.setTimeout(temp, 15000);
}

try {
  (function($) { [slideForward(1)] })(jQuery); 
}
catch(e) {
  // Do nothing:
}




/******************************************
* Lightbox config vars:
*/
var testing                       = false;
var write_cookie_after_seconds    = 3;  // Seconds
var close_lightbox_after_seconds  = 5; // Seconds

var lightbox_is_still_open        = false;


window.setTimeout(function() {
  if( /\#rename/i.test( document.location.hash.toString() ) || testing )
  {
    if( ! /knows_about_inflection_rename/.test( document.cookie.toString() ) || testing )
    {
      try {
        // Show the lightbox:
        $.fn.colorbox({
          inline:true,
          href: "#inlinediv",
          onClose: function() {
            lightbox_is_still_open = false;
          }
        });
        
        // Remember that the lightbox actually worked:
        lightbox_is_still_open = true;
      }
      catch(e) {
        // Do nothing:
      };
      
      // After X number of seconds, write the cookie so we don't show them again:
      window.setTimeout(function() {
        // If the lightbox was open this long, assume that the person has read it:
        if( lightbox_is_still_open )
        {
          var expires = new Date( (new Date()).valueOf() + ( 30 * 20 * 60 * 60 * 1000 ) );
          document.cookie = "knows_about_inflection_rename=1; expires=" + expires + "; path=/;";
        }// end if()
      }, write_cookie_after_seconds * 1000);
      
      // Close the lightbox automatically:
      window.setTimeout(function() {
        try {
         $.fn.colorbox.close();
        }
        catch(e) {
          // Do nothing:
        };
      }, close_lightbox_after_seconds * 1000 );
    }// end if()
  }// end if()
}, 2000);

