import mx.controls.streamingmedia.HMiniPlayBarTray;
import templateBook.mvctemplate.*
import templateBook.mvc.*
import templateBook.I.*
import flash.display.BitmapData
import templateBook.util.Observable
import templateBook.Configuration
import flash.filters.GlowFilter;
import templateBook.ToolTip
import mx.transitions.Tween;
import mx.transitions.easing.*

class templateBook.mvctemplate.PlayerSoundView extends AbstractTools {

var orient:String="TL"	                //orient for toolTip
var containerMusic:MovieClip            //container for player mp3
var blockade_press:Boolean = false;

////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function PlayerSoundView() {
		
	 	if (Configuration.MP3_PATHWAY_XML.length == undefined) {
			this.swapDepths(this._parent.getNextHighestDepth()+1000)
			this.removeMovieClip()
		}
	}
		
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onLoad() {
		desc_tool = Configuration.TOOL_SPEAKER
		containerMusic=this.createEmptyMovieClip("mcContainer",1)
		onResize()	
		createMaskReflection()
		
		if (Configuration.SOUND_MUTE_DEFAULT == "true") {
			onMuteOff();
		}else {
			onMuteOn()
		}
		
		if(Configuration.SOUND_MUTE_DEFAULT=="false"){
		  loadPlayer()
		}
		
				
		 ///color symbol
	   if (Configuration.SMALL_ICON_COLOR_NORMAL != undefined) {
		  NewColor.setColor(symbol, Configuration.SMALL_ICON_COLOR_NORMAL);		   
	   }else{
	   var k:Color = new Color(symbol);
	   k.setTransform( {
           ra: '100', rb: '0',
           ga: '100', gb: '0',
           ba: '100', bb: '0', 
           aa: '100', ab: '0'
        } );
	   }
	   
	   
	}
	
/////////////////////////////////////////////////////////////////////////////////////////////////

    function setOrient() {
		if (Configuration.TOOLS_POSITION == "down") {
		    orient = "TL"	
		}else{
		    orient = "BL"
	    }		
	}

//////////////////////////////////////////////////////////////////////////////////////////////////
  
   function onMuteOff() {
	  this.symbol.gotoAndStop(2)
  }
 
//////////////////////////////////////////////////////////////////////////////
 
  function onMuteOn() {
	  this.symbol.gotoAndStop(1)
  }

///////////////////////////////////////////////////////////////////////////////
 
function onStart_() {
	blockade_press = false;
}

  
//////////////////////////////////////////////////////////////////////////////////////////////////

function onPress() {
	var m:BookModel = BookModel(this.getModel())
	if (blockade_press == true) {
		return;
	}
	var book:BookModel = BookModel(this.getModel())
	if (m.player_mp3_loaded == false) {
		loadPlayer();
		onMuteOn();
		blockade_press = true;
		return;
	}
	if (book.__player.muteSound == true) {
	   book.__player.click_speaker_off=true
       book.__player.muteSound=false
    }
    else {
	   book.__player.click_speaker_off=false
      book.__player.muteSound=true
    }	
}
	
//////////////////////////////////////////////////////////////////////////////////////////////////

 function loadPlayer() {
	var loader:MovieClipLoader = new MovieClipLoader()
	loader.addListener(this)
	var container:MovieClip = containerMusic.createEmptyMovieClip("container2",1)
	loader.loadClip("book_player.swf",container)
}
	
//////////////////////////////////////////////////////////////////////////////////////////////////

function onLoadInit(target:MovieClip) {
	var m:BookModel=BookModel(this.getModel())
	var date = new XML(); ///load date
	var th:PlayerSoundView=this
	date.ignoreWhite = true;
	date.onLoad = function() {
		var config = new XML(); /////load config
		config.ignoreWhite = true;
		config.load(this.firstChild.attributes.url_config);
		config.onLoad = function() {
			
			m.__player = target.ini(date, this);
			m.__player.addEventListener("onInit", th)
			m.__player.addEventListener("onChangedVolume", m)
			m.__player.addEventListener("onMuteOff", th)
			m.__player.addEventListener("onMuteOn", th)
			m.__player.addEventListener("onStart_", th)
			m.__player.init()
					
		};
	};
	date.load(Configuration.MP3_PATHWAY_XML); 
	//createMaskReflection()
}

//////////////////on Init player////////////////////////////////////////////////////////////////////////////////

function onInit() {
	var m:BookModel = BookModel(this.getModel())
    
	/////chapter track
	var chapter:XMLNode = m.getChapter()
	var track = chapter.attributes.track
		
	if (track == undefined) {
		m.__player.current = 0
		
	}else {
		m.__player.__current = 0
	   m.__player.enabledChapter(track)
	   ///m.__player.__volumeMax = 20
	}
	
	/////volume
	var volumeLeft:Number =  Number (m.__pages[m.__currentLeft.__nr].node.attributes.volume)
	var volumeRight:Number =  Number (m.__pages[m.__currentRight.__nr].node.attributes.volume)
	var volume = (volumeLeft == undefined) ? volumeRight : volumeLeft
	
	 if (!isNaN(volume)) {
		   m.__player.__volumeMax=volume
	  }else {
		  m.__player.__volumeMax = 100
	  }
		
	  m.__container.__soundPage.onLoadingLeft()
	  m.__container.__soundPage.onLoadingRight()
      m.player_mp3_loaded = true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

function onLoadPlayer() {
	var m:BookModel = BookModel(this.getModel())
	var book:Book = Book(m.__container)
	var chapterSound:ChapterSoundView = book.__chapterSound
	var soundPage:SoundPageView=book.__soundPage

}

////////////////////////////////////////////////////////////////////////////////////////////

function onResize() {
	var m:BookModel=BookModel(this.getModel())
	 
}

///////////////////////////////////////////////////////////////////////////////////////////

function onSetPage(){
	 
}
//////////////////////////////////////////////////////////////////////////////////////////

}
