var mtPlay_media = null;

var mtPlay_swf = null;
var mtPlay_vol = null;
var mtPlay_play = false;

var mtPlay_divMute = null;
var mtPlay_divVolume = null;

var mtPlay_handler = {
  onInit: function() {
    mtPlay_init();
  }
}

function mtPlay_mute() {

  mtPlay_play = ( mtPlay_play == 1 ) ? 2 : 1;

  if ( mtPlay_play == 1 )
    mtPlay_swf.SetVariable( 'method:play', '' );
  else
    mtPlay_swf.SetVariable( 'method:pause', '' );
  
  createCookie( 'mtPlay_play', mtPlay_play, 180 );

  mtPlay_showMute();
}

function mtPlay_volume(e) {

  var ev = new Event( e );
  mtPlay_vol = parseInt( ( ev.page.x - $(this).getPosition().x ) * 200 / 28 );

  mtPlay_swf.SetVariable( 'method:setVolume', mtPlay_vol );
  
  createCookie( 'mtPlay_vol', mtPlay_vol, 180 );

  mtPlay_showVolume();
}

function mtPlay_showMute() {

  mtPlay_divMute.className = ( mtPlay_play == 1 ) ? '' : 'mute';
}

function mtPlay_showVolume() {

  mtPlay_divVolume.setStyle( 'background-position', parseInt( parseInt( mtPlay_vol * 28 / 200 ) - 44 ) + 'px -16px' );
}

function mtPlay_init() {

  mtPlay_divMute = $( 'music-mute' );
  mtPlay_divVolume = $( 'music-vol' );

  mtPlay_vol = readCookie( 'mtPlay_vol' );
  if ( mtPlay_vol == null )
    mtPlay_vol = 100;

  mtPlay_play = readCookie( 'mtPlay_play' );
  if ( mtPlay_play == null )
    mtPlay_play = 1;
  
  mtPlay_swf = document.getElementById( 'music-player' );
  mtPlay_swf.SetVariable( 'method:setUrl', mtPlay_media );
  mtPlay_swf.SetVariable( 'method:setVolume', mtPlay_vol );

  if ( mtPlay_play == 1 )
    mtPlay_swf.SetVariable( 'method:play', '' );

  mtPlay_divMute.addEvent( 'click', mtPlay_mute );
  mtPlay_divVolume.addEvent( 'click', mtPlay_volume );
 
  mtPlay_showMute();
  mtPlay_showVolume();
}


