$(document).ready(function() {
    // CONFIG:
    // String to prefix to the alt text of the plus / minus button
    var QuestionExpand = 'Maximise answer for:';
    var QuestionMinimised = 'Minimise answer for:';
    // END OF CONFIG:   

    // Show the plus buttons (hidden by default)
    $('.FAQbuttons').show();
    // Hide the answers
    $('.FaqItem .answer').hide();
    // Add a class to change the style of the Question to Closed stated (adds to "FaqItem" class)
    $('.FaqItem').toggleClass("FAQclosed")
    // Dynamic write the alt text to the plus/minus buttons - fetch the text from the question dom and write it to the alt text in the img button.	
    $('.FAQbuttons').each(function() {
        TheQAlt = QuestionExpand + jQuery.trim($(this).text());
        var img = $(this).find("img");
        if (TheQAlt != "") {
            $(img).attr("alt", TheQAlt);
        }
    });
    // add a click event to the open img to allow for expanding
    $('.FAQbuttons').click(function() {
        // Unhide the answer with a slide
        $(this).parent().parent().siblings().find('div.answer').slideUp(200);
        $(this).parent().parent().siblings().find('a').removeClass("white_bg");
        $(this).parent().parent().siblings().addClass("FAQclosed");
        $('.FAQbuttons').each(function() {
            TheQAlt = QuestionExpand + jQuery.trim($(this).text());
            var img = $(this).find("img");
            if (TheQAlt != "") {
                $(img).attr("alt", TheQAlt);
            }
        });

        if (sector) {

            switch (sector) {
                case "bus":
                    $(this).parent().parent().siblings().find('img').attr("src", "/templates/assets/images/ui/faqs_pm_buttons_bus.gif");
                    break;
                case "life":
                    $(this).parent().parent().siblings().find('img').attr("src", "/templates/assets/images/ui/faqs_pm_buttons_life.gif");
                    break;
                default:
                    $(this).parent().parent().siblings().find('img').attr("src", "/templates/assets/images/ui/faqs_pm_buttons_corp.gif");
                    break;
            }
        }

        $(this).find('a').addClass("white_bg");

        $(this).parents('.question').siblings('.answer').slideToggle(200);
        // Togal the FAQ Closed Class (changes the question style)
        $(this).parents('.FaqItem').toggleClass("FAQclosed")
        
        $(this).parent().parent().parent().find('div.FAQclosed a').removeClass('white_bg');
        

        // Change the image in the question box
        var img = $(this).find("img");

        if (sector) {

            switch (sector) {
                case "bus":

                    if ($(img).attr("src") == "/templates/assets/images/ui/faqs_pm_buttons_bus.gif") {
                        $(img).attr("src", "/templates/assets/images/ui/faqs_mp_buttons_bus.gif");

                        // Search and replace for the maxmise and minimise string in alt text
                        $(img).attr("alt", QuestionMinimised + jQuery.trim($(this).text()));
                    } else {
                        // Change the img src
                        $(img).attr("src", "/templates/assets/images/ui/faqs_pm_buttons_bus.gif");
                        // Change the alt text
                        $(img).attr("alt", QuestionExpand + jQuery.trim($(this).text()));
                    }

                    break;
                case "life":

                    if ($(img).attr("src") == "/templates/assets/images/ui/faqs_pm_buttons_life.gif") {
                        $(img).attr("src", "/templates/assets/images/ui/faqs_mp_buttons_life.gif");

                        // Search and replace for the maxmise and minimise string in alt text
                        $(img).attr("alt", QuestionMinimised + jQuery.trim($(this).text()));
                    } else {
                        // Change the img src
                    $(img).attr("src", "/templates/assets/images/ui/faqs_pm_buttons_life.gif");
                        // Change the alt text
                        $(img).attr("alt", QuestionExpand + jQuery.trim($(this).text()));
                    }

                    break;
                default:

                    if ($(img).attr("src") == "/templates/assets/images/ui/faqs_pm_buttons_corp.gif") {
                        $(img).attr("src", "/templates/assets/images/ui/faqs_mp_buttons_corp.gif");

                        // Search and replace for the maxmise and minimise string in alt text
                        $(img).attr("alt", QuestionMinimised + jQuery.trim($(this).text()));
                    } else {
                        // Change the img src
                        $(img).attr("src", "/templates/assets/images/ui/faqs_pm_buttons_corp.gif");
                        // Change the alt text
                        $(img).attr("alt", QuestionExpand + jQuery.trim($(this).text()));
                    }


                    break;
            }
        }


    });
});

    
    
/***********************************************************************************************************
 button script 
 ***************************************************************************************************

$(document).ready( function()
{

      $(".ro").hover(
      function () {$(this).css({ color:"#ffffff"}); }, function () {$(this).css({ color:"#F3C800"}); }
      );    
        $(".ro").focus(
      function () {$(this).css({ color:"#ffffff"}); }, function () {$(this).css({ color:"#F3C800"}); }
      );   
        $(".ro").blur(
      function () {$(this).css({ color:"#F3C800"}); }
      );

      $(".button_g").hover(
      function () {$(this).css({ background:"#ffffff"}); }, function () {$(this).css({ color:"#F3C800"}); }
      );    
        $(".button_g").focus(
      function () {$(this).css({ background:"#ffffff"}); }, function () {$(this).css({ color:"#F3C800"}); }
      );   
        $(".button_g").blur(
      function () {$(this).css({background:"#D1D1D1 url(../images/structure/bg_button_grey.gif) repeat-x scroll 0"}); }
      );          
});


********/



/***********************************************************************************************************
 button script 
 ***********************************************************************************************************/

$(document).ready( function()
{
   PEPS.rollover.init();
});

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
      
      $(".ro").focus(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
      $(".ro").blur(
         //function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
      
   },

   preload: function() {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function(src) {
      if (src.indexOf('_o') == -1) { // If the image is already 'on' then don't add the filename suffix again.
        return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
      } else {
        return src;
      }
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};
















