/**
 * default.js
 *
 * Version history (please keep backward compatible):
 * 1.0, 2009-07-30: Cornelius Hansjakob
 *
 * @author Cornelius Hansjakob <cha@massiveart.com>
 * @version 1.0
 */

Default = Class.create({

  initialize: function() {   
    this.reValue = false;     
    
    // Tab1
    if($('tab1')){
      $('tab1').observe('mouseover', function(event){ 
        $('tab1').addClassName('hover');
        $('bgTab').addClassName('hoverTab1');
        $('img1').show();
      }.bind(this));
    	        
      $('tab1').observe('mouseout', function(event){
        $('tab1').removeClassName('hover');
        //$('bgTab').removeClassName('hoverTab1');
        //$('img1').hide();
      }.bind(this));
    }
    // Tab2
    if($('tab2')){
      $('tab2').observe('mouseover', function(event){ 
        $('tab2').addClassName('hover');
        $('bgTab').addClassName('hoverTab2');
        $('img2').show();
      }.bind(this));
      	        
      $('tab2').observe('mouseout', function(event){
        $('tab2').removeClassName('hover');
        $('bgTab').removeClassName('hoverTab2');
        $('img2').hide();
      }.bind(this));
    }
    // Tab3
    if($('tab3')){
      $('tab3').observe('mouseover', function(event){ 
        $('tab3').addClassName('hover');
        $('bgTab').addClassName('hoverTab3');
        $('img3').show();
      }.bind(this));
        	        
      $('tab3').observe('mouseout', function(event){
        $('tab3').removeClassName('hover');
        $('bgTab').removeClassName('hoverTab3');
        $('img3').hide();
      }.bind(this));
    }
  },
  
  /**
   * toggleElement
   */
  toggleElement: function(elementId, dblDuration){
    if(typeof(dblDuration) == 'undefined'){
      dblDuration = 0.2;   
    }
    if($(elementId)){
      if($(elementId).style.display == 'none'){
        Effect.SlideDown(elementId, {duration: dblDuration});
      }else{
        Effect.SlideUp(elementId, {duration: dblDuration});
      }
    }
  },
  
  /**
   * submitForm
   */
  submitForm: function(formId){
    if($(formId)){
      
      /**
       * validation
       */
      this.retValue = true;
      
      this.validateInput('fname');
      this.validateInput('sname');
      this.validateInput('mail');
      this.validateInput('infos');
      
      if(this.retValue == true) {
	    if($('noticebox')) $('noticebox').hide();
	    this.addBusyClass('bttnSend');
	      
	    /**
	     * serialize form
	     */
	    var serializedForm = $(formId).serialize();
	      
	    new Ajax.Request($(formId).readAttribute('action'), {
	      parameters: serializedForm,
	      evalScripts: true,
	      onComplete: function(transport) {         
	        this.removeBusyClass('bttnSend');	        
	        if($('contactForm')) $('contactForm').hide();
	    	if($('succesbox')){	            
	          $('succesbox').appear();
	        }    
	      }.bind(this)
	    });
	  }else{
	    this.removeBusyClass('bttnSend');
        if($('noticebox')) $('noticebox').show();
	  }
    }
  },
  
  /**
   * validateInput
   */
  validateInput: function(element, baseValue) {
    if(($(element) && $F(element).blank()) || $F(element) == baseValue){
      $(element).addClassName('missinginput');
      this.retValue = false;
    }else{
      $(element).removeClassName('missinginput');
    }
  },
  
  /**
   * 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)
    });
  },
  
  /**
   * addBusyClass
   */
  addBusyClass: function(busyElement, blnDisplay) {
    if($(busyElement)){
      $(busyElement).addClassName('busy');
      if(blnDisplay) $(busyElement).show();
    }
  },

  /**
   * removeBusyClass
   */
  removeBusyClass: function(busyElement, blnDisplay) {
    if($(busyElement)){
      $(busyElement).removeClassName('busy');
      if(blnDisplay) $(busyElement).hide();
    }
  }
  
});