
jQuery.cookie=function(key,value,options){if(arguments.length>1&&String(value)!=="[object Object]"){options=jQuery.extend({},options);if(value===null||value===undefined){options.expires=-1;}
if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days);}
value=String(value);return(document.cookie=[encodeURIComponent(key),'=',options.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
options=value||{};var result,decode=options.raw?function(s){return s;}:decodeURIComponent;return(result=new RegExp('(?:^|; )'+encodeURIComponent(key)+'=([^;]*)').exec(document.cookie))?decode(result[1]):null;};;
(function ($) {

  Drupal.behaviors.richard_remiard_2011_1 = {
    attach: function(context, settings) {
    
    $.fn.changeBG = function(bg_image, page_container) { 
      $(this).fadeOut(1500, function(){
        $(this).attr('src', bg_image).hide();
        //$(this).css('width', '100%');
        //$(this).css('height', '100%');
        $(this).imagesLoaded(function(){
          if(page_container){
            page_container.fadeIn(1500);
          }
          $(this).fadeIn(1500);
        });
        
      });
    }
    
    var body = $('body');
    var bg_image = '';
    var classes = '';
    //var date = new Date();
    //var date = date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));

    //get the active image
    var active = $('#block-views-home-page-gallery-block .view-content').children().filter(':first');
    
    
    
    if(!body.hasClass('rr2011-bg-processed')){
      body.append('<div id="background-image"><img class="background" src="' + Drupal.settings.basePath + 'sites/all/themes/richard_remiard_2011/images/background-image.png" /></div>');
      
      var background = $('#background-image img.background');
      var page_container = $('body .panel .container');
      
      if ($('body').hasClass('front')){
        /* page_container.fadeIn(1500); */
        
        setTimeout(function(){
        
          $('.fp-logo').fadeIn(1500);
          
          active.removeClass('active');
          
          // if this is the last item in the row, start at the beginning
          if(active.hasClass('views-row-last')){
            var next = active.siblings().filter(':first').addClass('active');
          }else{
            // get the next image
            var next = active.next().addClass('active');
          }
          
          //get the background image href
          //bg_image = 'url(' + next.find('a').attr('href') + ')';
          bg_image = next.find('a').attr('href');
          
          //set the background image
          background.changeBG(bg_image);
         
          //set the next image to the active image
          active = next;
          
          setInterval(function(){
            //remove the active class from $(this)
            active.removeClass('active');
          
            // if this is the last item in the row, start at the beginning
            if(active.hasClass('views-row-last')){
              var next = active.siblings().filter(':first').addClass('active');
            }else{
              // get the next image
              var next = active.next().addClass('active');
            }
          
            //get the background image href
            //bg_image = 'url(' + next.find('a').attr('href') + ')';
            bg_image = next.find('a').attr('href');
            
            //set the background image
            background.changeBG(bg_image);
          
            //set the next image to the active image
            active = next;
  
          }, 5000);
          
        }, 1500);
        
      } else {
        //find the children of the gallery block
        var choices = $('#block-views-home-page-gallery-block .view-content').children();
      
        //choose a random number less than or equal to the length of the choices possible.
        randno = Math.floor ( Math.random() * choices.size() );
      
        //setup our new choice
        var choice = choices.eq(randno);
      
        //set the background image    
        //bg_image = 'url(' + choice.find('a').attr('href') + ')';
        bg_image = choice.find('a').attr('href');
        
        background.changeBG(bg_image, page_container);

      }
      
     /*
 if(!$.cookie("richard_remiard_bg")){
        //if no cookie is set, get the first element and make it the background.
        var first_image = $('#block-views-home-page-gallery-block .views-row-first a');
        $('#block-views-home-page-gallery-block .views-row-first').addClass('active');
        $.cookie("richard_remiard_bg", "views-row-1", { path: "/", expires: date });
        bg_image = 'url(' + first_image.attr('href') + ')';
        
        background.changeBG(bg_image);
      }else{
        $('#block-views-home-page-gallery-block .' + $.cookie("richard_remiard_bg")).addClass('active');
        bg_image = 'url(' + $('#block-views-home-page-gallery-block .' + $.cookie("richard_remiard_bg") + ' a').attr('href') + ')';
        background.changeBG(bg_image);
      }
*/
      
      body.addClass('rr2011-bg-processed');
    }
    
    
   /*
 $('#block-views-home-page-gallery-block .views-row a').click(function(){
      
      //get the parents of the clicked image
      var parent = $(this).parents('.views-row');
            
      //remove any active classes from other images
      parent.nextAll().removeClass('active');
      parent.prevAll().removeClass('active');
      
      //add the active class to the $(this)'s parent
      parent.addClass('active');
      
      //get the current classes of $(this) element.
      classes = parent.attr('class');
      
      //alert(classes);
      var myClasses = classes.split(' ');
      
      $.cookie("richard_remiard_bg", myClasses[1], { path: "/", expires: date });
      
      bg_image = 'url(' + $(this).attr('href') + ')';
      $('#background-image').changeBG(bg_image);
      
      return false;
    });
*/
    

    
    
    
    
    $('body.front').click(function(){
      //console.log(Drupal);
      //window.location = Drupal.settings.basePath + 'about';
      $('body .panel .container').fadeOut('slow', function(){
        $('#nav-bar').fadeIn(1500);
        $('#footer').fadeIn(1500);
      });
      
    });    
              
    }
  };

})(jQuery);

//if($.cookie("stivers_splash") == "one"){
//$.cookie("stivers_splash", "one", { path: "/", expires: date });
//;
(function ($) {

$(document).ready(function() {

  // Accepts a string; returns the string with regex metacharacters escaped. The returned string
  // can safely be used at any point within a regex to match the provided literal string. Escaped
  // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded
  // in this function as it's used to separate the domains names.
  RegExp.escapeDomains = function(text) {
    return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : '';
  }

  // Attach onclick event to document only and catch clicks on all elements.
  $(document.body).click(function(event) {
    // Catch the closest surrounding link of a clicked element.
    $(event.target).closest("a,area").each(function() {

      var ga = Drupal.settings.googleanalytics;
      // Expression to check for absolute internal links.
      var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i");
      // Expression to check for special links like gotwo.module /go/* links.
      var isInternalSpecial = new RegExp("(\/go\/.*)$", "i");
      // Expression to check for download links.
      var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i");
      // Expression to check for the sites cross domains.
      var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i");

      // Is the clicked URL internal?
      if (isInternal.test(this.href)) {
        // Is download tracking activated and the file extension configured for download tracking?
        if (ga.trackDownload && isDownload.test(this.href)) {
          // Download link clicked.
          var extension = isDownload.exec(this.href);
          _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]);
        }
        else if (isInternalSpecial.test(this.href)) {
          // Keep the internal URL for Google Analytics website overlay intact.
          _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]);
        }
      }
      else {
        if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) {
          // Mailto link clicked.
          _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]);
        }
        else if (ga.trackOutbound && this.href) {
          if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
            // Top-level cross domain clicked. document.location is handled by _link internally.
            _gaq.push(["_link", this.href]);
          }
          else if (ga.trackOutboundAsPageview) {
            // Track all external links as page views after URL cleanup.
            // Currently required, if click should be tracked as goal.
            _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]);
          }
          else {
            // External link clicked.
            _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]);
          }
        }
      }
    });
  });
});

})(jQuery);
;

