/* ---------------------------------------------------
CVS: $ $
Title: effectcontroller.js
Copyright: (c) 2010
Author: Phil Renaud - phil@rhinointernet.com
Company: Rhino Internet
Description: Javascript shenanigans for St. Benedict
--------------------------------------------------- */


$(document).ready(function(){

   if ($('body').is('#home')) {
      slider();
   } else {
      breadcrumb();
   } //if home
   //dropcap();
   navsearch();
   loggedin();

   var is_mobile = false;
   is_mobile = (navigator && navigator.platform && navigator.platform.match(/^(iPad|iPod|iPhone)$/));
   if (is_mobile) {
      mobile();
   }; //if is_mobile
   
   $('form[rel=external]').attr('target', '_blank');
   
   if ($.browser.msie && $.browser.version <= 7) {
      // Disable upcoming event links opening a new window (freezes in IE7)
      $('.upcoming_events li a').removeAttr('rel').removeAttr('target');
   }
});






/*==( 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').css({'display': 'block', 'top': '0px'});



looper = setInterval (function(){
   clickedright();
}, 10000); //bigpromotionloop

function clickedright() {
   if ($('.panelcontainer').children('li:last-child').is('.active'))
   {
      $('.panelcontainer').children('.active')
         .removeClass('active')
         .animate( {'opacity': 'hide', 'top': '20px'}
                 , {duration: 1000, easing: 'easeInOutExpo'} )
         .parent('.panelcontainer').children('li:first-child')
            .addClass('active')
            .animate( {'top': '20px'}
                    , 600 )
            .animate( {'opacity': 'show', 'top': '0px'}
                    , {duration: 500, easing: 'easeInOutExpo'} );
   } else {
      $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).next('li').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   }; //if
   $('.goright').unbind();
   $('.goleft').unbind();
   clearInterval(looper);
   looper = setInterval(function() {
      clickedright();
   }, 10000);
   setTimeout(function(){
      clickfunctions();
   }, 1200); //settimeout
   return false;
}; //clickedright


clickfunctions();

}; //slider


function clickfunctions(){

function clickedright() {
   if ($('.panelcontainer').children('li:last-child').is('.active')) {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).parent('.panelcontainer').children('li:first-child').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   } else {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).next('li').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   }; //if
   $('.goright').unbind();
   $('.goleft').unbind();
   clearInterval(looper);
   looper = setInterval(function() {
      clickedright();
   }, 10000);
   setTimeout(function(){
      clickfunctions();
   }, 1200); //settimeout
   return false;
}; //clickedright


$('.goright').click(function(){
   if ($('.panelcontainer').children('li:last-child').is('.active')) {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).parent('.panelcontainer').children('li:first-child').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   } else {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).next('li').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   }; //if
   $('.goright').unbind();
   $('.goleft').unbind();
   clearInterval(looper);
   looper = setInterval(function() {
      clickedright();
   }, 10000);
   setTimeout(function(){
      clickfunctions();
   }, 1200); //settimeout
   return false;
}); //click

$('.goleft').click(function(){
   if ($('.panelcontainer').children('li:first-child').is('.active')) {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).parent('.panelcontainer').children('li:last-child').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   } else {
   $('.panelcontainer').children('.active').removeClass('active').animate({'opacity': 'hide', 'top': '20px'}, {duration: 1000, easing: 'easeInOutExpo'}).prev('li').addClass('active').animate({'top': '20px'}, 600).animate({'opacity': 'show', 'top': '0px'}, {duration: 500, easing: 'easeInOutExpo'});
   }; //if
   $('.goleft').unbind();
   $('.goright').unbind();
   clearInterval(looper);
   looper = setInterval(function() {
      clickedright();
   }, 10000);
   setTimeout(function(){
      clickfunctions();
   }, 1200); //settimeout
   return false;
   
}); //click

}; //clickfunctions

/*==( Breadcrumb )======================================================*/

function breadcrumb() {
   var trails = $('.breadcrumb');
   trails.children('li').each(function(i){
      $(this).addClass('breadcrumb' + (trails.children('li').length - i));
   }); //each
   
   trails.children('li').not(':first-child').not(':last-child').addClass('breadcrumb_budge');
   trails.children('li:first-child').addClass('breadcrumb_first');
   trails.children('li:last-child').addClass('breadcrumb_last');
   
   trails.children('li').children('a').hover(
      function(){}, function(){}
   ); //hover
}; //breadcrumb




/*==( Large Drop Cap for beginning letter )======================================================*/

function dropcap() {
   $('.contentproper').each(function(){
      $(this).children('p').eq(0).fancyletter();
   }); //each
   $('.fancy-letter').each(function(){
      // set min-height of parent <p> to avoid squishing contents below in case of short text
      $(this).parent('p').css('min-height', $(this).outerHeight());
      // move fancy character just outside paragraph
      $(this).parent('p').before($(this));
   }); //each
}; //dropcap


/*==( Seach box in navigation )======================================================*/

function navsearch() {
         $('input.searchbox').focus(function() {
            if( this.value == this.defaultValue ) {
               this.value = "";
            }
         }).blur(function() {
            if( !this.value.length ) {
               this.value = this.defaultValue;
            }
         });
         $('input.emailbox').focus(function() {
            if( this.value == this.defaultValue ) {
               this.value = "";
            }
         }).blur(function() {
            if( !this.value.length ) {
               this.value = this.defaultValue;
            }
         });

}; //navsearch



/*==( Log out )======================================================*/
function loggedin() {
   if (null != readCookie('cpp-global-password')) {
      $('.navigation').append('<li class="loggedin"><a href="#" class="logout">You are logged in - <span>Log Out</span></a></li>');
      $('.logout').click(function() {
         eraseCookie('cpp-global-password');
         window.location.reload();
         return false;
      });
   }
}


/*==( Mobile device shenanigans )======================================================*/

function mobile() {
      $('body').css({'backgroundImage': 'url(/images/mobilebg.jpg)'});
}; //mobile





