/**
 * 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.bannerCounter = 0;
    this.bannerDirection = 'right';
    this.bannerStop = false;
    
    this.sliding = 0;
  },
  
  init: function(){
    if($('scrollLeft')) $('scrollLeft').observe('click', function(){ this.bannerStop = true; }.bind(this));
    if($('scrollRight')) $('scrollRight').observe('click', function(){ this.bannerStop = true; }.bind(this));
    setTimeout('myDefault.bannerCarousel()', 5000);
  },
  
  /**
   * bannerCarousel
   */
  bannerCarousel: function(){
    if(this.bannerStop == false){
      if($('slide_' + this.bannerCounter)){
	      if(this.bannerDirection == 'right' && !($('slide_' + (this.bannerCounter+1)))){
	        this.bannerDirection = 'left';
	      }
	      else if(this.bannerDirection == 'left' && !($('slide_' + (this.bannerCounter-1)))){
	        this.bannerDirection = 'right';
	      }
	      this.bannerSlide(this.bannerDirection);
	      setTimeout('myDefault.bannerCarousel()', 5000); 
	    } 
    }
  },
  
  /**
   * bannerSlide
   */
  bannerSlide: function(direction){
    if(typeof(direction) == 'undefined') direction = 'right';
    if(direction == 'left'){
      this.bannerSlideLeft('slide_' + this.bannerCounter, 'slide_' + (this.bannerCounter-1));
    }else{
      this.bannerSlideRight('slide_' + this.bannerCounter, 'slide_' + (this.bannerCounter+1));
    } 
  }, 
  
  /**
   * bannerSlideRight
   */
  bannerSlideRight: function(currElement, newElement){
    if($(newElement)){
      if(parseInt($(newElement).style.left) <= 320 && parseInt($(newElement).style.left) > 0){
        new Effect.Move(newElement, { x: 15, y: 20, mode: 'absolute', duration: 0.6 });
        new Effect.Move(currElement, { x: -320, y: 20, mode: 'absolute', duration: 0.6 });
        this.bannerCounter++;
      }
    }
  },
  
  /**
   * bannerSlideLeft
   */
  bannerSlideLeft: function(currElement, newElement){
    if($(newElement)){
      if(parseInt($(newElement).style.left) >= -320 && parseInt($(newElement).style.left) < 0){
        new Effect.Move(newElement, { x: 15, y: 20, mode: 'absolute', duration: 0.6 });
        new Effect.Move(currElement, { x: 320, y: 20, mode: 'absolute', duration: 0.6 });
        this.bannerCounter--;
      }
    }
  },
  
  /**
   * filterOverview
   */
  filterOverview: function(element){
    if($(element)){
      self.location.href = '?c='+$(element).getValue();
    }
  },
  
  /**
   * imgGalleryShowAll
   */
  imgGalleryShowAll: function(elementHide){
    if($('div_image_gallery')){
      var images = $('div_image_gallery').innerHTML;
      $('div_image_gallery').remove();
      if($(elementHide)) $(elementHide).hide();
      new Insertion.After($(elementHide), images);
    }
  },
  
  /**
   * showContainer
   */
   showContainer: function(elementShow, elementHide){
    if($(elementShow)){
      $(elementHide).hide();
      Effect.SlideDown(elementShow, {duration: 0.4});
      setTimeout('new Effect.ScrollTo(\''+elementShow+'\')', 400);
    }
  },
  
  /**
   * 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();
    }
  }
  
});
