// var prefix = '';
// prefix = String(document.location.href);
// prefix = prefix.split('/');
// prefix = '/' + prefix[prefix.length-2];
if(!window.cfc) {
    var cfc = {};
}
// cfc.getSite = function() {
//     var d = String(document.domain);
//     if((String(document.location.href)).indexOf('/rtfc') > -1) return 'rtfc';
//     if(d.indexOf('rtfc') > -1) return 'rtfc';
//     return 'cfc';
// }
// cfc.site = cfc.getSite();
if(window.$) {
    $(function() {

        if($.cfc_carousel) {
//            var playCtrl = prefix + '/images/' + cfc.site + '_playCtrl.gif';
//            var pauseCtrl = prefix + '/images/' + cfc.site + '_pauseCtrl.gif';
            $('#c-carousel ul.c-carouselList').cfc_carousel({initCallback:function(c) {
                                                               $('#c-pauseCtrl').click(function(ev) {
                                                                                           $('#c-carouselCtrls').toggleClass('c-carouselPlay').toggleClass('c-carouselPause');
                                                                                           if(c.timer) c.stopAuto();
                                                                                           else c.startAuto();
                                                                                           ev.preventDefault();
                                                                                        });

                                                               $('#c-nextCtrl').click(function(ev) {
                                                                                          c.stopAuto();
                                                                                          c.goNext();
                                                                                          ev.preventDefault();
                                                                                      });

                                                               $('#c-prevCtrl').click(function(ev) {
                                                                                          c.stopAuto();
                                                                                          c.goPrev();
                                                                                          ev.preventDefault();
                                                                                      });
                                                           }});
        }

          $('.c-helper .c-helpLink').hover(function() {
                                             $(this).siblings('.c-toolTip').show();
                                           },
                                           function() {
                                               $(this).siblings('.c-toolTip').hide();
                                           });

          $('#c-mainnav > ul > li:last').addClass('c-lastNavItem');
          $("#c-mainnav ul li").hover(function() {
                                          var ele = $(this);
                                          var ani = ele.data('ani');
                                          function adown(){
                                              clearTimeout(ani);
                                              ani = false;
                                              var par = ele.closest('ul.c-inner'); // second level menu
                                              var ch = par ? ele.children('ul.c-inner') : null;
                                              if(ch) {
                                                  var navItem = par.closest('li.c-lastNavItem'); // the last mainnav item
                                                  if(navItem.length && !ch.hasClass('c-leftItem')) { // move to the left so it's not off the page
                                                      ch.addClass('c-leftItem');
                                                  }
                                              }
                                              //Stop previous animations and drop down the subnav on hover
                                              ele.children("ul.c-inner").fadeIn(200).show();
                                          }
                                          if(ani) {
                                              clearTimeout(ani);
                                          }
                                          ani = setTimeout(adown,150);
                                          ele.data('ani', ani);
                                      },
                                      function() {
                                          var ele = $(this);
                                          var ani = ele.data('ani');
                                          function aup() {
                                              clearTimeout(ani);
                                              ani = false;
                                              //When the mouse hovers out of the subnav, stop previous animations and move it back up
                                              ele.children("ul.c-inner").hide();
                                          }
                                          if(ani) {
                                              clearTimeout(ani);
                                          }
                                          ani = setTimeout(aup, 150);
                                          ele.data('ani', ani);
                                    });
          var cbToggle = $('#c-cbToggle');
          if(cbToggle.length) {
              var cbList = cbToggle.closest('table').find('tbody input[type=checkbox]');
              cbToggle.click(function(ev) {
                                 var cb = $(this);
                                 console.log(cbList);
                                 if(cb.attr('checked')) {
                                     cbList.attr('checked','checked');
                                 } else {
                                     cbList.attr('checked','');
                                 }
                             });
          }

      });
}

//Makes hover and active states for buttons work in IE
$(document).ready(function() {
    //Toggle class for standard button hover state
   $(".c-stdBtn").hover(function() {
     $(this).addClass("c-stdHover");
   },function(){
     $(this).removeClass("c-stdHover");
   });
    //Toggle class for attention button hover state
   $(".c-attnBtn").hover(function() {
     $(this).addClass("c-attnHover");
   },function(){
     $(this).removeClass("c-attnHover");
   });

      
         //Add active class when button pressed
      $(".c-stdBtn").mousedown(function() {
     $(this).addClass("c-stdActive");
     $(this).removeClass("c-stdHover");

   });
         //Remove active class when button is released
      $(".c-stdBtn").mouseup(function() {
     $(this).removeClass("c-stdActive");

   });


         //Add active class when button pressed
      $(".c-attnBtn").mousedown(function() {
     $(this).addClass(".c-stdActive");
     $(this).removeClass(".c-attnHover");

   });
         //Remove active class when button is released
      $(".c-attnBtn").mouseup(function() {
     $(this).removeClass(".c-stdActive");
     

   });

 });