(function($) {
    cellars = {
      common: {
        init: function() {
          enquiry_form = new Leads.EnquiryForm();
          $('nav ul li.selected:first').click(function(event) {
              event.preventDefault();
              $('html, body').animate({
                    scrollTop: $('#site-navigation').offset().top
                }, 500);
          });
          if($('.slideshow.simple').length == 1){
            $( window ).load(function(){
              new SlideShow.SimpleShow({slideshow_el:$($('.slideshow.simple').first()), interval : 10000, caption_animation:true});
            });
          }
        }
      },
      home: {
          init: function() { 
              $( window ).load(function(){
                  new SlideShow.SimpleShow({slideshow_el:$($('.slideshow.simple')[0]), interval : 10000, caption_animation:true});
                  new SlideShow.SimpleShow({slideshow_el:$($('.slideshow.simple')[1])});
              });
              
           }
          
       },
      
      leads: {
        init: function() { },
        thankyou: function() {
          redirect = new Common.TimedRedirect({'anchor':'#timed-link'});
        }
      }
      
    };

    UTIL = {
      exec: function( controller, action ) {
        var ns = cellars,
            action = ( action === undefined ) ? "init" : action;

        if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
          ns[controller][action]();
        }
      },

      init: function() {
          var body = document.body,
          controller = body.getAttribute( "data-controller" ),
          action = body.getAttribute( "data-action" );
          UTIL.exec( "common" );
          UTIL.exec( controller );
          UTIL.exec( controller, action );
        }
    };

    $( document ).ready( UTIL.init );
})(jQuery);
