$(document).ready(function(){
  
  var THEMEPATH = "wp-content/themes/pecanstreet/";
  
  /* Show and hide the Smart Grid illustration */
  function hideImage() {
    $("#imageoverlay").hide(function(){
      $("body").unbind("click", hideImage);
    });
  }
  
  $(".smartgridlaunch").click(function(){
    $("#imageoverlay").show(function(){
      $("body").bind("click", hideImage);
    });
  });
  
  /* Select a random background photo to display 
  var availableBGimgs = 2; // number of photos that can be used in filename format "backgroundXX.png"
  var randBG = Math.floor(Math.random()*availableBGimgs) + 1; 
  $("body").css("background", "url('" + THEMEPATH + "images/background0" + randBG + ".png') #000 no-repeat"); */
  
  /* Hide/display helper text in the Sign-up form */
  $("#signupName").focus(function(){
    if ($(this).attr("value") == "Enter your name"){
      $(this).attr("value", "");
    }
  });
  
  $("#signupName").blur(function(){
    if ($(this).attr("value") == ""){
      $(this).attr("value", "Enter your name");
    }
  });
  
  $("#signupEmail").focus(function(){
    if ($(this).attr("value") == "Enter your email address"){
      $(this).attr("value", "");
    }
  });
  
  $("#signupEmail").blur(function(){
    if ($(this).attr("value") == ""){
      $(this).attr("value", "Enter your email address");
    }
  });
  
  /* Get Twitter Feed */
  
  getTwitters('twitter-feed', { 
    id: 'pecanstproject', 
    count: 5, 
    enableLinks: true, 
    ignoreReplies: false, 
    clearContents: true,
    template: '<p>"%text%" <br /><span class="twitterTimestamp">%time%</span></p>'
  });

  /* Apply PNG fix to IE browsers */
  
  jQuery.each(jQuery.browser, function(i, val) {
  if(i=="msie" && jQuery.browser.version.substr(0,1)=="6")
    $("ul.nav").addClass("pngtofix");
    DD_belatedPNG.fix('.pngtofix');
  });
  
  /* Email submit action */
  $("#signupButton").click(function(e){
    e.preventDefault();
    if ($("#signupEmail").attr("value") == "" || $("#signupEmail").attr("value") == "Enter your email address"){
      // do nothing
    } else {
      $(".emailList").submit();
    }
    
  });
  
  /* NAV SETUP */
  generateSprites(".nav", "current-", true, 150, "slide");
  generateSprites(".projectNav", "current-", true, 150, "fade");
  generateSprites(".partnersNav", "current-", true, 150, "fade");
  generateSprites(".newsNav", "current-", true, 150, "fade");
});