// === Volume Control ===
// Copyright 2001 Musicmusicmusic, Inc. All rights reserved.
// Author: Martin Andres
// Version: 1.2
// Date: Feb. 9, 2001
// =============
// Requires:
//  mediaplayer.php3.inc, mm.js, debug.js
//
// Required Vars:
//  volRange = (#) range in pixels
//  volName  = (text) volume knob layer name
//  volHorizontal = (true) horizontal or (false) vertical default=false
//
// Functions:
//  VolSet(), VolDrag(), VolPos(), VolMute(), VolMove()
//
// Reserved Vars:
//  volLyrObj, volLeft, volTop, volMuteVol, volMute, tmp
//
 
if (top.debug) top.debug("vol> Java Include (volume1.js) Start")

if (!volHorizontal) var volHorizontal=false

if (top.debug) top.debug("vol> volName="+volName+" volRange="+volRange+" volHorizontal="+volHorizontal)

// Find object
var volLyrObj=MM_findObj(volName, "")

// Set Init Position vars
if (document.layers) {
 var volLeft=volLyrObj.left
 var volTop=volLyrObj.top
} else {
 var volLeft=volLyrObj.style.left
 var volTop=volLyrObj.style.top
}
if (isNaN(volLeft)) { var tmp=volLeft.indexOf("px"); if (tmp>-1) volLeft=Number(volLeft.substring(0,tmp)) }
if (isNaN(volTop))  { var tmp=volTop.indexOf("px");  if (tmp>-1) volTop=Number(volTop.substring(0,tmp)) }

if (top.debug) top.debug("vol> volLeft="+volLeft+" volTop="+volTop)

// Define drag area
if (volHorizontal) { MM_dragLayer(volName,'',0,0,0,0,true,false,0,0,0,volRange,volLeft,volTop,0,'',false,'VolDrag()') }
              else { MM_dragLayer(volName,'',0,0,0,0,true,false,volRange,0,0,0,volLeft,volTop,0,'',false,'VolDrag()') }

// Set volume when draging
var volMuteVol = Number(0)
var volMute = true

// Set volume and slider
function VolSet(vol) {
	if (top.debug) top.debug("vol> VolSet("+vol+")")
	if (!vol) { vol=PlayerState('volume') }
	     else { PlayerAction('volume',vol) }
	VolPos(vol)
	if (top.debug) top.debug("vol> VolSet vol="+vol)
}

// Drag volume knob layor
function VolDrag() {
	if (top.debug) top.debug("vol> VolDrag()")
	if (volHorizontal) { var vol = volLyrObj.MM_LEFTRIGHT }
	              else { var vol = volLyrObj.MM_UPDOWN }
	vol = 100-Math.round((volRange+vol)*(100/volRange))
	if (volHorizontal) vol = -vol
	if (top.debug) top.debug("vol> VolDrag() vol="+vol)
	if (vol) { volMuteVol=0; volMute=false }
	    else { volMute=true }
	PlayerAction('volume',vol)
	if (top.debug) top.debug("vol> VolDrag vol="+vol+" volMuteVol="+volMuteVol+" volMute="+volMute)
}

// Set volume knob position 0-100%.  pos = #
function VolPos(vol) {
	if (top.debug) top.debug("vol> VolPos("+vol+")")
	if (vol!=0) { volMuteVol=0; volMute=false }
	       else { volMute=true }
	vol = Math.round(volRange*vol/100)
	if (volHorizontal) {
	  vol = volLeft+vol
          if (document.layers) { volLyrObj.left = vol }
                          else { volLyrObj.style.left = vol }
	} else {
	  vol = volTop-vol
          if (NS4) { volLyrObj.top = vol }
              else { volLyrObj.style.top = vol }
	}
	if (top.debug) top.debug("vol> VolPos vol="+vol+" volMuteVol="+volMuteVol+" volMute="+volMute)
}

// Mute volume
function VolMute() {
	if (top.debug) top.debug("vol> VolMute() volMuteVol="+volMuteVol+" volMute="+volMute);
	if (volMuteVol) { var vol=volMuteVol; volMuteVol=0 }
	           else { var vol=0; volMuteVol=PlayerState('volume') }
	if (top.debug) top.debug("vol> VolMute vol="+vol+" volMuteVol="+volMuteVol+" volMute="+volMute);
	PlayerAction('volume',vol)
	VolPos(vol)
 }

// Move volume position by 10%.  dir = 'up' or 'down'
function VolMove(dir) {
	if (top.debug) top.debug("vol> VolMove("+dir+")")
	var vol = PlayerState('volume')
	if (top.debug) top.debug("vol> VolMove("+dir+") vol="+vol)
	if (dir=='up') vol=vol+10; if (vol>100) vol=100
	if (dir=='down') vol=vol-10; if (vol<0) vol=0
	if (top.debug) top.debug("vol> VolMove vol="+vol)
	VolSet(vol)
}

if (top.debug) top.debug("vol> Java Include (volume1.js) End")
