/*
Class: Rako Background [Built on MooTools framework: www.mootools.net]
Author: Martin Jezek 2011
Version: 1.0
*/  
var RakoBackground = new Class ({
  // Options
  Implements : Options,
  options : {
    bg_id : "bg",
    wheeler_id : "wheeler",
    
    ratio : 0.5,
    delay: 4000,
    stop_wheeling : false
  },
  
  // Initialize
  initialize : function(options){
    this.setOptions(options);
    this.initBg();
     
   this.refresh(); 
    this.addEvents();
   
  },
  width: 0,
  height: 0,
  slide_count: 0,
  now: 0,
  point_height: 0,
  
  // Methods
  initBg : function(){
    this.bg = $(this.options.bg_id);
    this.wheeler = $(this.options.wheeler_id);
    this.items = this.bg.getElements(".item");
    this.slide_count = this.items.length;
    
    this.wheeler.setStyle("width", this.slide_count * 100 + "%");
   // alert(this.items.length)
   // alert(100 / this.slide_count + "%");
    //this.items[0].setStyle("width", 100 / this.slide_count + "%");
    this.items[0].style.width=100 / this.slide_count + "%";
    if(this.options.stop_wheeling){
      this.stop_wheeling();
    }
	
	

	
  },

  
  refresh : function(){
    this.width = this.bg.getWidth();
   
   // alert(this.bg.tagName)
    //this.height = (this.width * this.options.ratio).round();
    this.bg.setStyle("height",$(window).getHeight() );
	this.bg.setStyle("width",$(window).getWidth() );

  },
  
  addEvents : function(){
    window.addEvent("resize", this.refresh.bind(this));
  },

  wheeling : function(){
    if(!(this.bg.hasClass("stop_wheeling"))){ 
      if(this.now < this.slide_count-1) {
        this.now++;
      } else {
        this.now = 0;
      }
	  
      
	  this.wheeler.setStyle("left", 	-this.now * 100 + "%" );
    
	
	
      
    }
  },
  
  stop_wheeling : function(){
    if(!this.bg.hasClass("stop_wheeling")){
      this.bg.addClass("stop_wheeling");
    }
  },

  start_wheeling : function(){
      this.bg.removeClass("stop_wheeling");
  },
 
  point_click : function(point){
    if(point.item.hasClass("act")){
      this.start_wheeling();
    } else {
      this.stop_wheeling();
      
    }    
    point.item.toggleClass("act");
  }
});
