Element.implement({

 fadeTo : function( amount, whenFinished, duration ) {
   if(typeof whenFinished != 'function') {
	 whenFinished = function() {}   
   }
   this.setStyle('visibility','visible');
   
   new Fx.Elements(this, {
      transition : new Fx.Transition(Fx.Transitions.Quad.easeOut, 6).easeOut 
    , duration : ( (duration!=null && duration>0) ? duration : 500 )
    , onComplete : function() { 
	    if(amount==0) this.element.setStyle('visibility','hidden');
	    this.whenFinished.bind(this.element)();
	  }.bind({whenFinished:whenFinished,element:this})
   }).start({'0':{'opacity':[this.getOpacity(),amount]}});
   return this;
 }
		
});

/*******************************************************/

String.implement({
  preg_replace: function (pattern, pattern_replace)  {
	  var new_string = String (this);
    var reg_exp= RegExp(pattern, "gi");
    new_string = new_string.replace(reg_exp, pattern_replace);
		return new_string;
	}
});

/*******************************************************/

var pngAnim = new Class({    
    options : {
			size: 35,
			frames: 6, 
			speed: 80,
      stopAfterTime: 0,
      eventStop : null
		},
    
    initialize: function(el, options){
  		this.el = $(el);
  		this.setOptions(options);
  		this.x = 0;
  		this.cFrame = 0;
        
        if(this.options.stopAfterTime>0){
            var timeStop = setTimeout(function(){
                this.stop();
                $clear(timeStop);
            }.bind(this), this.options.stopAfterTime);
        }
        
        if(this.options.eventStop!=null){
            var action='';
            action = 'this.el.addEvent("'+this.options.eventStop+'", function(){';
            action+= '  this.stop();';
            action+= '}.bind(this));';
            eval(action);
        }
  	},
    
    
  	start: function(){
  		this.interval = function(){
          this.changeFrame();
        }.bind(this).periodical(this.options.speed);
  	},
  	
  	changeFrame: function(){
  		if (this.cFrame == this.options.frames){
  			this.cFrame = 0;
  			this.x = 0;
  		}
  		this.cFrame++;
  		this.x += this.options.size;
  		this.el.setStyle('background-position' , -this.x+'px 0');
  	},
  	
  	stop: function(){
  		$clear(this.interval);
  	}
})
pngAnim.implement(new Options, new Events);

/*******************************************************/

var initClassForm = function(){
    $$('input[type=text]').each(function(el){
        el.addClass('champ') 
    });
    
    $$('input[type=password]').each(function(el){
        el.addClass('password') 
    });
    
    $$('textarea').each(function(el){
        el.addClass('champ') 
    });
    
    $$('input[type=file]').each(function(el){
        el.addClass('champ') 
    });
    
    $$('input[type=submit]').each(function(el){
        el.addClass('submit') 
    });
    
    $$('input[type=button]').each(function(el){
        el.addClass('submit') 
    });
    
    $$('input[type=reset]').each(function(el){
        el.addClass('submit') 
    });
}

/*******************************************************/

var AntiRobotUpdate = function() { $('AntiRobotImage').src = 'captcha.jpg?v='+((new Date).getTime()); }