
/*  --------------------------------------------    
    core.js
    com.pushhere.www
    regi e.(regi@pushhere.com, Lead Dev)
    - Requires(Location):
      [mootools-core.js]
      (script/core.js)
    --------------------------------------------  */
    
    
    
/*  Class: SimpleCarousel
    ----------------------------------------------  */
    var SimpleCarousel = new Class({
        Implements: [Options, Events],
        options: {
            slideInterval: 4000,
            transitionDuration: 700,
            startIndex: 0,
            buttonOnClass: "selected",
            buttonOffClass: "off",
            rotateAction: "none",
            rotateActionDuration: 100,
            autoplay: true
        }, initialize: function (container, slides, buttons, options) {
            this.container = document.id(container);
            var instance = this.container.retrieve('SimpleCarouselInstance');
            if (instance) return instance;
            this.container.store('SimpleCarouselInstance', this);
            this.setOptions(options);
            this.container.addClass('hasCarousel');
            this.slides = $$(slides);
            this.buttons = $$(buttons);
            this.createFx();
            this.showSlide(this.options.startIndex);
            if (this.options.autoplay) this.autoplay();
            if (this.options.rotateAction != 'none') this.setupAction(this.options.rotateAction);
            return this;
        }, toElement: function () {
            return this.container;
        }, setupAction: function (action) {
            this.buttons.each(function (el, idx) {
                document.id(el).addEvent(action, function () {
                    this.slideFx.setOptions(this.slideFx.options, {
                        duration: this.options.rotateActionDuration
                    });
                    if (this.currentSlide != idx) this.showSlide(idx);
                    this.stop();
                }.bind(this));
            }, this);
        }, createFx: function () {
            if (!this.slideFx) this.slideFx = new Fx.Elements(this.slides, {
                duration: this.options.transitionDuration
            });
            this.slides.each(function (slide) {
                slide.setStyle('opacity', 0);
            });
        }, showSlide: function (slideIndex) {
            var action = {};
            this.slides.each(function (slide, index) {
                if (index == slideIndex && index != this.currentSlide) {
                    if (document.id(this.buttons[index])) document.id(this.buttons[index]).swapClass(this.options.buttonOffClass, this.options.buttonOnClass);
                    action[index.toString()] = {
                        opacity: 1
                    };
                } else {
                    if (document.id(this.buttons[index])) document.id(this.buttons[index]).swapClass(this.options.buttonOnClass, this.options.buttonOffClass);
                    action[index.toString()] = {
                        opacity: 0
                    };
                }
            }, this);
            this.fireEvent('onShowSlide', slideIndex);
            this.currentSlide = slideIndex;
            this.slideFx.start(action);
            return this;
        }, autoplay: function () {
            this.slideshowInt = this.rotate.periodical(this.options.slideInterval, this);
            this.fireEvent('onAutoPlay');
            return this;
        }, stop: function () {
            $clear(this.slideshowInt);
            this.fireEvent('onStop');
            return this;
        }, rotate: function () {
            var current = this.currentSlide;
            var next = (current + 1 >= this.slides.length) ? 0 : current + 1;
            this.showSlide(next);
            this.fireEvent('onRotate', next);
            return this;
        }
    });


/*  Class: landingPage
    ----------------------------------------------  */    
    var landingPage = new Swiff('/static/uploads/pages/images/home_animation.swf', {
        id: 'animation',
        width: '100%',
        height: '308',
        style: 'visibility: visible',
        container: $('section-header'),
            params:  {
                bgcolor: '#ffffff',
                allowScriptAccess: 'always',
                quality: 'high',
                wMode: 'opaque',
                scale: 'noscale',
                menu: 'false',
                swLiveConnect: 'false'
            }
    });
    
    
/*  Object: InputWaterMark
    ----------------------------------------------  */;
    function InputWaterMark() {

      this.collection = function(elements) {
        for (var i=0, len = elements.length; i < len; i++) {
          elements.store('value' + [i], elements.get('value'));

          elements.addEvents({
            'focus': function() {
              if (this.get('value') == 'Email Address') {
                this.set('value', '');              
              };
            },
            'blur': function() {
              if (this.get('value') == '') {
                this.set('value', 'Email Address');              
              };
            }
          });
          
        };
      }
    }
    
    InputWaterMark.prototype = {
      
      init: function(elements) {
        this.elements = $$(elements);
        this.collection(this.elements);
      }
    }
    
    var newsletter = new InputWaterMark();
    
    
 
/*  Ready()
    -----------------------------------------------  */
    window.addEvent('domready', function() {
       landingPage.replaces($('animation'));
       if (!$('default-image')) {
	       new SimpleCarousel($('partner-images'), $$('#partners-section .mask img'), {
	        slideInterval: 2000
	       });
	       newsletter.init('#newsletter input');              	
       };

    });
    

