/**
 * default.js
 *
 * Version history (please keep backward compatible):
 * 1.0, 2009-02-26: Cornelius Hansjakob
 *
 * @author Cornelius Hansjakob <cha@massiveart.com>
 * @version 1.0
 */

Default = Class.create({

  initialize: function() {
    this.map = null;
    this.geocoder = null;
    this.marker = null;
    
    this.reValue = false;
    
    this.currQ;
    this.currYear;    
    this.newQ;
    this.newYear;    
    this.currEventCalListId = '';
    this.newEventCalListId = '';
    
    this.bannerCounter = 1;
    this.bannerDirection = 'right';
    this.bannerStop = false;
    
    setTimeout('myDefault.fly();', 5000);
    
    this.initProductOverview();
  },
  
  init: function(){ 
    this.currElement = 'slideshow_' + this.bannerCounter;
    this.newElement = 'slideshow_' + this.bannerCounter;
    
    
    if($('productOverlay')){
      $$('.contentContainer')[0].setStyle({display: 'none'});
      $('footer').setStyle({display: 'none'});
      $('main').setStyle({padding: '0px'});  
    }
    
    setTimeout('myDefault.bannerCarousel()', 3000);
    
    
    /*if($('productOverlay')) {
      var events = ['click', 'mousemove', 'keydown'],
      i = events.length,
      timer,
      delay = 2000,
      logout = function () {
        alert("!");
      },
      reset = function () {
          clearTimeout(timer);
          timer = setTimeout(logout, delay);
      };

      while (i) {
        i -= 1;
        $('productOverlay').addEventListener(events[i], reset, false);
      }
      reset();      
    }*/

  },
  
  fly: function(){
    if($('expressService')){  
      $('expressService').appear({ duration: 0.6 });
      new Effect.Move('expressService', {
        x: 705, y: 0, mode: 'relative',
        transition: Effect.Transitions.sinoidal
      });      
    }
  },
  
  /**
   * bannerCarousel
   */
  bannerCarousel: function(){
    if(this.bannerStop == false){
      
      if($('slideshow_' + this.bannerCounter)){
        this.slideShow();
        setTimeout('myDefault.bannerCarousel()', 3000); 
      }
    }
  },   
  
  /**
   * slideShow
   */
  slideShow: function(){
    currElement = 'slideshow_' + this.bannerCounter;
    newElement = 'slideshow_' + (this.bannerCounter + 1);
    this.bannerSlide(currElement, newElement); 
  },
  
  /**
   * submitForm
   */
  submitForm: function(formId){
    if($(formId)){      
      /**
       * validation
       */
      this.retValue = true;
      
      $$('.mandatory').each(function(element){
        this.validateInput(element.id);
        if(element.id == 'email'){
          this.validateInputEmail(element.id);
        }
      }.bind(this)); 
      
      if(this.retValue == true) {	      
	      /*var serializedForm = $(formId).serialize();
	      
	      new Ajax.Request($(formId).readAttribute('action'), {
	        parameters: serializedForm,
	        evalScripts: true,
	        onComplete: function(transport) {         
	           
	        }.bind(this)
	      });*/
        $(formId).submit();
	    }else{
	      
	    }
    }
  },
  
  /**
   * validateInput
   */
  validateInput: function(element, baseValue) {
    if(($(element) && $F(element).blank()) || $F(element) == baseValue){
      if($('lbl_'+element)) $('lbl_'+element).addClassName('missing');
      this.retValue = false;
    }else{
      if($('lbl_'+element)) $('lbl_'+element).removeClassName('missing');
    }
  },
  
  /**
   * validateInputEmail
   */
  validateInputEmail: function(element){
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if($(element)){
      if(!filter.test($F(element))){
        if($('lbl_'+element)) $('lbl_'+element).addClassName('missing');
        this.retValue = false;
      }else{
        if($('lbl_'+element)) $('lbl_'+element).removeClassName('missing');
      }
    }
  },
  
  /**
   * bannerSlide
   */
  bannerSlide: function(currElement, newElement){
    if($(newElement)){
      this.currElement = currElement;
      this.newElement = newElement;      
      $(currElement).hide();     
      $(newElement).appear({ duration: 0.4 });
      this.bannerCounter++;
    }
  },
  
  /**
   * changeTestMode
   */
  changeTestMode: function(status){
    new Ajax.Request('/zoolu-website/testmode/change', {
      parameters: { TestMode: status },
      evalScripts: true,
      onComplete: function(transport) {         
        window.location.href = window.location.href;
      }.bind(this)
    });
  },
  
  /**
   * initProductOverview
   */  
  initProductOverview: function() {
    if($('productOverlay')) {
      //$$('body')[0].setStyle({overflow:'hidden'});
      $('bgProduct').setStyle({opacity:'0'});
      $('resistenteText').setStyle({display:'none'});
      $('monoText').setStyle({display:'none'});
      $('perfettoText').setStyle({display:'none'});
      $('belloText').setStyle({display:'none'});
      $('metalloText').setStyle({display:'none'});
      setTimeout('myDefault.toogleProductOverview();', 3000);
    }
  },
  
  /**
   * toogleProductOverview
   */  
  toogleProductOverview: function() {
    if($('bgProduct') && $('bgStart')) {
      $('bgProduct').fade({duration: 2.0, from: 0, to: 1});
      $('bgStart').fade({duration: 2.0, from: 1, to: 0});
    }
  },
  
  /**
   * showText
   */  
  showText: function(e) {
    if($(e)) {
      $(e).setStyle({display:'block'});
    }
  },
  
  /**
   * hideText
   */  
  hideText: function() {
    $$('.overlayText').each(function(e){
      e.setStyle({display:'none'});
    });
  },
  
  /**
   * hideIntro
   */  
  hideIntro: function() {
    if($('productOverlay')) {
      $('productOverlay').setStyle({display:'none'});
      $$('.contentContainer')[0].setStyle({display: 'block'});
      $('footer').setStyle({display: 'block'});
      $('main').setStyle({padding: '0px 0px 290px 0'});
    }
  }
  
});
