/**************************************************
Trivantis (http://www.trivantis.com)
**************************************************/

// Media Object
function ObjMedia(n,m,a,l,x,y,w,h,v,z,c) {
  this.name = n
  this.mediaString = ' SRC="'+m+'"'
  this.x = x
  this.y = y
  this.w = w
  this.h = h
  this.c = c
  this.isPlaying = false
  this.bVis = v
  if( v ) this.v = "inherit"
  else this.v = (is.ns4)? "hide" : "visible"
  this.z = z
  this.obj = this.name+"Object"
  this.hrefPrompt = 'javascript:void(null);'
  if( l ) this.loopString = ' LOOP="TRUE"'
  else this.loopString = ' LOOP="FALSE"'
  this.embed=''
  this.BuildMediaString( a );
  eval(this.obj+"=this")
}

function ObjMediaBuildMediaString( bPlay ){
  var autoString=''
  var contString=''
  var width=this.w
  var height=this.h
  var setWH=true
  var addIEheight=20
  this.isPlaying = bPlay
  if( this.isPlaying ) autoString = ' AUTOSTART="TRUE"'
  else autoString = ' AUTOSTART="FALSE"'
  if( !is.ns4 && !this.bVis ) autoString += ' hidden="TRUE"'
  if( this.mediaString.indexOf(".avi") >= 0 ) {
    if( !is.ns ) {
      if( this.c ) {
        contString += ' ShowControls="TRUE"'
        height += addIEheight
        setWH=false
      }
      else contString += ' ShowControls="FALSE"'
    }
  }
  else if (this.mediaString.indexOf(".mov") >= 0 ) {
    if( this.c == 0) height += addIEheight
  }
  else if (!is.ns4 && this.mediaString.indexOf(".mp") >= 0 ) {
    height += addIEheight
    setWH=true
  }
  else if( this.c ) {
    if( is.ns ) {
	  var plugin = "audio/x-mpeg\""
      var mimeType = eval( "navigator.mimeTypes[\"" + plugin + "]")
      if( mimeType && (!mimeType.enabledPlugin || mimeType.enabledPlugin.name.indexOf( "QuickTime" ) < 0) ) {
	    width = 145
	    height = 60
	  }
    }
    else if( is.ieMac ) height -= 10
	else if( !is.ns ) {
	  setWH = false
	  height += addIEheight
	}
  }
  this.embed = '<EMBED' +this.mediaString+contString
  if( setWH ) this.embed += ' WIDTH=' + width + ' HEIGHT=' + height 
  this.embed += autoString+this.loopString+'>\n'
}

function ObjMediaActionGoTo( destURL, destFrame ) {
  this.objLyr.actionGoTo( destURL, destFrame );
}

function ObjMediaActionGoToNewWindow( destURL, name, props ) {
  this.objLyr.actionGoToNewWindow( destURL, name, props );
}

function ObjMediaActionPlay( ) {
  this.BuildMediaString( true );
  this.objLyr.write( this.embed );
}

function ObjMediaActionStop( ) {
  this.BuildMediaString( false );
  this.objLyr.write( this.embed );
}

function ObjMediaActionShow( ) {
  if( is.ie ) {
    this.bVis = 1
    this.BuildMediaString( this.isPlaying )
    this.objLyr.write( this.embed );
  }
  else this.objLyr.actionShow();
}

function ObjMediaActionHide( ) {
  if( is.ie ) {
    this.bVis = 0
    this.BuildMediaString( this.isPlaying )
    this.objLyr.write( this.embed );
  }
  else this.objLyr.actionHide();
}

function ObjMediaActionLaunch( ) {
  this.objLyr.actionLaunch();
}

function ObjMediaActionExit( ) {
  this.objLyr.actionExit();
}

function ObjMediaActionChangeContents( newMedia ) {
  this.mediaString = ' SRC="' +newMedia +'"'
  this.BuildMediaString( false );
  if( is.ns5 ) this.objLyr.ele.innerHTML=this.embed
  else this.objLyr.write( this.embed );
}

function ObjMediaActionTogglePlay( ) {
  if( this.isPlaying == false ) {
    this.BuildMediaString( true )
    this.objLyr.write( this.embed )
  }
  else {
    this.BuildMediaString( false )
    this.objLyr.write( this.embed )
  }
}

function ObjMediaActionToggleShow( ) {
  if( is.ie ) {
    this.bVis = !this.bVis
    this.BuildMediaString( this.isPlaying )
    this.objLyr.write( this.embed );
  }
  else this.objLyr.actionToggleShow();
}

{ //Setup prototypes
var p=ObjMedia.prototype
p.BuildMediaString = ObjMediaBuildMediaString
p.build = ObjMediaBuild
p.activate = ObjMediaActivate
p.capture = 0
p.up = ObjMediaUp
p.down = ObjMediaDown
p.over = ObjMediaOver
p.out = ObjMediaOut
p.onOver = new Function()
p.onOut = new Function()
p.onSelect = new Function()
p.onDown = new Function()
p.onUp = new Function()
p.actionGoTo = ObjMediaActionGoTo
p.actionGoToNewWindow = ObjMediaActionGoToNewWindow
p.actionPlay = ObjMediaActionPlay
p.actionStop = ObjMediaActionStop
p.actionShow = ObjMediaActionShow
p.actionHide = ObjMediaActionHide
p.actionLaunch = ObjMediaActionLaunch
p.actionExit = ObjMediaActionExit
p.actionChangeContents = ObjMediaActionChangeContents
p.actionTogglePlay = ObjMediaActionTogglePlay
p.actionToggleShow = ObjMediaActionToggleShow
p.writeLayer = ObjMediaWriteLayer
p.slideTo = ObjMediaSlideTo
p.moveTo = ObjMediaMoveTo
}

function ObjMediaBuild() {
  this.css = buildCSS(this.name,this.x,this.y,null,null,this.v,this.z,this.clip)
  var divStart
  var divEnd
  divStart = '<div id="'+this.name+'"><a name="'+this.name+'anc">'
  divEnd   = '</a></div>'
  if( is.ns4 && this.capture & 4 ){
    divStart = divStart + '<A HREF="' +this.hrefPrompt+'">'
    divEnd   = '</A>' + divEnd 
  }
  this.div = divStart + '\n' +this.embed + divEnd + '\n';
}

function ObjMediaActivate() {
  this.objLyr = new ObjLayer(this.name)
  if( this.objLyr && this.objLyr.styObj ) this.objLyr.styObj.visibility = this.v
  if( this.capture & 4 ) {
    if (is.ns4) this.objLyr.ele.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
    this.objLyr.ele.onmousedown = new Function(this.obj+".down(); return false;")
    this.objLyr.ele.onmouseup = new Function(this.obj+".up(); return false;")
  }
  if( this.capture & 1 ) this.objLyr.ele.onmouseover = new Function(this.obj+".over(); return false;")
  if( this.capture & 2 ) this.objLyr.ele.onmouseout = new Function(this.obj+".out(); return false;")
}

function ObjMediaDown() {
  if( is.ie && event.button != 1 ) return
  this.onSelect()
  this.onDown()
}

function ObjMediaUp() {
  this.onUp()
}

function ObjMediaOver() {
  this.onOver()
}

function ObjMediaOut() {
  this.onOut()
}

function ObjMediaWriteLayer( newContents ) {
  if (this.objLyr) this.objLyr.write( newContents )
}

function ObjMediaSlideTo(ex,ey,amt,spd,fn) {
  if (this.objLyr) this.objLyr.slideTo(ex,ey,amt,spd,fn);
}

function ObjMediaMoveTo(x,y) {
  if (this.objLyr) this.objLyr.moveTo(x,y);
}

