// Copyright (c) CVT Ventures 2004
//
function ImageButton( document, name, selected, location, height, width )
{
    if (document == null)
    {
	    return;
    }
    
    // Define image functions, if they have not been defined
    if (!ImageButton.prototype.over) 
    {
        // Initialize the prototype object to create our methods.
        ImageButton.prototype.over = _ImageButton_over;
        ImageButton.prototype.out = _ImageButton_out;
        ImageButton.prototype.click = _ImageButton_click;
    }
    
    // Create an array of image objects, and assign URLs to them.
	this.imagenames = new Array(3); 
    this.imagenames[0] = "images/cvt-nav_" + name + ".gif";     // normal;
    this.imagenames[1] = "images/cvt-nav_" + name + "-on.gif";  // selected;
    this.imagenames[2] = "images/cvt-nav_" + name + "-on.gif";  // roll over;
    
    this.images = new Array(3);
    for(var i = 0; i < 3; i++) 
    {
        this.images[i] = new Image(width, height);
        this.images[i].src = this.imagenames[i];
    }

    // Save some of the arguments we were passed.
    this.document = document;
    this.selected = selected;
    this.location = location;

    // Figure out where in the document.images[] array the images go
    var index = document.images.length;

    // Output the HTML code for the button
    document.write('<a href ="" ' +
      'onMouseOver="document.images[' + index + ']._button.over(); return true;" '+
      'onMouseOut="document.images[' + index + ']._button.out()" '+
      'onClick="document.images[' + index + ']._button.click(); return false;">');
    document.write('<img src="' + this.imagenames[this.selected] +'"'+
                   ' width=' + width +
                   ' height=' + height +
                   ' border=0 hspace=0 vspace=0 align="left">');
    document.write('</a>');

    // Save a reference to the image object and from the image object to the button
    this.image = document.images[index];
    this.image._button = this;
}

// Change to the roll over image
function _ImageButton_over()
{
    this.image.src = this.imagenames[2];
}

// Change the image to its current state
function _ImageButton_out()
{
    this.image.src = this.imagenames[this.selected];
}

// Change the image to the clicked state.
function _ImageButton_click()
{
    this.selected = 1;
    this.image.src = this.imagenames[1];
    document.location = this.location
}


