﻿//  functions.js - general javascript functionality
//  **Uses jquery v1.2.6**

$(function(){


// sIFR Flash Text Replacment functions
    
   
// End of sIFR functions

// FAQ Functions 

    // Initially hide questions and answers
    $(".questions li dd, .questions > ul > li > ul").hide();
    
    $(".questions h3").each( function() {
        $(this).html('<a href="#">' + $(this).text() + '</a>');
    });
    
    $(".questions dt").each( function() {
        $(this).html('<a href="#">' + $(this).html() + '</a>');
    }); 
    
    $(".questions h3").click( function() {
        $(this).parent().toggleClass("open");
        $(this).next().slideToggle("fast");
        return false;
    });
    
    $(".questions dt").click( function() {
        $(this).parent().toggleClass("open");
        $(this).next().slideToggle("fast");
        return false;
    });


// End of FAQ Functions


     $(".disclaimer #close").click(function(){
        window.close();
     });
     
     $(".disclaimer #print").click(function(){
        window.print();
     });


   

    $(".contentBlock > ol").each(function() {
        $("> li", this).each(function(i) {
            $(this).prepend("<span>" + (i + 1) + "</span>");
        });
    });

    

    $(".tip").each(function() {
        $(this).find('.desc').before('<p class="infoLink"><a href="#">View actions</a></p>');

         $("p.infoLink a", this).click(function() {
            $(this).toggleClass("expand").parents(".tip").find(".desc").slideToggle();
            $(this).text($(this).hasClass('expand') ? 'Close actions' : 'View actions');

            return false;
        });
    });
    
    $(".helpFaqs").each(function() {
        $(this).find('.desc').before('<p class="infoLink"><a href="#">View questions and answers</a></p>');

         $("p.infoLink a", this).click(function() {
            $(this).toggleClass("expand").parents(".helpFaqs").find(".desc").slideToggle();
            $(this).text($(this).hasClass('expand') ? 'Close questions and answers' : 'View questions and answers');

            return false;
        });
    });
    
    $(".legalTerms").each(function() {
        $(this).find('.desc').before('<p class="infoLink"><a href="#">View details</a></p>');

         $("p.infoLink a", this).click(function() {
            $(this).toggleClass("expand").parents(".legalTerms").find(".desc").slideToggle();
            $(this).text($(this).hasClass('expand') ? 'Close details' : 'View details');

            return false;
        });
    });
    
    
    $(".subTip").each(function() {
        $(this).html('<a href="#" >' + $(this).html() + '</a>');
    });
            
    $(".subTip a").click(function (){
        $(this).toggleClass("expand").parent().next().slideToggle();
        return false;
    });
        
    
   $(".tip p.infoLink a:first").click();
   $(".tip .subTip a:first").click();
   $(".helpFaqs p.infoLink a:first").click();
   $(".helpFaqs .subTip a:first").click();
   $(".legalTerms p.infoLink a:first").click();
   $(".legalTerms .subTip a:first").click();
   
   
    
    
    $(".newsStory").each(function() {
        $(this).find('.desc').before('<p class="infoLink"><a href="#">Read full article</a></p>');
        $("p.infoLink a", this).click(function() {
            $(this).toggleClass("expand").parents(".newsStory").find(".desc").slideToggle();
            $(this).text($(this).hasClass('expand') ? 'Close article' : 'Read full article');

            return false;
        });
    });


    
    

    $(".tip ol, .newsStory ol").each(function() {
        $("> li", this).each(function(i) {
            $(this).prepend("<span>" + (i + 1) + "</span>");
        });
    });
    
    $(".savingSteps .steps ol li a").click(function() {
        if ($(this).parent().is(".active")) return false;
        $(".savingSteps .tabContent:visible").hide();
        $(".savingSteps li.active").removeClass('active');
        $(this).parent().addClass("active");
        $($(this).attr("href")).show();
        $(this).blur().css('outline','' );
        return false;
    }).mousedown(function() {
        $(this).css('outline','none' );
    })

    var panelID = location.href.match(/#.+$/) || "#panel1";
    $("[href$='"+panelID+"']").click();




    
    $("fieldset .error").append("*").prepend("*");
    
    setGoogleLinks();
    
  });
 
function setGoogleLinks()
{
    var onsiteUrls = location.host + "|" + "\.mandsenergy\.com";
    var downloadDocTypes = "(pdf|doc|docx)$";
    
    var prefix = "";
    var re = null;
    var pageLocation = unescape( location.pathname.replace(/(^\/)|(\/$)/g , "") );
    $("a").each( function(e) {

        var anchor = null;
        var site = new RegExp( onsiteUrls , "ig" );
        var download = new RegExp( downloadDocTypes , "ig" );

        // return for javascript links
        if( this.href.match(/(^javascript)|(^#)/) || !this.href ) return true;

        // mailto
        if( this.href.match(/mailto/ig) )
        {
            prefix = "mailto";
            anchor = this;
        }
        // download
        else if( download.test( this.href ) )
        {
            prefix = "download";
            anchor = this;
        }
        // external link
        else if( !site.test( this.href ) )
        {
            prefix = "external";
            anchor = this;
        }
        
        if( anchor )
        {
            var googleString = prefix + " / " + pageLocation + " / " + this.href.replace(/http[s]*:\/\// , "");
            
            $(anchor).click(function() {
//                console.info( googleString );
//                return false;
                pageTracker._trackPageview( googleString );
            });
        }
    
    });
}


/*OLD SIFR*/
// $(function(){
//     //sIFR.replaceElement(named({sSelector:"body .mainContent .content>h1, body .mainContent>h1, body .siteInfoContent .mainContent h1, body .formContent>h1, body .disclaimer h1,body #aboutContent h1,body #sitemapContent h1, body #contactContent h1, body #pageContent .calcInner h1", sFlashSrc:"/js/sifr/helveticathinh1.swf", sColor:"#7DB956", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
//     sIFR.replaceElement(named({sSelector:".introduction h1", sFlashSrc:"/js/sifr/helveticathinh1.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
//    
//    //sIFR.replaceElement(named({sSelector:"body .topic h2, body .savingsCompare h2, body .formContent h2.stage", sFlashSrc:"/js/sifr/helveticathin.swf", sColor:"#333333", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#666666", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
// 
// });


  var SSETitle = {
    src: '/js/sifr/Helvetica-LT-45-Light.swf'
      , ratios: [7, 1.32, 11, 1.31, 19, 1.23, 27, 1.2, 28, 1.18, 29, 1.19, 37, 1.18, 41, 1.17, 42, 1.18, 57, 1.17, 62, 1.16, 63, 1.17, 89, 1.16, 90, 1.15, 95, 1.16, 97, 1.15, 100, 1.16, 104, 1.15, 106, 1.16, 111, 1.15, 112, 1.16, 118, 1.15, 119, 1.16, 1.15]
    };
 
  sIFR.useStyleCheck = true;
  sIFR.activate(SSETitle);
  
  sIFR.replace(SSETitle, {
    selector: '.contactUs h3, .vouchers h3, .enegrySurvey h3 , .mainContent h1, .formContent h1, h1, body .formContent h2.stage, .news div h3, .paperlessBilling h3, .testimonials h3, .latestNews h3,.switchEnergy h3 , .savingSteps h2', wmode:'transparent' 
    ,wmode:'transparent' 
    ,css: [
        '.sIFR-root { text-align: left; font-weight: bold; }'
        ,'a { text-decoration: none; text-align: left;}'
        ,'a:link { color: #000000; }'
        ,'a:hover { color: #000000; text-decoration: underline;}'
      ]
  });
  
    sIFR.replace(SSETitle, {
    selector: '.savingsCalculator h3'
    ,wmode:'transparent' 
    ,css: [
        '.sIFR-root { text-align: left; font-weight: bold; }'
        ,'a { text-decoration: none; text-align: left;}'
        ,'a:link { color: #cbd300; }'
        ,'a:hover { color: #cbd300; text-decoration: underline;}'
      ]
  });
  
  
  
  