/**************************************************
Trivantis (http://www.trivantis.com)

This JavaScript code uses techniques found at
The Dynamic Duo - http://www.dansteinman.com/dynduo/
**************************************************/

// ButtonImage Object
function ButtonImage(name,altName,x,y,width,height,visible,zorder) {
    this.name = name
    this.altName = altName
    this.x = x
    this.y = y
    this.w = width
    this.h = height
    if( visible ) 
        this.v = (is.ns4)? "show" : "visible"
    else
        this.v = (is.ns4)? "hide" : "hidden"
    this.z = zorder
    this.obj = this.name+"Object"
    this.hrefPrompt = 'javascript:;'
    eval(this.obj+"=this")
}

function ButtonImageActionGoTo( destURL, destFrame ) {
    this.lyr.actionGoTo( destURL, destFrame );
}
function ButtonImageActionPlay( ) {
    this.lyr.actionPlay();
}
function ButtonImageActionStop( ) {
    this.lyr.actionStop();
}
function ButtonImageActionShow( ) {
    this.lyr.actionShow();
}
function ButtonImageActionHide( ) {
    this.lyr.actionHide();
}
function ButtonImageActionLaunch( ) {
    this.lyr.actionLaunch();
}
function ButtonImageActionExit( ) {
    this.lyr.actionExit();
}
function ButtonImageActionChangeContents( ) {
    this.lyr.actionChangeContents();
}
function ButtonImageActionTogglePlay( ) {
    this.lyr.actionTogglePlay();
}
function ButtonImageActionToggleShow( ) {
    this.lyr.actionToggleShow();
}
ButtonImage.prototype.checkbox = false
ButtonImage.prototype.preload = ButtonImagePreload
ButtonImage.prototype.setImages = ButtonImageSetImages
ButtonImage.prototype.build = ButtonImageBuild
ButtonImage.prototype.activate = ButtonImageActivate
ButtonImage.prototype.down = ButtonImageDown
ButtonImage.prototype.up = ButtonImageUp
ButtonImage.prototype.over = ButtonImageOver
ButtonImage.prototype.out = ButtonImageOut
ButtonImage.prototype.change = ButtonImageChange
ButtonImage.prototype.capture = 0
ButtonImage.prototype.onDown = new Function()
ButtonImage.prototype.onUp = new Function()
ButtonImage.prototype.onOver = new Function()
ButtonImage.prototype.onOut = new Function()
ButtonImage.prototype.onSelect = new Function()
ButtonImage.prototype.onDeselect = new Function()
ButtonImage.prototype.actionGoTo = ButtonImageActionGoTo
ButtonImage.prototype.actionPlay = ButtonImageActionPlay
ButtonImage.prototype.actionStop = ButtonImageActionStop
ButtonImage.prototype.actionShow = ButtonImageActionShow
ButtonImage.prototype.actionHide = ButtonImageActionHide
ButtonImage.prototype.actionLaunch = ButtonImageActionLaunch
ButtonImage.prototype.actionExit = ButtonImageActionExit
ButtonImage.prototype.actionChangeContents = ButtonImageActionChangeContents
ButtonImage.prototype.actionTogglePlay = ButtonImageActionTogglePlay
ButtonImage.prototype.actionToggleShow = ButtonImageActionToggleShow
ButtonImage.prototype.writeLayer = ButtonImageWriteLayer

function ButtonImageSetImages(imgOff,imgOn,imgRoll,dir) {
    if (!dir) dir = ''
    this.preload(this.obj+".imgOff",imgOff?dir+imgOff:'')
    this.preload(this.obj+".imgOn",imgOn?dir+imgOn:'')
    this.preload(this.obj+".imgRoll",imgRoll?dir+imgRoll:'')
}
function ButtonImagePreload(imgObj,imgSrc) {
    if (imgSrc) {
        eval(imgObj+' = new Image()')
        eval(imgObj+'.src = "'+imgSrc+'"')
        eval(imgObj+'s = true')
    }
    else eval(imgObj+'s = false')
}
function ButtonImageBuild() {
    this.css = css(this.name,this.x,this.y,this.w,this.h,this.v,this.z)

    this.div = '<div id="'+this.name+'">'
    if( is.ns4 )
        this.div += '<a name="'+this.name+'"><a href="' +this.hrefPrompt+'">'
        
    this.div += '<img name="'+this.name+'Img" src="'+this.imgOff.src
    if( this.altName )
        this.div += '" alt="['+this.altName+']'
    if( is.ns4 )
        this.div += '" width='+this.w+' height='+this.h+' border=0></a></a></div>\n'
    else
        this.div += '" width='+this.w+' height='+this.h+' border=0 style="cursor:hand"></div>\n'
}
function ButtonImageActivate() {
    this.lyr = new DynLayer(this.name)
    if( this.lyr && this.lyr.css )
        this.lyr.css.visibility = this.v
    
    if (is.ns4) this.lyr.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
    this.lyr.elm.onmousedown = new Function(this.obj+".down(); return false;")
    this.lyr.elm.onmouseup = new Function(this.obj+".up(); return false;")
    this.lyr.elm.onmouseover = new Function(this.obj+".over(); return false;")
    this.lyr.elm.onmouseout = new Function(this.obj+".out(); return false;")
}
function ButtonImageDown() {
    if (this.selected) {
        this.selected = false
        if (this.imgOns) this.change(this.imgOn)
        this.onDeselect()
    }
    else {
        if (this.checkbox) this.selected = true
        if (this.imgOns) this.change(this.imgOn)
        this.onSelect()
    }
    this.onDown()
}
function ButtonImageUp() {
    if (!this.selected) {
        if (this.imgRolls) this.change(this.imgRoll)
        else if (this.imgOns) this.change(this.imgOff)
    }
    this.onUp()
}
function ButtonImageOver() {
    if (this.imgRolls && !this.selected) this.change(this.imgRoll)
    this.onOver()
}
function ButtonImageOut() {
    if (this.imgRolls && !this.selected) this.change(this.imgOff)
    this.onOut()
}
function ButtonImageChange(img) {
    this.lyr.doc.images[this.name+"Img"].src = img.src
}
function ButtonImageWriteLayer( newContents ) {
    this.lyr.write( newContents )
}

