/**
 * default.js
 *
 * Version history (please keep backward compatible):
 * 1.0, 2010-05-04: Michael Trawetzky
 *
 * @author Michael Trawetzky <mtr@massiveart.com>
 * @version 1.0
 */

Default = Class.create({

  initialize: function() {
    this.language = 'de';
    
    this.bannerCounter = 1;
    this.bannerDirection = 'right';
    this.bannerStop = false;
    
    this.currElement = '';
    this.newElement = '';
  },
  
  init: function(language){
    if(typeof(language) != 'undefined') this.language = language;
	  if($('slidePrev')) $('slidePrev').observe('click', function(){ this.bannerStop = true; }.bind(this));
    if($('slideNext')) $('slideNext').observe('click', function(){ this.bannerStop = true; }.bind(this));
    
    this.currElement = 'slideshow_' + this.language + '_' + this.bannerCounter;
    this.newElement = 'slideshow_' + this.language + '_' + this.bannerCounter;
    
    setTimeout('myDefault.bannerCarousel()', 3000);
  },
  
  /**
   * bannerCarousel
   */
  bannerCarousel: function(){
    if(this.bannerStop == false){
      if($('slideshow_' + this.language + '_' + this.bannerCounter)){
	      if(this.bannerDirection == 'right' && !($('slideshow_' + this.language + '_' + (this.bannerCounter+1)))){
	        this.bannerDirection = 'left';
	      }
	      else if(this.bannerDirection == 'left' && !($('slideshow_' + this.language + '_' + (this.bannerCounter-1)))){
	        this.bannerDirection = 'right';
	      }
	      this.slideShow(this.bannerDirection);
	      setTimeout('myDefault.bannerCarousel()', 3000); 
	    } 
    }
  },
  
  /**
   * slideShow
   */
  slideShow: function(direction){
    if(typeof(direction) == 'undefined') direction = 'right';
    currElement = 'slideshow_' + this.language + '_' + this.bannerCounter;
    if(direction == 'left'){      
      this.bannerSlideLeft(currElement, 'slideshow_' + this.language + '_' + (this.bannerCounter-1));
    }else{
      this.bannerSlideRight(currElement, 'slideshow_' + this.language + '_' + (this.bannerCounter+1));
    } 
  },  
  
  /**
   * bannerSlideRight
   */
  bannerSlideRight: function(currElement, newElement, blnAjax){
    if(typeof(blnAjax) == 'undefined') blnAjax = false;
    if($(newElement)){
      this.currElement = currElement;
      this.newElement = newElement;
    	$(currElement).fade({ duration: 0.4 });    	
    	$(newElement).appear({ duration: 0.4 });
    	$('slideshow_'+(this.bannerCounter+1)+'_pic').addClassName('selected');
    	$('slideshow_'+this.bannerCounter+'_pic').removeClassName('selected');
      this.bannerCounter++;
    }
  },
  
  /**
   * bannerSlideLeft
   */
  bannerSlideLeft: function(currElement, newElement, blnAjax){
    if(typeof(blnAjax) == 'undefined') blnAjax = false;	
	  if($(newElement)){
  		this.currElement = currElement;
  		this.newElement = newElement;		
      $(currElement).fade({ duration: 0.4 });        
      $(newElement).appear({ duration: 0.4 });
      $('slideshow_'+(this.bannerCounter-1)+'_pic').addClassName('selected');
      $('slideshow_'+this.bannerCounter+'_pic').removeClassName('selected');
      this.bannerCounter--;
    }
  },
  
  /**
   * selectSlide
   */
  selectSlide: function(idNumber){
    if($('slideshow_'+idNumber+'_pic')){
      if($(this.currElement)){
        this.bannerStop = true;
        if(idNumber != this.bannerCounter){
          $('slideshow_'+idNumber+'_pic').addClassName('selected');
          $('slideshow_'+this.bannerCounter+'_pic').removeClassName('selected');
          this.slideToElement(idNumber);	
        }
      }		
    }
  },
  
  /**
   * slideToElement
   */
  slideToElement: function(counter){
    if($('slideshow_'+this.language+'_'+counter)){
      $(this.newElement).fade({ duration: 0.6 });        
      $('slideshow_'+this.language+'_'+counter).appear({ duration: 0.6 });
      this.newElement = 'slideshow_'+this.language+'_'+counter;
      this.bannerCounter = counter;	
    }
  },  
  
  /**
   * 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});
      }
    }
  },  
  
  /**
   * 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();
    }
  }
  
});
