if(typeof Common == 'undefined') {
    var Common = {};
};

Common.TimedRedirect = function(options) {
    this.options  = jQuery.extend({}, this.default_options, options);
    this.init();
};

(function($) {
    Common.TimedRedirect.prototype = {
        default_options: {
            time : 5000
        },
        init : function(){
            this.anchor = $(this.options.anchor)
            this.href = this.anchor.attr('href');
            this.time = this.options.time;   
            setTimeout( $.proxy(function() {  window.location = this.href;  },this), this.time)
        }
    }
    
})(jQuery);

if(typeof Leads == 'undefined') {
    var Leads = {};
};

Leads.EnquiryForm = function(elements) {
    this.elements = jQuery.extend({}, this.default_elements, elements);
    this.init();
};

(function($) {
    
    Leads.EnquiryForm.prototype = {
        default_elements : {
            form_id                 : '#storelocator',
            email_input_id          : '#id_email',
            full_name_id            : '#id_full_name',
            required_field_class    : '.requiredField'
        },
        init : function() {
            $('.requiredField').next('input').addClass('required');
            $('#id_email').addClass('validateEmail');
            $('#id_full_name').addClass('validateFullName');
            $('form.uniForm').uniform({
                prevent_submit:true, 
                prevent_submit_callback:this.prevent_submit_callback
            }); 
        },
        prevent_submit_callback: function(form, title){
              $('html, body').animate({
                  scrollTop: form.offset().top
              }, 500);
              
              return false;
          }
      }

})(jQuery);


if(typeof SlideShow == 'undefined') {
    var SlideShow = {};
};
SlideShow.SimpleShow = function(options) {
    this.options = jQuery.extend({}, this.default_options, options);
    this.init();
};
(function() {
    SlideShow.SimpleShow.prototype = {
        default_options: {
           slideshow_el   : $('.SlideShow').first(),
           interval : 5000,
           fade_duration: 1000,
           caption_animation: false
        },
        init : function(){
           this.slideshow = this.options.slideshow_el;
           this.slides = this.slideshow.find('li');
           this.set_current_slide(this.slides.first());
           this.slideshow.height(this.current_slide.height());
           this.slideshow.addClass('activated');
           this.iterate();
           $(window).blur($.proxy(function() {
               clearTimeout(this.timer);
           },this)).focus($.proxy(function() {
               this.iterate();
           },this));
        },
        set_current_slide : function(slide){
            if(typeof this.current_slide != 'undefined'){
                this.prev_slide = this.current_slide;
                this.prev_slide.fadeOut({'duration':this.options.fade_duration});
            }
            this.current_slide = slide;
            //this.slideshow.height(this.current_slide.height());
            this.slides.removeClass('current');
            this.current_slide.fadeIn({'duration':this.options.fade_duration});
            if(this.options.caption_animation){
                this.current_slide.find('.caption').each(
                    function(){
                        el = $(this);
                   
                        if(typeof el.data('full_width') == 'undefined'){
                            el.data('full_width',el.width());
                        }
                        el.css({ width: 1, opacity:0 }).delay(1300).animate({width:el.data('full_width'), opacity:0.9}, 200);
                    
                    }
                )
            }
            
            
        },
        next : function(iterate){
            
            next_slide = this.slides.first()
            if(this.current_slide.next().length > 0){
                next_slide = this.current_slide.next();
            }
            if($(window).focus){
                this.set_current_slide(next_slide);
            }
            if(iterate == true){
                this.iterate()
            }
        },
        prev : function(){
            prev_slide = this.slides.last()
            if(this.current_slide.prev().length > 0){
                prev_slide = this.current_slide.prev();
            }
            if($(window).focus){
                this.set_current_slide(next_slide);
            }
            
        },
        iterate : function(){
            if (this.slides.length > 1){
                this.timer = setTimeout( $.proxy(function() {  this.next(true);  },this), this.options.interval);
            }
        }
        
    }
})();

