(function( $ ){
  
    var methods = {
      init : function( options ) { 
        //try {console.log('=== jquery.vfsbanner.js : init ===');} catch(e){}
 
        var defaultSettings = {
              autoPlay: true,
              allowMinimize: true,
              maxSlides: 10, 
              banner: '.banner',
              slides: '#banners',
              nextTrig: '.slider_arrow_right',
              prevTrig: '.slider_arrow_left',
              minTrig: '.slider_arrow_min',
              maxTrig: '.slider_arrow_max', 
              slideHeightMax: '261px',
              slideHeightMin: '26px',
              slideSpeed: 600,
              selector: '.slider_selector' 
        };
        var o =  $.extend(defaultSettings, options);
    
        return this.each(function() {
          //var o = options;
          //try {console.dir(o);} catch(e){};  
          
          var $this = $(this);
          
          
          // Set Initial State
          var currentBannerState = $.cookies.get("bannerState");
          //try {console.log("currentBannerState is: %s.",currentBannerState);} catch(e){};
          if (currentBannerState) {          
            //try {console.log("initial banner state is: %s.",uiStateData.banner);} catch(e){};
            if (currentBannerState === 'closed') {
              var customSettings = {};              
              var tempOptions = {slideSpeed:0};
              //var settings = $.extend(empty, defaultSettings, tempOptions);
              $.extend(customSettings, defaultSettings, tempOptions);
              methods.minimize(customSettings);
            }
          }
          
          // do rest of init when page loads
          $(document).ready(function() {
              
            //Load DD Slider
            $(o.slides).DDSlider({
              nextSlide: o.nextTrig,
              prevSlide: o.prevTrig,
              selector: o.selector,
              waitTime: 10000,
              duration: 1000
            });
            // Hover state (show left/right/min arrows)
            $this.hover(function () {
              $(o.prevTrig).fadeIn("fast");
              $(o.nextTrig).fadeIn("fast");
            }, function () {
              $(o.prevTrig).fadeOut("fast");
              $(o.nextTrig).fadeOut("fast");
            });
            //bind click,mouseover/out handlers to min/max triggers
            $(o.minTrig).click(function (event) {
               methods.minimize(o);
               methods.setuiState("closed");
               event.stopPropagation();
            });
            $(o.maxTrig).click(function (event) {
               methods.maximize(o);
               methods.setuiState("open");
               event.stopPropagation();
            });
            // just kill propogation for ddslider buttons... 
            $(".slider_selector").click(function (event) {
               event.preventDefault();
            });
             $(".slider_arrow_left").click(function (event) {
               event.stopPropagation();
            });
             $(".slider_arrow_right").click(function (event) {
               event.stopPropagation();
            });
             
          });
          
        });
      },

      minimize : function(options) {
        var o = options;
        //try {console.log(o);} catch(e){};
        //try {console.log(this);} catch(e){}; this = clicked div object duh
        
        $(o.minTrig).hide(0);
        $(o.maxTrig).show(0);        
        $(o.banner).animate({
            "height": o.slideHeightMin
          }, {
          duration: o.slideSpeed,
          specialEasing: {
            height: "easeInCubic"
          },
          complete: function() {
            $(o.banner).addClass("minimized");
          }
        });
      },
      
      maximize : function(options) {
        var o = options;
        $(o.banner).removeClass("minimized");
        $(o.maxTrig).hide(0);
        $(o.minTrig).show(0);
        $(o.banner).animate({
          "height": o.slideHeightMax
        }, {
          duration: o.slideSpeed,
          specialEasing: {
            height: "easeInCubic"
          },
          complete: function() {
            //$(o.minTrig).fadeIn("fast");
          }
        });
    
      },      
      
      setuiState : function(state) {
        //var o = options;
        //try {console.log(o);} catch(e){};
        if($.cookies.test())
        {
        	/* $.cookies.set( 'bannerState', state); */
          $.cookies.set( 'bannerState', state, {domain: '.vfs.com'} );
          var currentState = $.cookies.get( 'bannerState' );
          /* try {console.log("current banner state is now: %s.",currentState);} catch(e){}; */
        }
      }
      
    };
    
    $.fn.VFSBanner = function( method ) {
      
      // Method calling logic
      if ( methods[method] ) {
        return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return methods.init.apply( this, arguments );
      } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.VFSBanner' );
      }    
    
    };
 
 
})( jQuery );


