//this function includes all necessary js files for the application
function include(file)
{
  var script  = document.createElement('script');
  script.src  = file;
  script.type = 'text/javascript';
  script.defer = true;

  document.getElementsByTagName('head').item(0).appendChild(script);
}

/* include any js files here */
include('js/dom.general.js');
include('js/dom.event.js');

/********************************
* class ImageButton
* 
* implement function that change the src
* of img when mouse over,out and click
********************************/
  
//In here, this is image object
ImageButton.funOver= function(){this.src = this.oversrc;}  
ImageButton.funOut= function(){this.src = this.defaultsrc;}  
ImageButton.funDown= function(){this.src = this.downsrc;}  
ImageButton.funUp= function(){this.src = this.defaultsrc;}

function ImageButton(idname,_src,_oversrc,_downsrc){
  //Error check
  if(arguments.length!=4)
   throw new Error("The number of arguments must be 4.");
  
  if(typeof idname != "string" || typeof _src != "string" ||
     typeof _oversrc != "string" || typeof _downsrc != "string")
   throw new Error("The type of parameters must be string.");  
       
  //Add properties    
  this.obj = id(idname);
  if(!this.obj || this.obj.tagName!="IMG")
    throw new Error("Parameter 1 must be id of some img tag.");          
  this.obj.oversrc = _oversrc;
  this.obj.downsrc = _downsrc;
  this.obj.defaultsrc = _src;
}
 
ImageButton.prototype.enableOver = function(){    
  addEvent(this.obj,"mouseover",ImageButton.funOver);    
  addEvent(this.obj,"mouseout",ImageButton.funOut);
}

ImageButton.prototype.disableOver = function(){
  removeEvent(this.obj,"mouseover",ImageButton.funOver);
  removeEvent(this.obj,"mouseout",ImageButton.funOut);    
}

ImageButton.prototype.enableMouseDown = function(){
  addEvent(this.obj,"mousedown",ImageButton.funDown);  
  addEvent(this.obj,"mouseup",ImageButton.funUp);
}

ImageButton.prototype.disableMouseDown = function(){
  removeEvent(this.obj,"mousedown",ImageButton.funDown);
  removeEvent(this.obj,"mouseup",ImageButton.funUp);
}
