var currentURL=new String(window.location);
var isIE=false;
jQuery.each(jQuery.browser, function(i, val) {
  if(i=="msie" && val==true)
  {
    isIE=true;
  }
});

jQuery.fn.log = function (msg) {
  if(!isIE)
  {
   // console.log("%s: %o", msg, this);
  }
  return this;
};
 
jQuery(window).bind('load', function() {
  preloadImages();
});

jQuery().ready(function(){
    
  if(jQuery(".detailPageMiddleCol").length>0 && jQuery("title").length>0 && !jQuery(".noPageHeading").length>0)
  {
    var newTitle;
    newTitle=jQuery("title").html().substring(13, jQuery("title").html().length);
    jQuery(".detailPageMiddleCol").prepend("<h1>"+newTitle+"</h1>");
  }
  jQuery("#middle").prepend(jQuery("#rightCol"));
  
  //determine expanded state of left nav if applicable - modified for multiple #leftNav entries (smartCurrents)
  var foundOne=false;
  jQuery("#leftCol .menu").each(function(){
    //console.log(jQuery(this));
    if(jQuery(this).length>0)
    {
      jQuery("ol > li", this).each(function(){
        //console.log(jQuery(this));
        if(!foundOne)
        {
          var baseURLArray=currentURL.split("/",7);
          if(jQuery("ol", this).length>0)
          {
            jQuery("ol > li > a", this).each(function(){
              var hrefArray=jQuery(this).attr("href").split("/",7);
              if(baseURLArray.length == hrefArray.length)
              {
                var continueSearch=true;
                for (arrCtr=baseURLArray.length-1;arrCtr>2;arrCtr--)
                {
                  if(baseURLArray[arrCtr]==hrefArray[arrCtr] && continueSearch)
                  {
                    if(arrCtr==3)
                    {
                      //jQuery(this).log(baseURLArray[arrCtr] + " | " + hrefArray[arrCtr] + "\n\nfound match for : \n" + currentURL + "\n to be : \n" + jQuery(this).attr("href"));
                      jQuery(this).parent().addClass("secondLevelSelected");
                      //jQuery(this).css("color","#0066cc");
                      foundOne=true;
                    }
                  }
                  else
                  {
                    continueSearch=false;
                  }
                }
              }
            });
          }
          else
          {
            var hrefArray=jQuery('a', this).attr("href").split("/",7);
            if(baseURLArray.length == hrefArray.length)
            {
              var continueSearch=true;
              for (arrCtr=baseURLArray.length-1;arrCtr>2;arrCtr--)
              {
                if(baseURLArray[arrCtr]==hrefArray[arrCtr] && continueSearch)
                {
                  if(arrCtr==3)
                  {
                    jQuery(this).addClass("firstLevelSelected");
                    //jQuery('a', this).css("color","#FFFFFF");
                    foundOne=true;
                  }
                }
                else
                {
                  continueSearch=false;
                }
              }
            }
          }
          if(foundOne)
          {
            jQuery('ol', this).show();
            jQuery('div img', this).attr("src", dteenergySitePrefix+"/images/navigation/leftNavSelectedArrow.gif");
            jQuery(this).addClass("showSecondLevel");
            //jQuery(this).css("background-color", "#A3A3A3");
            //jQuery(this).css("color", "#FFFFFF");
          }
        }
      });
    }
  });

  // show here else the video features text won't display
  jQuery("#rightCol, #middleCol, #bottom").show();

  jQuery(".feature").each(function(){
    if(jQuery('a', this).attr("href").indexOf("/video/")>-1)
    {
      jQuery(this).addClass("video");
      jQuery('a', this).hide();
      if(jQuery('.featureContent img', this).width()!=jQuery('.featureContent', this).width())
      {
        jQuery('.featureHeading, .featureSubHead', this).hide();
        setTimeout(resetVideoTextDivWidths, 1000);
      }
      jQuery('.featureHeading, .featureSubHead', this).width(jQuery('.featureContent', this).width());
    }
    else
    {
      if (jQuery(this).hasClass("featureSpanTwoCols"))
      {
        jQuery('.featureContent', this).width(376);  //  (189 * 2) - 2 for borders
      }
      else
      {
        jQuery('.featureContent', this).width(187);  // 189 - 2 for borders
      }
    }
  });

	var now=new Date();
	var currYear=now.getFullYear();
  jQuery("#footerYear").html(currYear);

  jQuery("#signIn").mouseover(function(){
    jQuery(this).attr("src", "/images/buttons/signInClearGRAYDown.jpg");
  }).mouseout(function(){
    jQuery(this).attr("src", "/images/buttons/signInClearGRAYUp.jpg");
  });

  //remove from view the positioning numbers for the landingPageTopDiv
  jQuery("#themeHead p:first-child").css("display","none");
  jQuery("#themeSub p:first-child").css("display","none");
  jQuery("#themeText p:first-child").css("display","none");

  //feature/promo borders
  /* features in the right hand side (including landingPageTopDiv) are not allowed to 
  have vertical lines (borders).  This is because the image is sized for 187 pixels
  which allows room for the 2 pixel border to the left of the image on the right side */
  jQuery("#landingPageTopDiv .featureVertBorder").remove();
  jQuery("#rightCol .featureVertBorder").remove();
  
  jQuery("#landingPageBottomDiv .feature").each(function(i){
    if(i==0)
    {
      if(jQuery(this).parent().hasClass('1FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('1FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
    if(i==1)
    {
      if(jQuery(this).parent().hasClass('2FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('2FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
    if(i==2)
    {
      if(jQuery(this).parent().hasClass('3FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('3FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
    if(i==3)
    {
      if(jQuery(this).parent().hasClass('4FeatureRightBorder'))
      {
        jQuery('.featureVertBorder:last-child', this).css("background-color", "#A3A3A3");
      }
      if(jQuery(this).parent().hasClass('4FeatureLeftBorder'))
      {
        jQuery('.featureVertBorder:first-child', this).css("background-color", "#A3A3A3");
      }
    }
  });

  jQuery(".newsLink").mouseover(function(){
    jQuery(this).css("background", "url('/images/navigation/blueArrow.gif') no-repeat right 1px");
    jQuery('a', this).css("color", "#0066CC");
  });
  jQuery(".newsLink").mouseout(function(){
    jQuery(this).css("background", "url('/images/navigation/leftNavNotSelectedArrow.gif') no-repeat right 1px");
    jQuery('a', this).css("color", "#333333");
  });

  if(jQuery("#newsfeed").length>0)
  {
    jQuery("#newsfeed").feedreader({
      // production needs proxy pass-thru and to test error display, just reference non-existin url
      //targeturl: dteenergySitePrefix+'/includes/rssfeedSample.xml'
      targeturl: jQuery('#newsFeedURL a', this).attr('href'),
      items: jQuery("#numOfNewsArticlesToDisplay").html()
    });
  }

  // left nav
  jQuery("#leftNav li li").bind("mouseenter",function(){
    //jQuery('a', this).css("color", "#015FD3");
  }).bind("mouseleave",function(){
    if(jQuery(this).hasClass('selected'))
    {
      //jQuery('a', this).css("color", "#0066cc");
    }
    else
    {
      //jQuery('a', this).css("color", "#333333");
    }
  });

  jQuery("#leftNav > ol > li").bind("mouseenter",function(){
    if(jQuery('ol', this).length>0)
    {
      //jQuery(this).css("background-color", "#A3A3A3");
      //jQuery(this).css("color", "#FFFFFF");
    }
    else
    {
      //jQuery(this).css("background-color", "#A3A3A3");
      //jQuery('a', this).css("color", "#FFFFFF");
    }
  }).bind("mouseleave",function(){
    if(jQuery('ol', this).length>0)
    {
      if(!(jQuery('ol', this).css("display").indexOf("block")>-1))
      {
        //jQuery(this).css("background-color", "#D9D9D9");
        //jQuery(this).css("color", "#333333");
      }
    }
    else
    {
      if(jQuery(this).hasClass('selected'))
      {
        //jQuery(this).css("background-color", "#A3A3A3");
        //jQuery('a', this).css("color", "#FFFFFF");
      }
      else
      {
        //jQuery(this).css("background-color", "#D9D9D9");
        //jQuery(this).css("color", "#333333");
        //jQuery('a', this).css("color", "#333333");
      }
    }
  });

  jQuery("#leftNav a").click(function(event){
    // based on testing, it appears that the "a" tag will fire successfully and then stop any processing for the click, which keeps the "li" click from happening
    //alert ("stopping 'a'");
    event.stopPropagation();
  });
  jQuery("#leftNav ol li ol li").click(function(event){
    //second level LeftNav link.  The event.stopPropagation(); keeps the leftNav open if the second level has been expanded.
    //alert ("second level li click");
    var newWindow = jQuery('a', this).attr("target");
    if (newWindow == "_blank") {
      window.open(jQuery('a', this).attr("href"));
    } else {
      window.location=jQuery('a', this).attr("href");
    }
    event.stopPropagation();
	});

  jQuery("#leftNav > ol li").click(function(event){
		if(jQuery('ol', this).length>0)
		{
			if(jQuery('ol', this).css("display")=="none")
			{
        jQuery("#leftNav ol ol").each(function(){
          if(jQuery(this).css("display")=="block")
          {
            jQuery(this).slideUp(300);
            jQuery('div img', jQuery(this).parent()).attr("src", dteenergySitePrefix+"/images/navigation/leftNavNotSelectedArrow.gif");
            //jQuery(this).parent().css("background-color", "#D9D9D9");
            //jQuery(this).parent().css("color", "#333333");
          }
        })
        jQuery('ol', this).slideDown(300, function(){
            var borderTop=jQuery('li:eq(0)', this).css("border-top-width");
            borderTop=borderTop.substring(0,borderTop.indexOf("px"));
            var paddingTop=jQuery('li:eq(0)', this).css("padding-top");
            paddingTop=paddingTop.substring(0,paddingTop.indexOf("px"));
            var height=jQuery('li:eq(0)', this).height();
            var adjustedHeight=height*1+paddingTop*1+borderTop*1;
          jQuery(this).css("height", (adjustedHeight*(jQuery('li', this).length))+"px");
        });
        jQuery('div img', jQuery(this)).attr("src", dteenergySitePrefix+"/images/navigation/leftNavSelectedArrow.gif");
        //jQuery('a', this).css("color", "#333333");
      }
			else
			{
				jQuery('ol', this).slideUp(300);
        jQuery('div img', jQuery(this)).attr("src", dteenergySitePrefix+"/images/navigation/leftNavNotSelectedArrow.gif");
			}
		}
		else
		{
      //first level LeftNav link.  The event.stopPropagation(); keeps the leftNav open if the second level has been expanded.
      //alert ("first level li click");
      var newWindow = jQuery('a', this).attr("target");
      if (newWindow == "_blank") {
        window.open(jQuery('a', this).attr("href"));
      } else {
        window.location=jQuery('a', this).attr("href");
      }
      event.stopPropagation();
		}
	});

  // features
  jQuery(".feature a, .investorHighlight a").click(function(e){
    e.stopPropagation();
  });
  
  jQuery(".feature, .investorHighlight").click(function(e){
    if(!jQuery(this).hasClass("video"))
    {
      if(jQuery('a', this).attr("target")=="_blank")
      {
        window.open(jQuery('a', this).attr("href"));
      }
      else
      {
        window.location=jQuery('a', this).attr("href");
      }
      e.stopPropagation();
    }
  });

  jQuery(".feature").mouseover(function(){
    jQuery(".promoLink a, .businessLandingPageSubNavText a", this).css("color", "#0066cc");
    jQuery(".promoLink", this).css("background", "url('/images/navigation/blueArrow.gif') no-repeat right 1px");
  });

  jQuery(".feature").mouseout(function(){
    jQuery(".promoLink a, .businessLandingPageSubNavText a", this).css("color", "#333333");
    jQuery(".promoLink", this).css("background", "url('/images/navigation/leftNavNotSelectedArrow.gif') no-repeat right 1px");
  });

  // investor highlights
  jQuery(".investorHighlight").click(function(event){
    window.location=jQuery('a', this).attr("href");
    event.stopPropagation();
  });

  jQuery(".investorHighlight").mouseover(function(){
    jQuery('a', this).css("color", "#0066cc");
  });

  jQuery(".investorHighlight").mouseout(function(){
    jQuery('a', this).css("color", "#333333");
  });

  //connections
  jQuery("#connectionsPrime").mouseover(function(){
    jQuery("a", this).css("color", "#0066cc");
    if(jQuery(this).hasClass("businessConnections"))
    {
      jQuery(".connectionsPrimeLink", this).css("background", "url('/images/navigation/blueArrow.gif') no-repeat 166px 3px #b2cc99");
    }
    if(jQuery(this).hasClass("residentialConnections"))
    {
      jQuery(".connectionsPrimeLink", this).css("background", "url('/images/navigation/blueArrow.gif') no-repeat 166px 3px #99CCe5");
    }
  });

  jQuery("#connectionsPrime").mouseout(function(){
    jQuery("a", this).css("color", "#333333");
    if(jQuery(this).hasClass("businessConnections"))
    {
      jQuery(".connectionsPrimeLink", this).css("background", "url('/images/navigation/leftNavNotSelectedArrow.gif') no-repeat 166px 3px #b2cc99");
    }
    if(jQuery(this).hasClass("residentialConnections"))
    {
      jQuery(".connectionsPrimeLink", this).css("background", "url('/images/navigation/leftNavNotSelectedArrow.gif') no-repeat 166px 3px #99CCe5");
    }
  });

  jQuery("#connectionsPrime").click(function(){
    window.location=jQuery('a', this).attr("href");
  });

  jQuery(".video").click(function(event){
    var veilFadeInOutSpeedMillis=800;
    jQuery("#middle").append("<div class='veil'></div>");
    jQuery(".veil").css("opacity", "0.6");
    jQuery(".veil").css("filter", "alpha(opacity=60)");
    jQuery(".veil").css("position", "absolute");
    jQuery(".veil").css("width", "756px");
    jQuery(".veil").css("height", jQuery("#middleCol").height());
    jQuery(".veil").css("left", jQuery("#middleCol").offset().left + "px");
    jQuery(".veil").css("top", jQuery("#middleCol").offset().top + "px");
    jQuery(".veil").fadeIn(veilFadeInOutSpeedMillis);
    var box=Boxy.load(jQuery('a', this).attr("href"), 
      {title: jQuery('.featureHeading', this).html(), draggable: false, afterShow: function(){positionVideo()}, afterHide: function(){
        jQuery(".veil").fadeOut(veilFadeInOutSpeedMillis, function(){jQuery(".boxy-wrapper").remove();jQuery(".veil").remove();});
      }
    });
    // return false is specifically here to prevent browser from navigating to target of an "a" tag.
    return false;
  });

 
  jQuery(".featureRightVertLine").prepend("<div class='featureRightBorder'></div>");
  jQuery(".featureLeftVertLine").prepend("<div class='featureLeftBorder'></div>");


  // Special handling of Business Landing Page "features"

  /* djf - special handling of the business landing page features was commented out 1/13/2011 because 
           corporate communications changed the page to a normal landing page with normal features

  if((currentURL.lastIndexOf('/businessCustomers/')==(currentURL.length-'/businessCustomers/'.length)) 
    || (currentURL.indexOf("/businessCustomers/index.html")>-1))
  {
    jQuery("#landingPageBottomDiv .feature").each(function(i){
      jQuery('.featureVertBorder', this).remove();
      jQuery('.featureSpacer', this).remove();
      jQuery('.featureHeading', this).remove();
      jQuery('.featureSubHead', this).remove();
      jQuery('.featureLinkSpacer', this).remove();
      var busImgSrc=jQuery('.featureImage', this).attr("src");
      var busImgAlt=jQuery('.featureImage', this).attr("alt");
      jQuery('.featureImage', this).remove();
      jQuery('.promoLink', this).removeClass("promoLink").addClass("businessLandingPageSubNavText");
      jQuery('.businessLandingPageSubNavText', this).after("<img class='businessLandingPageNavArrow' />");
      jQuery('.businessLandingPageNavArrow', this).after("<img src='"+busImgSrc+"' alt='"+busImgAlt+"' />");
      
      if(i<1||i>2)
      {
        jQuery('.businessLandingPageNavArrow', this).attr("src", "/images/navigation/barArrow187.jpg");
      }
      else
      {
        jQuery('.businessLandingPageNavArrow', this).attr("src", "/images/navigation/barArrow188.jpg");
      }
      
      if(i<2)
      {
        jQuery(this).css("background", jQuery(this).css("background-image")+" left 60px no-repeat");
      }
      else
      {
        jQuery(this).css("background", jQuery(this).css("background-image")+" right 60px no-repeat");
      }
    });
  }
  */

  // helpCenter click
  jQuery("#helpCenterMsgArea").click(function(event){
    var URL = window.location.href;
    var section = "";
    if (URL.indexOf('businessCustomers') > 0) 
    {
      section = "businessCustomers";
    } else {
      section = "residentialCustomers";
    }
    window.location = dteenergyUnsecuredSitePrefix + "/" + section + "/billingPayment/questions/questions.html";
  });  //end of click

  // electricityAlert click
  jQuery("#electricityAlertMsgArea").click(function(event){
    var tempBox = Boxy.load("/electricityAlert.html", {
      title: "Electricity Alert", 
      draggable: false, 
      modal: true
    });
  });  //end of click

  // interruption probability click
  jQuery("#interruptionProbabilityMsgArea").click(function(event){
    window.location="/businessCustomers/largeBusinesses/electric/interruptionProbability.html";
  });  //end of click


  // new increase / decrease font size options

  /*  options commented out since the text resize options have not been implemented
  
  var originalFontSize = parseFloat(jQuery("body").css("font-size"), 12);
  setFontSize(originalFontSize);   // sets #middleCol to default font-size of 12

  jQuery(".resetFont").click(function(){
    setFontSize(originalFontSize);
    return false;
  });
  jQuery(".increaseFont").click(function(){
    var fontSize = getFontSize();
    var newFontSize = fontSize + 1;
    setFontSize(newFontSize);
    return false;
  });
  jQuery(".decreaseFont").click(function(){
    var fontSize = getFontSize();
    var newFontSize = fontSize - 1;
    setFontSize(newFontSize);
    return false;
  });

  */

  // moreLess is used on the corporate responsibility report
  jQuery(".moreLessOption").click(function(){
    //console.log(jQuery(this).parent().parent());
    moreLessText = jQuery(this).parent().parent().children(".moreLessText");
    if(moreLessText.is(":visible"))
    {
      moreLessText.hide();
      jQuery(this).html("more");
    }
    else
    {
      moreLessText.show();
      jQuery(this).html("less");
    }
  });
  
  /*  set table to have a colored top row, then alternating gray/white rows */
  jQuery("table.zebra").each(function(){
    //console.log(jQuery(this));
    jQuery(this).addClass("color");
    jQuery("tr:even", this).addClass("white");
    jQuery("tr:odd", this).addClass("gray");
    jQuery("tr:first", this).addClass("color").removeClass("white");
    jQuery("tr:first td", this).each(function(){
      jQuery("td", this).addClass("white");
    });
  });

});

function resetVideoTextDivWidths()
{
  if(jQuery('.featureContent img', this).width()!=jQuery('.featureContent', this).width())
  {
    setTimeout(resetVideoTextDivWidths, 1000);
  }
  else
  {
    jQuery(".feature").each(function(){
      if(jQuery('a', this).attr("href").indexOf("/video/")>-1)
      {
        jQuery('.featureHeading, .featureSubHead', this).show();
        jQuery('.featureHeading, .featureSubHead', this).width(jQuery('.featureContent', this).width());
      }
    });
  }
}

function resetColumnHeights()
{
/*
  //  set heights to default before reset
  jQuery("#leftCol").css("height", "auto");
  jQuery("#middleCol").css("height", "auto");
  jQuery("#rightCol").css("height", "auto");
  jQuery("#middle").css("height", "auto");
  if(jQuery(".detailPageMiddleCol").length>0)
  {
    jQuery(".detailPageMiddleCol").css("height", "auto");
  }

  var middleColHeight=document.getElementById("middleCol").offsetHeight;
  var leftColHeight;
  var rightColHeight;
  var singleColWidth=189;
  var cols="";
  var tallestColHeight;

  if(jQuery("#rightCol").length>0)
  {
    rightColHeight=document.getElementById("rightCol").offsetHeight;
    cols="r";
  }

  if (jQuery("#leftCol").length>0)
  {
    leftColHeight=document.getElementById("leftCol").offsetHeight;
    cols=cols+"l";
    if (jQuery("#leftNav ol ol").length>0)
    {
      // *Note: we must account for padding and potential full expansion of all left nav sub menus
      var leftSubMenuItemHeight=jQuery("#leftNav ol ol > li:first").css("height");
      leftSubMenuItemHeight=leftSubMenuItemHeight.substring(0, leftSubMenuItemHeight.indexOf("px"));
      var leftSubMenuItemPaddingHeight = jQuery("#leftNav ol ol > li:first").css("padding-top");
      leftSubMenuItemPaddingHeight=leftSubMenuItemPaddingHeight.substring(0, leftSubMenuItemPaddingHeight.indexOf("px"));
      var leftSubMenuItemTotalHeight=leftSubMenuItemHeight*1 + leftSubMenuItemPaddingHeight*1;
      var tallestLeftColSubMenu=0;
      jQuery("#leftNav ol ol").each(function(){
        if(jQuery('li', this).length>tallestLeftColSubMenu)
        {
          tallestLeftColSubMenu=jQuery('li', this).length;
        }
      });
      leftSubMenuItemTotalHeight=leftSubMenuItemTotalHeight+1;
      leftColHeight=(((jQuery("#leftNav > ol > li").length + tallestLeftColSubMenu) * leftSubMenuItemTotalHeight)-1);
      if(jQuery("#messageCenter").length>0)
      {
        leftColHeight=leftColHeight+jQuery("#messageCenter").height();
      }
    }
  }

  var detailMidPageLeftRightPad;
  if(jQuery(".detailPageMiddleCol").length>0)
  {
    detailMidPageLeftRightPad=jQuery(".detailPageMiddleCol").css("padding-left").replace(/px/, '')*1+jQuery(".detailPageMiddleCol").css("padding-right").replace(/px/, '')*1;
  }

  switch(cols)
  {
    case "r":
    {
      if(jQuery(".detailPageMiddleCol").length>0)
      {
        jQuery(".detailPageMiddleCol").css("width", singleColWidth*4-detailMidPageLeftRightPad + "px");
      }
      //recalculate the middle col height after width gets adjusted
      jQuery("#middleCol").css("width", singleColWidth*4 + "px");
      middleColHeight=document.getElementById("middleCol").offsetHeight;
      tallestColHeight=Math.max(middleColHeight, rightColHeight);
      break;
    }
    case "l":
    {
      if(jQuery(".detailPageMiddleCol").length>0)
      {
        jQuery(".detailPageMiddleCol").css("width", singleColWidth*4-detailMidPageLeftRightPad + "px");
      }
      //recalculate the middle col height after width gets adjusted
      jQuery("#middleCol").css("width", singleColWidth*4 + "px");
      middleColHeight=document.getElementById("middleCol").offsetHeight;
      tallestColHeight=Math.max(leftColHeight, middleColHeight);
      break;
    }
    case "rl":
    {
      tallestColHeight=Math.max(leftColHeight, middleColHeight, rightColHeight);
      break;
    }
    case "":
    {      
      if(jQuery(".detailPageMiddleCol").length>0)
      {
        jQuery(".detailPageMiddleCol").css("width", singleColWidth*5-detailMidPageLeftRightPad + "px");
      }
      //recalculate the middle col height after width gets adjusted
      jQuery("#middleCol").css("width", singleColWidth*5 + "px");
      middleColHeight=document.getElementById("middleCol").offsetHeight;
      tallestColHeight=middleColHeight;
      break;
    }
  }

  jQuery("#leftCol").css("height", tallestColHeight);
  jQuery("#middleCol").css("height", tallestColHeight);
  jQuery("#rightCol").css("height", tallestColHeight);
  jQuery("#middle").css("height", tallestColHeight);

  //show middleCol and rightCol div's that were set visibility:hidden in css to compensate for delay of the jQuery work.
  jQuery("#middleCol, #rightCol").wrapInner("<div></div>");
  jQuery("#middleCol").css("visibility", "visible");
  jQuery("#rightCol").css("visibility", "visible");
*/
}

//top Navigation Tab functions
// set State for Tabs / buttons  (three states are Up, Over, Down)
function changeTab(section,state){
  var testSource = document.getElementById(section).src;
  if (testSource.indexOf("btnDown") < 0) {
    document.getElementById(section).src = dteenergySitePrefix+"/images/navigation/" + section + "_btn" + state + ".jpg";
  }
}

function changeButton(section,state){
  if(section.indexOf('@')>-1)
  {
    document.getElementById(section).src = dteenergySitePrefix+"/images/buttons/" + section.substring(0,section.indexOf('@')) + state + ".jpg";
  }
  else
  {
    document.getElementById(section).src = dteenergySitePrefix+"/images/buttons/" + section + state + ".jpg";
  }
}

var disappeardelay=500;
function delayHideSubMenu(){
 delayhide=setTimeout("hideSubMenu()",disappeardelay)
};

function clearHideSubMenu(){
  if (typeof delayhide!="undefined")
  clearTimeout(delayhide)
};

function hideSubMenu(){
  jQuery("#subArea").animate({height: "0px", marginLeft: "567px", top:"48px", width: "0px"}, 500);
  changeButton('allSitesArea','Up');
};

function show(item) {
  document.getElementById(item).style.display = "block";
}

function hide(item) {
  document.getElementById(item).style.display = "none";
}

function toggle(item) {
  if (document.getElementById(item).style.display == "block") {
    document.getElementById(item).style.display = "none";
    if (item == "subList") {
      changeButton('allSitesArea','Up');
    }
  } else {
    document.getElementById(item).style.display = "block";
    if (item == "subList") {
      changeButton('allSitesArea','Down');
    }
  }
}

function toggleSubList() {
  if(jQuery("#subArea").height()=="0")
  {
    setSubListHeight();
    document.getElementById("subArea").style.left = (document.getElementById("mainCenteringWrapper").offsetLeft + jQuery("#subArea").width() + 189) + "px";
    // move to top and left position calculations
    var leftPosition = (document.getElementById("mainCenteringWrapper").offsetLeft + 189) + "px";
    var topPosition = "1px";
    jQuery("#subArea").animate({height: "145px", marginLeft: "0px", top:"0px", width: "567px"}, 500);
  }
  else
  {
    hideSubMenu()
  }
}

function setSubListHeight() {
  jQuery("#subList").height(Math.max(document.getElementById("affiliatesBox").offsetHeight, document.getElementById("specialInterestBox").offsetHeight));
}

function positionVideo() {
  jQuery(".boxy-wrapper").hide();
  var leftOffset=0;
  if(jQuery("#rightCol").length>0)
  {
    leftOffset=(jQuery("#middleCol").offset().left+jQuery("#middleCol").width()/2+jQuery("#rightCol").width()/2)-((jQuery(".boxy-wrapper").width())/2);
  }
  else
  {
    leftOffset=jQuery("#middleCol").offset().left+(jQuery("#middleCol").width()/2)-((jQuery(".boxy-wrapper").width())/2);
  }
  var topOffset=jQuery("#middleCol").offset().top+20;
  jQuery(".boxy-wrapper").css("left", leftOffset+"px");
  jQuery(".boxy-wrapper").css("top", topOffset+"px");
  jQuery(".boxy-wrapper").fadeIn(500);
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//  function used by the FAQ, didn't rename it because would require a template change as well.
function toggleItem(question, answer) {
  if (document.getElementById(answer).style.display == "none") {
    document.getElementById(answer).style.display = "block";
  } else {
    document.getElementById(answer).style.display = "none";
  }
  
  if (document.getElementById(question).getElementsByTagName("span")[0].innerHTML == "+&nbsp;&nbsp;") {
    document.getElementById(question).getElementsByTagName("span")[0].innerHTML = "-&nbsp;&nbsp;";
  } else {
    document.getElementById(question).getElementsByTagName("span")[0].innerHTML = "+&nbsp;&nbsp;";
  }
  
  resetColumnHeights();

}

function hideLoginBox(){
  jQuery(".connectionsPrimeLink").css("border-top", "1px solid #FFFFFF");
  jQuery("#notLoggedInText").hide();
  jQuery("#customerLoginForm").animate({
    height: "0px"
  }, 500 );
  jQuery(".connections").animate({
    height: "213px"
  }, 500, function(){
    jQuery("#loggedInText").animate({
    height: "133px"
    }, 500);
  });
}

/*

function no longer active with the login box functioning, left in for code example

function testSignOut(){
  jQuery("#businessCustLogin #password").attr("value", "");
  jQuery(".connections").animate({
    height: "94px"
  }, 1000);
  jQuery("#loggedInText").animate({
    height: "0px"
  }, 800, function(){
    jQuery("#loggedInText").css("display", "none");
    jQuery("#notLoggedInText").show();
    jQuery(".connectionsPrimeLink").css("border-top", "");
    jQuery("#customerLoginForm").animate({
      height: "213px"
    }, 500 );
  });
}
*/

/*  Printer Friendly functions */
function setPrinterFriendly() {
  jQuery("#top").hide();
  jQuery("#leftCol").hide();
  jQuery("#rightCol").hide();
  jQuery("#bottom").hide();
  jQuery("#printerFriendly").hide();
  jQuery("#webView").show();
}

function setNormal() {
  jQuery("#top").show();
  jQuery("#leftCol").show();
  jQuery("#rightCol").show();
  jQuery("#bottom").show();
  jQuery("#printerFriendly").show();
  jQuery("#webView").hide();
}

/*  disabled this function since it was causing problems, code was added to jQuery ready for binding clicks
function turnStyleOn (ssName) {
  $('link').each(function(i) {
    if (this.getAttribute('title')) {
      this.disabled = true;
      if (this.getAttribute('title') == ssName) {
        this.disabled = false;
      }
    }
  });
}
*/

/* NOTE: The boxyForm function below was refactored and the name was not changed so as to avoid having to refactor the 99+ links in 47+ files.  Consequently, 
  the name is somewhat misleading.  The forms do not open in a "boxy" window, rather as inline content like the rest of the forms. 
  TODO : use jQuery UI's modal, draggable dialog box instead ... for now it is just ugly and serves only 5 forms */
function boxyForm(cookieName, cookieData, title, pathToWrapper) {
  if(cookieName && cookieData)
  {
    jQuery.cookie(cookieName, cookieData + "|" + title, {path: '/'});
  }
  
  var windowOptions = "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no"
  
  if((pathToWrapper.indexOf("fileComplaintForm")>-1) || (pathToWrapper.indexOf("customerServiceEmailForm")>-1))
  {
    windowOptions = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no"
  }
  
  window.open(dteenergySecuredSitePrefix+pathToWrapper, '',windowOptions);
}

function addCommas(nStr) {
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return x1 + x2;
}  

function getArgs(){
   var args = new Object();
   var query = location.search.substring(1);
   var pairs = query.split("&");
   for (var i=0; i<pairs.length; i++){
      var pos = pairs[i].indexOf('=');
	  if (pos == -1) continue;
	  var argname = pairs[i].substring(0,pos);
	  var value=pairs[i].substring(pos+1);
	  args[argname]=unescape(value);
   }
   return args;
}

// added function for bookmarking pages.
function bookmark(){
  var url = this.location;
  var title = document.title;
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}  

function highlightLeftNavFirstOccuranceCurrentDirectory() {
  if(jQuery("#leftNav").length>0)
  {
    var foundOne=false;
    var baseURLArray=currentURL.split("/",7);
    jQuery("#leftNav > ol > li").each(function(){
      if(!foundOne)
      {
        var hrefArray=jQuery('a', this).attr("href").split("/",7);
        if(baseURLArray.length == hrefArray.length)
        {
          var continueSearch=true;
          for (arrCtr=baseURLArray.length-2;arrCtr>2;arrCtr--)
          {
            if(baseURLArray[arrCtr]==hrefArray[arrCtr] && continueSearch)
            {
              if(arrCtr==3)
              {
                jQuery(this).addClass("selected");
                jQuery(this).css("background-color", "#A3A3A3");
                jQuery('a', this).css("color","#FFFFFF");
                foundOne=true;
              }
            }
            else
            {
              continueSearch=false;
            }
          }
        }
      }
    });
  }
}

// new functions added 2/2/2011 for increase/decreasing font size in page
function getFontSize() {
    var currentSize = jQuery("#middleCol").css("font-size");
    var currentSizeNumber = parseFloat(currentSize, 12);
    if(currentSizeNumber < 7) 
    {
      currentSizeNumber = 7;
    }
    if(currentSizeNumber > 20) 
    {
      currentSizeNumber = 20;
    }
    return currentSizeNumber;
}

function setFontSize(size) {
    jQuery("#middleCol").css("font-size", size);
}


function preloadImages() {
  
  var preload = new Array();
  preload.push(dteenergySitePrefix+"/images/buttons/allSitesAreaDown.jpg");
  preload.push(dteenergySitePrefix+"/images/buttons/allSitesAreaUp.jpg");
  preload.push(dteenergySitePrefix+"/images/buttons/searchClearOver.jpg");
  preload.push(dteenergySitePrefix+"/images/buttons/searchClearUp.jpg");

  preload.push(dteenergySitePrefix+"/images/homePage/rollOverMainPgSubBg.jpg");
  preload.push(dteenergySitePrefix+"/images/homePage/rollOverMainPgSubNav.jpg");
  preload.push(dteenergySitePrefix+"/images/homePage/ResMainPg_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/homePage/BusinessMainPg_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/homePage/DTEcoMainPg_btnOver.jpg");

  preload.push(dteenergySitePrefix+"/images/navigation/aboutDTE_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/aboutDTE_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/aboutDTE_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/billing_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/billing_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/billing_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/busCustomers_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/busCustomers_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/busCustomers_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/careers_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/careers_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/careers_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/community_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/community_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/community_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/contactUs_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/contactUs_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/contactUs_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/DTEcompany_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/DTEcompany_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/DTEcompany_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/economicDev_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/economicDev_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/economicDev_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/environment_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/environment_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/environment_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/investors_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/investors_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/investors_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/lrgBusinesses_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/lrgBusinesses_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/lrgBusinesses_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/myAccount_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/myAccount_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/myAccount_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/newsRoom_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/newsRoom_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/newsRoom_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/problemsSafety_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/problemsSafety_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/problemsSafety_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/products_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/products_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/products_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/resCustomers_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/resCustomers_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/resCustomers_btnUp.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/saveEnergy_btnDown.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/saveEnergy_btnOver.jpg");
  preload.push(dteenergySitePrefix+"/images/navigation/saveEnergy_btnUp.jpg");

  preload.push(dteenergySitePrefix+"/images/landingPages/residentialMain.jpg");
  preload.push(dteenergySitePrefix+"/images/landingPages/businessMain.jpg");
  preload.push(dteenergySitePrefix+"/images/landingPages/stormResMain.jpg");
  
  var ctr=0;
  for(ctr; ctr<preload.length; ctr++)
  {
    jQuery("#bottomImgPreload").append("<img class='preloadedImg' src='" + preload[ctr] + "'/>");
  }

}

