var vbNavigation = Class.create();

vbNavigation.prototype = {

   // initialize()
     // Constructor runs on completion of the Page loading.        //

      initialize: function() {

      this.activeQuestion = null;
      this.questionCount = 0;
      this.timeout = null;
      this.animateSpeed = 0.1;
      this.imgNum = 0;
      this.fadeRunning = 0;
      this.slideRunning = 0;
      this.eventCarouselHTML = "";
      this.carouselInterval = 5000;
      this.currentFNItem = 0;
      this.currentEvent = 1;
      this.eventCarouselCount = 0;
      eventSlideRunning = false;
      FNFadeRunning = false;

      this.enhanceHomepage();
      this.processQAs();
      this.findPopups();
      this.findCTARollovers();
      this.findSignin();
      this.enableCarousel();
      this.findPayPal();

   },

       findSignin: function() {
       
          if($('signin')) {
             this.activateSignin($('signin'))
          }       
       },
       
       
       activateSignin: function(element) {
       
          Event.observe(element,'click', this.storeSigninLocation.bindAsEventListener(this));
          element.writeAttribute("onclick", "return false");
       },
       
       storeSigninLocation: function() {

   
          thisUrl = location.href;
          this.deleteCookie('signinLocation');
          this.setCookie('sigininLocation',thisUrl);
          redirectUrl = $('signin').href;
          window.location = redirectUrl;
       
       },
   

   findPopups: function() {
   
   var popupItems = $$('a[rel^=popup]');

      popupItems.each(function(s) {
         this.activatePopup(s);
      }.bind(this));
   },
   
   activatePopup: function(element) {
   
      popupAttr = this.extractPopupAttributes(element);
      popupUrl = element.href;
      popupId = element.id+"-popup";
      var onClickCode = element.readAttribute("onclick");

      Event.observe(element,'click', function(event){
        try {
            eval(onClickCode);
        } catch(err) {
            eval(onClickCode.replace(new RegExp("return\s+\w*;?"),""));
        }
      });

      element.writeAttribute("onclick", "return false");
      Event.observe(element,'click', function(event){Event.stop(event);});
      Event.observe(element,'click', this.openPopup.bindAsEventListener(this, popupUrl, popupId, popupAttr));
   },
   
   extractPopupAttributes: function(id) {

      popupStr = $(id).rel;
      popupStrSpl = popupStr.split("[");
      popupStrSpl = popupStrSpl[1].split("]");
      popupAttr = popupStrSpl[0].split(",");

      return popupAttr;
   },

   closePopup: function() {

      if (this.NewWin && (! this.NewWin.closed)) {
             this.NewWin.close ();
        } else {
             return false;
        }
   },
   
   openPopup: function(e, url,WinName,attr) {

      this.closePopup();

      // Set defaults according to the old function's settings
      var defaultParamObj = {
         resizable:'yes',
         toolbar:'no',
         scrollbars:'yes',
         menubar:'yes',
         status:'yes'
         }
      var params = ",";

      if(attr[2]) { // Checks to see if the fifth parameter exists
         var obj    = attr[2];
         for (var prop in obj) { //Loops through the values in the object
            defaultParamObj[prop] = obj[prop];  // replace defaults as necessary
         }
      }

      for (var defaultProp in defaultParamObj) {
         params+= defaultProp +"=" + defaultParamObj[defaultProp] +","; //rewrites the object in the correct string format
      }

      params = params.substring(0,params.length-1); //remove the comma at the end of the string

      var winl = (screen.width - attr[0]) / 2;
      var wint = (screen.height - attr[1]) / 2;
      winprops = 'height='+attr[1]+',width='+attr[0]+',top='+wint+',left='+winl+params;

      this.NewWin = window.open(url,'popup',winprops);
      this.NewWin.focus();
     
   },

   findCTARollovers: function() {

      var ctaItems = $$('a[rev^=rollover]');
      if(ctaItems.length > 0) {
         ctaItems.each(function(s) {
            this.activateCTA(s);
         }.bind(this));
      }         
   },
   
   activateCTA: function(element) {
   
      imageSrc = element.down().src;
      imageOverUrl = this.extractCTARolloverUrl(element);
      this.preloadImage(imageOverUrl);
   
      Event.observe(element,'mouseover',this.mouseoverCTA.bindAsEventListener(this, element));
      Event.observe(element,'mouseout',this.mouseoutCTA.bindAsEventListener(this, element, imageSrc));
   },
   
   mouseoverCTA: function(e,id) {
   
         mouseoverUrl = this.extractCTARolloverUrl(id);
         id.down().src = mouseoverUrl;
   },
   
   mouseoutCTA: function(e,id,src) {
   
         id.down().src = src;   
   },
   
   extractCTARolloverUrl: function(id) {
   
         rolloverStr = id.rev;
         rolloverStrSpl = rolloverStr.split("[");
         rolloverStrSpl = rolloverStrSpl[1].split("]");
         return rolloverStrSpl[0];
   },
   
   extractRolloverUrl: function(id) {
   
         rolloverStr = $(id).down().rev;
         rolloverStrSpl = rolloverStr.split("[");
         rolloverStrSpl = rolloverStrSpl[1].split("]");
         return rolloverStrSpl[0];
   },   
   
   processQAs: function() {

      var questions = $$('#content .question, #popup-content .question');
      if(questions.length > 0) {
         questions.each(function(s) {
            this.questionCount++;
            this.hideQAs(s);
            this.idQAs(s);
            this.activateQAs(s);   
         }.bind(this));
      }
   },
   
   
   hideQAs: function(element) {
      element.next(1).setStyle({'display':'none'});
   },
   
   idQAs: function(element) {
      element.writeAttribute("id", "question"+this.questionCount);
      element.next(1).writeAttribute("id", "answer"+this.questionCount);
   },
   
   
   activateQAs: function(element) {
      Event.observe(element,'click',this.actionQA.bindAsEventListener(this, element));   
   },
   
   actionQA: function(e, element) {
      if (element.id != this.activeQuestion && this.activeQuestion) {

         $(this.activeQuestion).next(1).hide();
         $(this.activeQuestion).setStyle({'fontWeight':'bold'});
         $(this.activeQuestion).addClassName('question');
         $(this.activeQuestion).removeClassName('question-over');
      }
   
      if(element.next(1).visible()) {
         element.next(1).hide();
         element.setStyle({'fontWeight':'bold'});
         element.addClassName('question');
         element.removeClassName('question-over');
      
      } else {
         element.setStyle({'fontWeight':'bold'});
         element.next(1).show();
         element.addClassName('question-over');
         element.removeClassName('question');
      }
      this.activeQuestion = element.id;
   },
   
   setCookie: function(name,value) {
   /** 
    *  Sets session cookie of (name,value)
    */ 
      document.cookie = name +"="+ value +";path=/;"
   },

   deleteCookie: function(name) {
   /** 
    *  Deletes session cookie of (name)
    */ 
      document.cookie = name + '=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;';
   },
   
   getCookieValueFromName: function(name) {
   /** 
    *  Returns cookie value from cookie name
    */ 
      var cookies = document.cookie.split(';');
      for(var i = 0; i < cookies.length; i++) {   
         var cookie = cookies[i].split("=");
         if(cookie[0].replace(" ", "") == name) {
            return cookie[1];    
         }
      }
   },

   readCookieValueFromName: function(name) {
   /** 
    *  Returns true if cookie found
    */ 
      var cookies = document.cookie.split(';');
      for(var i = 0; i < cookies.length; i++) {   
         var cookie = cookies[i].split("=");
         if(cookie[0].replace(" ", "") == name) {
            return true    
         }
      }
   },
   
   preloadImage: function(imgUrl) {
   
      imageNumber = "imgpl"+this.imgNum
      imageNumber = new Image();
      imageNumber.src = imgUrl;
      this.imgNum++;
   },

   // Social Bookmarking methods

   findShareLink: function() {
      if($('share-link')) {
         shareLink = $('share-link');
         this.activateShareLink(shareLink)
         this.writeShareElement();
      }
   },

   activateShareLink: function(element) {
      Event.observe(element,'mouseover', this.shareMouseOver.bindAsEventListener(this));
      Event.observe(element,'mouseout', this.shareMouseOut.bindAsEventListener(this));
   },

   shareMouseOver: function() {
      window.clearTimeout(this.shareTimeout)
      $("share-popup").show();
      Event.observe("share-popup",'mouseover',this.sharePopupMouseOver.bind(this));
      Event.observe("share-popup",'mouseout',this.sharePopupMouseOut.bind(this));
   },

   shareMouseOut: function() {
      window.clearTimeout(this.shareTimeout)
      this.shareTimeout = setTimeout(function() { $("share-popup").hide(); }, 1000 )
   },

   writeShareElement: function() {

      var pageUrl   = escape(document.location);
      var pageTitle = document.title;
      buttonPos = $("shareButton").positionedOffset();
      popPosTop = buttonPos[1] + 16
      popPosLeft = buttonPos[0] - 200 + $("shareButton").getWidth()
      var bodyElmt = $$('body')[0];

      // Determine which browser we're in //
      var IE = document.all ? true : false;

      if (IE) {
        bookmarkLink = "<a title='Add this page to your favourites' href='javascript:window.external.AddFavorite(\""+pageUrl+"\", \""+pageTitle+"\")'><img src='images/favourites.gif'>&nbsp;Favourites</a>";
      }else{
        bookmarkLink = "<a title='Add this page to your bookmarks' href='javascript:window.sidebar.addPanel(\""+pageTitle+"\", \""+pageUrl+"\",\"\")'><img src='images/favourites.gif'>&nbsp;Bookmark</a>";
      }

      // Create the content for the popup //
      sharePopupContent  = "<div class='shareColumn'><div>";
      sharePopupContent += "<a title='Post this page to Facebook' href='http://www.facebook.com/sharer.php?u="+pageUrl+"' target='_blank'><img src='images/facebook.gif'>&nbsp;Facebook</a><br />";
      sharePopupContent += "<a title='Post this page to Del.icio.us' href='http://del.icio.us/post?url="+pageUrl+"&title="+pageTitle+"' target='_blank'><img src='images/delicious.gif'>&nbsp;Delicious</a><br />";
      sharePopupContent += "<a title='Post this page to Digg' href='http://digg.com/submit?url="+pageUrl+"&title="+pageTitle+"' target='_blank'><img src='images/digg.gif'>&nbsp;Digg</a>";
      sharePopupContent += "</div></div><div class='shareColumn'><div>";
      sharePopupContent += "<a title='Post this page to Reddit' href='http://reddit.com/submit?url="+pageUrl+"&title="+pageTitle+"' target='_blank'><img src='images/reddit.gif'>&nbsp;Reddit</a><br />";
      sharePopupContent += "<a title='Post this page to Stumbleupon' href='http://www.stumbleupon.com/submit?url="+pageUrl+"&title="+pageTitle+"' target='_blank'><img src='images/stumbleupon.gif'>&nbsp;StumbleUpon</a><br />";
      sharePopupContent += bookmarkLink+"</div></div>";

      var sharePopupContainerElmt = new Element('div', { 'id':'popup-message'}).update(sharePopupContent);
      var sharePopupElmt = new Element('div', { 'id':'share-popup'}).update(sharePopupContainerElmt).hide();
      sharePopupElmt.setStyle({'position':'absolute','top':popPosTop+'px','left':popPosLeft+'px'});

      new Element.insert(bodyElmt, {bottom:sharePopupElmt});
   },

   sharePopupMouseOver: function() {
      window.clearTimeout(this.shareTimeout);
   },

   sharePopupMouseOut: function() {
      window.clearTimeout(this.shareTimeout)
      this.shareTimeout = setTimeout(function() { $("share-popup").hide(); }, 1000 )
   },
   
   // Homepage Carousel //
   enableCarousel: function() {

      this.currentCarouselItem = 0;
      this.carouselItemPos1 = 0;
      this.totalCarouselItems = 0;
      this.leftCarouselArrowEnabled = false;
      this.rightCarouselArrowEnabled = false;
      this.thumbWidth = 80;
      this.duration = 0.5;
      this.autoDuration = 10000;

      if($('homepage-carousel')) {

         carouselItems = $$('.carousel-item');
         totalItems = carouselItems.length;
         this.totalCarouselItems = totalItems;
         this.assignSliderAnchors();
         this.hideCarouselItems();
         $('carousel-slider').style.display = 'block';
         this.updateCarouselArrows(this.carouselItemPos1);
         automate = window.setTimeout(function() { this.automateCarousel() }.bind(this), this.autoDuration);
      }
   },

   hideCarouselItems: function() {
      var carouselItems = $$('.carousel-item');
      $('carousel-container').setStyle({position:'relative'});
      carouselItems.each(function(s,i) {
         s.setStyle({position:'absolute', top:'0px', left:'0px'});
         if (i == 0) {
            s.show();
         }else{
            s.hide();
         }
      });

      $('carouselThumb0').removeClassName('carousel-thumb');
      $('carouselThumb0').addClassName('carousel-thumb-selected');
   },

   changeCarouselItem: function(e, itemNumberToShow) {
      if (this.fadeRunning == 0 && itemNumberToShow != this.currentCarouselItem) {
         window.clearTimeout(automate);
         this.fadeRunning = 1;
         $('carouselThumb'+this.currentCarouselItem).removeClassName('carousel-thumb-selected');
         $('carouselThumb'+this.currentCarouselItem).addClassName('carousel-thumb');
         $('carouselThumb'+itemNumberToShow).removeClassName('carousel-thumb');
         $('carouselThumb'+itemNumberToShow).addClassName('carousel-thumb-selected');

         var carouselItems = $$('.carousel-item');
         new Effect.Fade(carouselItems[this.currentCarouselItem], {duration:this.duration});
         new Effect.Appear(carouselItems[itemNumberToShow], {duration:this.duration, afterFinish:function() {this.fadeRunning = 0;}.bind(this)});
         this.currentCarouselItem = itemNumberToShow;
         automate = window.setTimeout(function() { this.automateCarousel() }.bind(this), this.autoDuration);
      }
   },

   assignSliderAnchors: function() {
      var sliderItems = $$('.carousel-thumb');

      sliderItems.each(function(s,i) {
         Event.observe(s, 'click', this.changeCarouselItem.bindAsEventListener(this,i));
      }.bind(this));
   },

   updateCarouselArrows: function() {
      if (this.carouselItemPos1 > 0) {
         this.toggleLeftCarouselArrow(1);
      }else{
         this.toggleLeftCarouselArrow(0);
      }
      if (this.totalCarouselItems - 5 > this.carouselItemPos1) {
         this.toggleRightCarouselArrow(1);
      }else{
         this.toggleRightCarouselArrow(0);
      }
   },

   toggleLeftCarouselArrow: function(flag) {

      Event.stopObserving($('carousel-left-arrow'));
      if (flag == 0) {
         $('carousel-left-arrow').src = "/giving/Images/slider-left-arrow-off_tcm31-14221.gif";
         $('carousel-left-arrow').removeClassName('carouselArrowEnabled');
         $('carousel-left-arrow').addClassName('carouselArrowDisabled');
         this.leftCarouselArrowEnabled = false;
      }else{
         $('carousel-left-arrow').src = "/giving/Images/slider-left-arrow-on_tcm31-14222.gif";
         $('carousel-left-arrow').removeClassName('carouselArrowDisabled');
         $('carousel-left-arrow').addClassName('carouselArrowEnabled');
         Event.observe($('carousel-left-arrow'),'click',this.moveSlider.bindAsEventListener(this, (this.carouselItemPos1 - 1)));
         this.leftCarouselArrowEnabled = true;
      }
   },

   toggleRightCarouselArrow: function(flag) {

      Event.stopObserving($('carousel-right-arrow'));
      if (flag == 0) {
         $('carousel-right-arrow').src = "/giving/Images/slider-right-arrow-off_tcm31-14223.gif";
         $('carousel-right-arrow').removeClassName('carouselArrowEnabled');
         $('carousel-right-arrow').addClassName('carouselArrowDisabled');
         this.rightCarouselArrowEnabled = false;
      }else{
         $('carousel-right-arrow').src = "/giving/Images/slider-right-arrow-on_tcm31-14224.gif";
         $('carousel-right-arrow').removeClassName('carouselArrowDisabled');
         $('carousel-right-arrow').addClassName('carouselArrowEnabled');
         Event.observe($('carousel-right-arrow'),'click',this.moveSlider.bindAsEventListener(this, (this.carouselItemPos1 + 1)));
         this.rightCarouselArrowEnabled = true;
      }
   },

   moveSlider: function(e, moveToIndex) {

      if (this.slideRunning == 0) {
         this.slideRunning = 1;
         if (moveToIndex > this.totalCarouselItems - 5) {
            moveToIndex = 0;
         }

         moveAmount = (moveToIndex - this.carouselItemPos1) * this.thumbWidth * -1;
         thumbsId = $('thumb-container');
         new Effect.Move(thumbsId, {x:moveAmount,y:0,duration:this.duration, afterFinish:function() {this.slideRunning = 0;}.bind(this)});
         this.carouselItemPos1 = moveToIndex;
         this.updateCarouselArrows();
      }
   },

   automateCarousel: function() {
      moveToItem = this.currentCarouselItem + 1;
      if (moveToItem > this.carouselItemPos1 + 4) {
         this.moveSlider(this, this.carouselItemPos1 + 1);
      }
      if (moveToItem >= this.totalCarouselItems) {
         moveToItem = 0;
      }
      this.changeCarouselItem(this, moveToItem);
   },

   findPayPal: function() {
      if($('paypal') && $('homepage')) {
         this.displayPayPal();
      }
   },

   displayPayPal: function() {
      var paypalContent = "<div id='paypal-link'>";
      paypalContent += "<a href='#' onclick='launchPayPal()'>";
      paypalContent += "<img src='http://www.paypal.com/en_US/i/bnr/bnr_nowAccepting_150x40.gif' border='0' alt='Now accepting PayPal' />";
      paypalContent += "</a></div>";
      $('paypal').innerHTML = paypalContent;
   },

   enhanceHomepage: function() {
      if ($('homepage2011')) {
         $('event-carousel-panel').hide();
         $('fn-carousel-panel').hide();
         this.rebuildPage();
         this.initialiseCarousels();
         $('event-carousel-panel').show();
         $('fn-carousel-panel').show();
         this.processBlogDates();
         this.startCarousels();
      }
   },

   rebuildPage: function() {

      var carouselContent = new Array(6);
      carouselContent[0] = new Array();
      carouselContent[1] = new Array();
      carouselContent[2] = new Array();
      carouselContent[3] = new Array();
      carouselContent[4] = new Array();
      carouselContent[5] = new Array();

      //Rebuild FN Carousel
      for (i=0; i<=3; i++) {
         carouselContent[0][i] = "<div class='fn-carousel-item-image' id='fn-image"+i+"' style='background-image:url("+$('fn-image'+i).src+")'></div>";
         carouselContent[1][i] = "<div class='fn-carousel-item-text'><div class='fn-carousel-item-title'>"+$('fn-title'+i).innerHTML+"</div><div class='fn-carousel-item-desc'>"+$('fn-desc'+i).innerHTML+"</div></div><div class='fn-carousel-item-link'><a href='"+$('fn-link'+i).href+"'><img src='/giving/Images/btn-double-chevron-g_tcm31-23120.gif' alt='Find out more' title='Find out more' /></a></div>";
         carouselContent[2][i] = "<div class='fn-carousel-tab-title'>"+$('fn-title'+i).innerHTML+"</div>";
      }

      for (i=0; i<=3; i++) {
         $('fn-carousel-item'+i).innerHTML = carouselContent[0][i];
         $('fn-carousel-details-item'+i).innerHTML = carouselContent[1][i];
         $('fn-tab'+i).innerHTML = carouselContent[2][i];
      }

      $('fn-tab0').removeClassName('fn-carousel-tab');
      $('fn-tab0').addClassName('fn-carousel-tab-selected');
      $('fn-carousel').removeClassName('fn-carousel-container');
      $('fn-carousel').addClassName('fn-carousel-container-enhanced');

      //Rebuild Event Carousel
      this.eventCarouselCount = $$('.event-carousel-item').length;

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselContent[0][i] = $('event-image'+i).src;
         carouselContent[1][i] = $('event-title'+i).innerHTML;
         carouselContent[2][i] = $('event-title'+i).href;
         carouselContent[3][i] = $('event-what'+i).innerHTML;
         carouselContent[4][i] = $('event-where'+i).innerHTML;
         carouselContent[5][i] = $('event-when'+i).innerHTML;
      }

      carouselHtml = "<div class='carousel-left'></div><div class='event-carousel-body'><div class='event-carousel-title'>";

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselHtml += "<div class='event-item-title' id='event-title"+(i+1)+"'>"+carouselContent[1][i]+"</div>";
      }

      carouselHtml += "</div><div class='event-carousel-slider'><div id='event-carousel-content'>";

      carouselHtml += "<div class='event-item-image'><img src='"+carouselContent[0][this.eventCarouselCount-2]+"' /></div>";
      carouselHtml += "<div class='event-item-image'><img src='"+carouselContent[0][this.eventCarouselCount-1]+"' /></div>";

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselHtml += "<div class='event-item-image'><img src='"+carouselContent[0][i]+"' /></div>";
      }

      carouselHtml += "<div class='event-item-image'><img src='"+carouselContent[0][0]+"' /></div>";
      carouselHtml += "<div class='event-item-image'><img src='"+carouselContent[0][1]+"' /></div>";

      carouselHtml += "</div><div id='event-carousel-control'><div class='event-carousel-left-arrow'><a id='event-carousel-left-arrow'><img src='/giving/Images/carousel-left-arrow_tcm31-23117.png' alt='Previous' title='Previous' /></a></div>";
      carouselHtml += "<div class='event-carousel-right-arrow'><a id='event-carousel-right-arrow'><img src='/giving/Images/carousel-right-arrow_tcm31-23118.png' alt='Next' title='Next' /></a></div></div></div><div class='event-carousel-position'>";

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselHtml += "<img class='event-indicator' id='event-indicator"+(i+1)+"' src='/giving/Images/carousel-indicator_tcm31-23122.gif' />";
      }

      carouselHtml += "</div><div class='event-carousel-details'><div class='event-carousel-detail-labels'><p>What?</p><p>Where?</p><p>When?</p></div><div class='event-carousel-detail-data'>";

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselHtml += "<div id='event-detail"+(i+1)+"'><p>"+carouselContent[1][i]+"</p><p>"+carouselContent[4][i]+"</p><p>"+carouselContent[5][i]+"</p></div>";
      }

      carouselHtml += "</div><div class='event-carousel-detail-link' id='event-link-button'>";

      for (i=0; i<this.eventCarouselCount; i++) {
         carouselHtml += "<div id='event-link"+(i+1)+"'><a href='"+carouselContent[2][i]+"'><img src='/giving/Images/btn-double-chevron-lb_tcm31-23121.gif' alt='Go to event' title='Go to event' /></a></div>";
      }

      carouselHtml += "</div></div></div></div><div class='carousel-right'></div>";

      $('event-carousel').innerHTML = carouselHtml;
      $('event-carousel').removeClassName('event-carousel-container');
      $('event-carousel').addClassName('event-carousel-container-enhanced');
      $('event-indicator'+this.currentEvent).removeClassName('event-indicator');
      $('event-indicator'+this.currentEvent).addClassName('event-indicator-selected');

   },

   initialiseCarousels: function() {

      var carouselItems = $$('.fn-carousel-item');
      carouselItems.each(function(s,i) {
         if (i == 0) {
            $('fn-carousel-item'+i).show();
            $('fn-carousel-details-item'+i).show();
         }else{
            $('fn-carousel-item'+i).hide();
            $('fn-carousel-details-item'+i).hide();
         }
      });

      carouselWidth = (this.eventCarouselCount+4)*140+"px";
      $('event-carousel-content').setStyle({width:carouselWidth});
      for (i=1; i<=this.eventCarouselCount; i++) {
         if (i == 1) {
            $('event-title'+i).show();
            $('event-detail'+i).show();
            $('event-link'+i).show();
            $('event-indicator'+i).src = "/giving/Images/carousel-indicator-selected_tcm31-23123.gif";
         }else{
            $('event-title'+i).hide();
            $('event-detail'+i).hide();
            $('event-link'+i).hide();
         }
      }

      for (i=0; i<=3; i++) {
         Event.observe($('fn-tab'+i),'click',this.changeFNCarousel.bindAsEventListener(this,i));
      }

      Event.observe($('event-carousel-left-arrow'), 'click', this.moveEventSlider.bindAsEventListener(this,1));
      Event.observe($('event-carousel-right-arrow'), 'click', this.moveEventSlider.bindAsEventListener(this,-1));
   },

   startCarousels: function() {
      autoFNCarousel = window.setTimeout(function() {this.changeFNCarousel(this,this.currentFNItem+1)}.bind(this), this.carouselInterval);
      autoEventCarousel = window.setTimeout(function() {this.moveEventSlider(this,-1)}.bind(this), this.carouselInterval);
   },

   changeFNCarousel: function(e,targetFNItem) {

      if (targetFNItem == 4) {
         targetFNItem = 0;
      }
      if (this.currentFNItem != targetFNItem && !FNFadeRunning) {
         FNFadeRunning = true;

         window.clearTimeout(autoFNCarousel);

         new Effect.Fade($('fn-carousel-item'+this.currentFNItem), {duration:0.5});
         new Effect.Fade($('fn-carousel-details-item'+this.currentFNItem), {duration:0.5, afterFinish:function() {new Effect.Appear($('fn-carousel-details-item'+targetFNItem), {duration:0.5, afterFinish:function() {FNFadeRunning = false;}});}});
         $('fn-tab'+this.currentFNItem).removeClassName('fn-carousel-tab-selected');
         $('fn-tab'+this.currentFNItem).addClassName('fn-carousel-tab');

         new Effect.Appear($('fn-carousel-item'+targetFNItem), {duration:0.5});
         $('fn-tab'+targetFNItem).removeClassName('fn-carousel-tab');
         $('fn-tab'+targetFNItem).addClassName('fn-carousel-tab-selected');

         this.currentFNItem = targetFNItem;
         autoFNCarousel = window.setTimeout(function() {this.changeFNCarousel(this,this.currentFNItem+1)}.bind(this), this.carouselInterval);
      }
   },

   moveEventSlider: function(e,slideDir) {

      if (!eventSlideRunning) {
         window.clearTimeout(autoEventCarousel);
         targetEvent = this.currentEvent - slideDir;

         if (targetEvent > this.eventCarouselCount) {
            targetEvent = 1;
            $('event-carousel-content').setStyle({left:"-42px"});
         }else if (targetEvent == 0) {
            targetEvent = this.eventCarouselCount;
            targetSliderPosition = "-"+((this.eventCarouselCount*132)+174)+"px";
            $('event-carousel-content').setStyle({left:targetSliderPosition});
         }

         slideAmount = slideDir * 132;
         eventSlideRunning = true;

         new Effect.Parallel([
            new Effect.Move($('event-carousel-content'), {sync: true, x:slideAmount, y:0, mode:'relative'}),
            new Effect.Fade($('event-title'+this.currentEvent), {sync: true, duration:0.5, afterFinish:function() {new Effect.Appear($('event-title'+targetEvent), {duration:0.5});}}),
            new Effect.Fade($('event-detail'+this.currentEvent), {sync: true, duration:0.5, afterFinish:function() {new Effect.Appear($('event-detail'+targetEvent), {duration:0.5});}}),
            new Effect.Fade($('event-link-button'), {sync: true, duration:0.5, afterFinish:function() {new Effect.Appear($('event-link-button'), {duration:0.5});}})
         ], {
            afterFinish:function() {eventSlideRunning = false;}
         });

         $('event-link'+this.currentEvent).hide();
         $('event-link'+targetEvent).show();

         $('event-indicator'+this.currentEvent).src="/giving/Images/carousel-indicator_tcm31-23122.gif";
         $('event-indicator'+targetEvent).src="/giving/Images/carousel-indicator-selected_tcm31-23123.gif";

         this.currentEvent = targetEvent;
         autoEventCarousel = window.setTimeout(function() {this.moveEventSlider(this,-1)}.bind(this), this.carouselInterval);
      }
   },

   processBlogDates: function() {
      if ($('homepage-blog-panel')) {

         var blogDates = $$('.blog-date');
         var blogTimes = $$('.blog-time');

         for (i=0; i<blogDates.length; i++) {
            blogDates[i].innerHTML = getTimeDiff(blogDates[i].innerHTML, blogTimes[i].innerHTML);
         }
      }
   },

   test: function() {
      alert("Hello");
   }

}

Event.observe(window, 'load', function () {

new vbNavigation();

});
