/*
 * Copyright 2006 OST-SYSTEMS. All rights reserved.
 */

function HectorInfoButton(flipper, front, foregroundStyle, backgroundStyle, onclick) {
  
  this.onclick = onclick;    
	this.flipper = flipper;
	this.front = front;
	this.animator = null;
	
	var doc = flipper.ownerDocument;
	this.background = doc.createElement("div");
	this.foreground = doc.createElement("img");
	flipper.appendChild(this.background);
	flipper.appendChild(this.foreground);
	
	this.setStyle(foregroundStyle, backgroundStyle);
	this.foreground.setAttribute("alt", "");
	
	var style1 = this.foreground.style;
	style1.position = "absolute";
	style1.top = 0;
	style1.left = 0;
	if (!window.MobileWidget) {
	  style1.opacity = 0;
	}  
	
	style1 = this.background.style;
	style1.position = "absolute";
	style1.top = 0;
	style1.left = 0;
	style1.width = "13px";
	style1.height = "13px";
	this.setCircleOpacity(0.25);
	if (!window.MobileWidget) {
  	style1.visibility = "hidden";
	}	
	
	this.setStyle(foregroundStyle, backgroundStyle);
	
	var _self = this;
	this.flipper.onmouseover = function() {
	  _self.background.style.visibility = "visible";
	}
	
	this.flipper.onmouseout = function() {
	  _self.background.style.visibility = "hidden";	  
	}
	
	this.flipper.onclick = function() {
	  if (_self.onclick) {
	    _self.onclick();
	  }
	}
	
	if (!window.MobileWidget) {
  	this.front.onmousemove = function() {
  	  if (_self.animator) {
  	    _self.animator.stop();
  	    delete _self.animator;
  	  }
  	  _self.animator = new HectorAnimator(500, 40, parseFloat(_self.foreground.style.opacity), 1, 
  	    function (animator, value, first, done) {
  	      _self.foreground.style.opacity = value;
  	      if (done) {
  	        _self.foreground.style.opacity = 1;
  	        _self.animator = null;
  	        //_self.front.onmouseout();
  	      }
  	    });
  	  _self.animator.start();
  	}
  	
  	this.front.onmouseout = function() {
  	  if (_self.animator) {
  	    _self.animator.stop();
  	    delete _self.animator;
  	  }
  	  _self.animator = new HectorAnimator(1000, 40, parseFloat(_self.foreground.style.opacity), 0, 
  	    function (animator, value, first, done) {
  	      _self.foreground.style.opacity = value;
  	      if (done) {
  	        _self.foreground.style.opacity = 0;
  	        _self.animator = null;
  	      }
  	    });	  
  	  _self.animator.start();
  	}
	} 
}

HectorInfoButton.prototype.remove = function() {
  while (this.flipper.firstChild != null) {
    this.flipper.removeChild(this.flipper.lastChild);
  }
}

HectorInfoButton.prototype.setStyle = function(foregroundStyle, backgroundStyle)
{
  var path = getHectorPath() + "scripts/HectorClasses/Images/";  

	this.foreground.src = path + foregroundStyle + "_i.png";
	this.background.style.background = "url(" + path + backgroundStyle + "_rollie.png) no-repeat top left";
}

HectorInfoButton.prototype.setCircleOpacity = function(opacity) {
  this.background.style.opacity = opacity;
}

HectorInfoButton.prototype._labelOver = function(event) {
	this.background.style.visibility = "visible";	  
}

HectorInfoButton.prototype._labelOut = function(event) {
	this.background.style.visibility = "hidden";	  
}

