/*
Phil Renaud the mad scientist behind this.
phil@rhinointernet.com
http://rhinointernet.com
*/



$(document).ready(function(){

   if ($('body').is('.home')) {
      slider();
   } else {
//      randomheader();
   } //if home
   memberlogin();
   subnavigation();
   
   if ($('.contentproper').find('table').length) {
   zebra();
   }; //if
   
   if ($('ul.locations').length) {
      locations();
   }; //if

   if ($('body').is('#atmlocator')) {
      $(".fancyboxer").fancybox({
         'titleShow'      : false,
         'transitionIn'   : 'elastic',
         'transitionOut'   : 'elastic'
      });
   }; //if

   if ($('.alert').length) {
      alertstyles();
   }; //if

   if ($('body').is('#checking.personal') || $('body').is('#businesscheckingsavings')) {
      personalchecking();
   }; //if

   headingout();

if ($('body').is('.rates.personal')||$('body').is('.rates.business')){
collapserates();
}; //if
});






/*==( Homepage Animated Slider )======================================================*/

function slider() {

$('#hero').append('<div class="panelnav"></div>');
$('.panelnav').append('<a href="#" class="goleft">Previous</a><a href="#" class="goright">Next</a>');

$('.panelcontainer').children('li:first-child').addClass('active');



looper = setInterval (function(){
   $('.goright').click();
}, 8000); //bigpromotionloop




      //$('#hero').hover(
	  //function(){
      //   clearInterval(looper);
      //}, function(){
      //   looper = setInterval(function() {
      //      $('a.goright').click();
      //   }, 8000);
      //}
	  //); //hover
      






$('.goright').click(function(){
   if ($('.panelcontainer').children('li:last-child').is('.active')) {
   $('.panelcontainer').children('.active').removeClass('active').parent('.panelcontainer').children('li:first-child').addClass('active');
   } else {
   $('.panelcontainer').children('.active').removeClass('active').next('li').addClass('active');
   }; //if
         clearInterval(looper);
         looper = setInterval(function() {
            $('a.goright').click();
         }, 8000);
$('.panelcontainer').animate({'left': -$('.panelcontainer').children('li.active').position().left}, {duration: 1000, easing: 'expoinout'});
   return false;
}); //click


$('.goleft').click(function(){
   if ($('.panelcontainer').children('li:first-child').is('.active')) {
   $('.panelcontainer').children('.active').removeClass('active').parent('.panelcontainer').children('li:last-child').addClass('active');
   } else {
   $('.panelcontainer').children('.active').removeClass('active').prev('li').addClass('active');
   }; //if
         clearInterval(looper);
         looper = setInterval(function() {
            $('a.goright').click();
         }, 8000);
$('.panelcontainer').animate({'left': -$('.panelcontainer').children('li.active').position().left}, {duration: 1000, easing: 'expoinout'});
   return false;
}); //click


}; //slider


/*==( Client Login )======================================================*/


function memberlogin(){
          $.ajax({  	 
             type: "GET", 	 
             url: "/check_availability.php", 	 
             dataType: "html", 	 
             success: function(pulleddata) { 	 
                $('#header .loader').remove(); 	 
                $('#header').prepend(pulleddata); 	 
$('form.memberlogin').find('input').not('.submitbutton').focus(function(){
   if (this.value == this.defaultValue) {
      this.value = "";
   }; //if
}).blur(function(){
   if (!this.value.length) {
      this.value = this.defaultValue;
   }; //if
}); 
             } //success 	 
          }); //ajax 	 

}; //memberlogin








/*==( Random Header for Interior Pages )======================================================*/

function randomheader() {
howmanyarethere = 4;
   therandomnumber=Math.floor(Math.random()*howmanyarethere)+1;
$('#hero').css({'backgroundImage': 'url(/images/intheader'+therandomnumber+'.jpg)'});

}; //randomheader





/*==( Subnavigation Highlighting )======================================================*/

function subnavigation(){
$('.minor1').find('a').each(function(){
whereami = window.location.pathname;
if ($(this).attr('href') == whereami) {
$(this).addClass('active');
}; //if
}); //each a
}; //subnavigation





/*==( Alternating Table Row Background Colours )======================================================*/

function zebra(){
   if (!$('body').is('#holidayclosures')) {
      $('.contentproper').find('table').each(function(){
         $(this).children('tbody').children('tr').children('th').parent('tr').addClass('bigfish');
         $(this).children('tbody').find('th:odd').parent('tr').addClass('odd').nextUntil('.bigfish').addClass('oddish');
   
         if ($(this).children('tbody').children('tr').children('th').length) {
         } else {
            $(this).children('tbody').children('tr:odd').addClass('odd');
         }; //if
      }); //each
   } else {
      $('.contentproper table').find('table').each(function(){
         $(this).children('tbody').children('tr').children('th').parent('tr').addClass('bigfish');
         $(this).children('tbody').find('th:odd').parent('tr').addClass('odd').nextUntil('.bigfish').addClass('oddish');
   
         if ($(this).children('tbody').children('tr').children('th').length) {
         } else {
            $(this).children('tbody').children('tr:odd').addClass('odd');
         }; //if
      }); //each
   }; //if holiday closures
}; //zebra






/*==( Alert - page style considerations )======================================================*/

function alertstyles() {
$('.alert').wrap('<div class="alertwrapper"></div>');
$('.alertwrapper').css({'width': $(document).width()-2});
$('.alertwrapper').prependTo('body');
$('body').css({'backgroundPosition': '50% '+($('.alert').height()+21)+'px'});
}; //alert







/*==( Homepage Animated Slider )======================================================*/

function personalchecking() {
$('.contentproper').find('table').find('tr').children('th:nth-child(2)').addClass('onespot');
$('.contentproper').find('table').find('tr').children('td:nth-child(2)').addClass('onespot');

$('.contentproper').find('table').find('tr').children('th:nth-child(3)').addClass('twospot');
$('.contentproper').find('table').find('tr').children('td:nth-child(3)').addClass('twospot');

$('.contentproper').find('table').find('tr').children('th:nth-child(4)').addClass('threespot');
$('.contentproper').find('table').find('tr').children('td:nth-child(4)').addClass('threespot');

$('.contentproper').find('table').find('tr').children('th:nth-child(5)').addClass('fourspot');
$('.contentproper').find('table').find('tr').children('td:nth-child(5)').addClass('fourspot');

}; //personalchecking



/*==( Homepage Animated Slider )======================================================*/

function headingout() {
   $('a[rel=external]').each(function(){
      var whereto = $(this).attr('href');
      if (whereto.substring(0,4) == "http") {
         $(this).addClass('headingout');
      }; //if
   }); // each a rel external
   
   $('a.headingout').click(function(){
$('body').append('<div class="overlay"></div>');
$('.overlay').css({'height': $(document).height()});
   $('body').append('<div class="leaving"><p>You are now leaving First Credit Union\'s website. First Credit Union is not responsible for this site or its content, which is not maintained by First Credit Union.</p><a href="'+$(this).attr('href')+'" class="button peaceout" target="_blank">Continue</a><a href="#" class="closeit">Cancel</a></div>');
//$(window).scrollTop('0px');

   $('.leaving').css({'top': $(window).scrollTop()+250});
$('a.closeit').click(function(){
   $('.overlay').remove();
   $('.leaving').remove();
   return false;
}); //closeit click

$('a.peaceout').click(function(){
   $('.overlay').remove();
   $('.leaving').remove();
}); //closeit click

   return false;
   }); //click


}; //headingout




/*==( Collapse Rates )======================================================*/

function collapserates() {
$('.contentproper').children('h4').css({'marginBottom': '20px', 'textDecoration': 'underline', 'cursor': 'pointer'});
$('.hideaway').hide();

$('.contentproper').children('h4').toggle(function(){
$(this).next('.hideaway').show(500);
}, function() {
$(this).next('.hideaway').hide(500);
});//toggle


}; //collapserates









