import mx.controls.streamingmedia.HMiniPlayBarTray;
import mx.transitions.easing.Strong;
import mx.transitions.Tween;
import mx.transitions.easing.*
import templateBook.mvctemplate.*
import templateBook.mvc.*
import templateBook.I.*
import flash.display.BitmapData
import templateBook.util.Observable
import templateBook.Configuration
import flash.filters.GlowFilter;
    
class templateBook.mvctemplate.ToolsView extends AbstractView {
		
private var __numberPageView:NumberPageView           //instance NumberPageView
var __prevChapter:PrevChapterView                     //prev chapter
var __nextChapter:NextChapterView                     //next chapter
var __prev:PrevButtonView                             //prev button
var __next:NextButtonView                             //next button
var __orginalDepths:Number                            //first depths
var __yOrginal:Number                                 //first position y
var __xOrginal:Number                                 //first position x
var zoom_in:ZoomInView                                //instance ZoomInView
var zoom_out:ZoomOutView                              //instance ZoomOutView
var zoom_orginal:ZoomOrginalView                      //instance ZoomOrginalView
var zoom_auto:ZoomAutoView                            //instance ZoomAutoView
var player_sound:PlayerSoundView                      //instance PlayerSound
var printButton:ButtonPrintView                       //instance ButtonPrintView
var form:FormButtonView                               //instance FormButtonView
var download:DownloadView                             //instance DownloadView
var full_screen:FullScreenView                        //instance FullScreenView
var button_list:ButtonListView                        //instance ButtonListView
var logo:LogoView                                     //instance LogoView
var bcg:MovieClip                                     //background
var inter_show:Number                                 //handler for setInterval
var buttonHome:ButtonHomeView                         //instance ButtonHomeView
var line_footer:MovieClip                             //line for tools
var tween:Tween                                       //tween
var __inter:Number                                    //handler for setInterval
var container1:MovieClip                              //container1 for icon
var container2:MovieClip                              //container2 for icon (sound,form,fullscreen)
var colorBcg:String                                   //color for background
var colorSep                                          //color separator


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

	function ToolsView() {
		_visible=false
		colorBcg = Configuration.TOOLS_BACKGROUND_COLOR.split(",")[0];
		colorSep = Configuration.TOOLS_COLOR_SEP
	}
		
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onLoad() {
		/////container1
		download = container1.download
		printButton = container1.printButton
		zoom_in = container1.zoom_in
		zoom_out = container1.zoom_out
		zoom_orginal = container1.zoom_orginal
		zoom_auto = container1.zoom_auto
		button_list = container1.button_list
		buttonHome = container1.buttonHome
				
		////container2
		form = container2.form
		player_sound = container2.player_sound
		full_screen = container2.full_screen
				
		var m:BookModel = BookModel(BookModel.getInstance()) 
		
		__orginalDepths=getDepth()
		_addListeners()
		
		if(m.toolsPosition=="down"){
		this._y = __yOrginal + 300
		}else {
		this._y = __yOrginal - (m.toolsHeight+50)
		}
		
		if (Configuration.TOOLS_VISIBLE == "false") {
			this._visible=false
		}
				
		//TOOLS
		
		//color bcg
		if(colorBcg!=undefined){
		NewColor.setColor(container1.bcg, colorBcg)
		NewColor.setColor(container2.bcg, colorBcg)
		}
		//alpha bcg
		container1.bcg._alpha = Configuration.TOOLS_BACKGROUND_COLOR.split(",")[1];
		
		//color line
		if(Configuration.TOOLS_LINE_COLOR!=undefined){
		NewColor.setColor(line_footer, Configuration.TOOLS_LINE_COLOR);
		}

		if (colorSep != undefined) {
		NewColor.setColor(container1.sep,colorSep)				
		NewColor.setColor(container2.sep,colorSep)					
		}
		
		/////color bcg small icon
		if(Configuration.SMALL_ICON_COLOR_BCG!=undefined){
		NewColor.setColor(container2.bcg, Configuration.SMALL_ICON_COLOR_BCG)
		}
		
		onResize()
	}
	
	
////////////////////////////////////////////////////////////////////////////////////////////////

function onFaceBook() {
	_alpha=0
	_visible = true	
	var tweenInTools = new Tween(this, "_alpha",Strong.easeInOut, 0, 100, 2, true);	
}

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

function show() {
	    clearInterval(inter_show)
	 	tween = new Tween(this, '_y', Strong.easeOut,_y , __yOrginal, 1, true)
		tween.onMotionFinished = Delegate2.create(this, onEnd)
		//player_sound.loadPlayer()
}

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

function hide() {
		
}

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

    function onEnd() {
		clearInterval(__inter)
		__inter=setInterval(this,'loadPlayerAndBackground',1000)
	}
	
////////////////////////////////////////////////////////////////////////////////////////////////	

function swapDepthsOrginal() {
	this.swapDepths(__orginalDepths)
}

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

function swapDepthsToDown() {
	swapDepths(13)
}

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

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

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

function loadPlayerAndBackground() {
	clearInterval(__inter)	
	var m:BookModel=BookModel(this.getModel())
}

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

   function onLoadBackground() {
	    	shov_delay()
	 }
	
//////////////////////////////////////////////////////////////////////////////////////////////////	
	
function shov_delay() {
	clearInterval(inter_show)
	inter_show=setInterval(this,'show',1500)
	
}

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

  function onResize() {
	var m:BookModel = BookModel(this.getModel())
	var book_view:BookView = m.__container.__bookView
	tween.stop()

	/////container1
	if(m.change_positions_book()==false){
	container1._x = m.__container.__containerBook._x + m.getWidthCurrent()/2-278/2
	container1._y = m.__height - 60
	container1.bcg._x = -container1._x
	container1.bcg._width = m.__width;
	}
				
	/////container2 ( with flip book )
	if(m.change_positions_book()==false){
	container2._x= m.__width-105//( m.__container.__containerBook._x+m.getWidthCurrent()   ) - 133+30
	container2._y = m.__height - 55
	line_footer._x = 0
	line_footer._y =  m.__height - 63
    }
		
	this._x = 0;
	this._y = 0;
 }

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


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

 //////number Page
/*
 __numberPageView.setModel(m)
 m.addEventListener("onResize",__numberPageView)
 m.addEventListener("onSetPage",__numberPageView)
 m.addEventListener("onNextPage",__numberPageView)
 m.addEventListener("onPrevPage", __numberPageView)

 
 m.removeEventListener("onTweenPageEnd",__numberPageView)
 m.addEventListener("onTweenPageEnd",__numberPageView)
  /*/
  
 ////prev chaper
 m.__container.__prevChapter=__prevChapter
 __prevChapter.setModel(m)
 m.addEventListener("onResize",__prevChapter)
 m.addEventListener("onSetPage",__prevChapter)
 m.addEventListener("onNextPage",__prevChapter)
 m.addEventListener("onPrevPage",__prevChapter)
 m.addEventListener("onTweenPageEnd", __prevChapter)
 
 ///next chapter
 m.__container.__nextChapter=__nextChapter
 __nextChapter.setModel(m)
 m.addEventListener("onResize", __nextChapter)
 m.addEventListener("onSetPage",__nextChapter)
 m.addEventListener("onNextPage",__nextChapter)
 m.addEventListener("onPrevPage",__nextChapter)
 m.addEventListener("onTweenPageEnd", __nextChapter)
  
 /*
 ////prev sheet
 __prev.setModel(m)
 m.addEventListener("onResize",this.__prev)
 m.addEventListener("onSetPage",this.__prev)
 m.addEventListener("onNextPage",this.__prev)
 m.addEventListener("onPrevPage",this.__prev)
 m.addEventListener("onTweenPageEnd", this.__prev)
 
 ////next sheet
 __next.setModel(m)
m.addEventListener("onResize", this.__next)
 m.addEventListener("onSetPage",this.__next)
 m.addEventListener("onNextPage",this.__next)
 m.addEventListener("onPrevPage",this.__next)
 m.addEventListener("onTweenPageEnd", this.__next)
 /*/
 
 /////zoom
 zoom_in.setModel(m)
 zoom_out.setModel(m)
 zoom_orginal.setModel(m)
 zoom_auto.setModel(m)
  
 //////player Sound
 player_sound.setModel(m)
 m.addEventListener("onResize", player_sound)
 
 /////print buttton
 printButton.setModel(m)
 m.addEventListener("onResize",  printButton)
 
 ////form
 form.setModel(m)
 m.addEventListener("onResize",form) 
 
 ////downlaod
 download.setModel(m)
 m.addEventListener("onResize",download)
 
 ////full screen
 full_screen.setModel(m)
 m.addEventListener("onResize", full_screen)
 
 ////buttton list
 button_list.setModel(m)
 m.addEventListener("onResize",button_list)
  
 /////logo
/// logo.setModel(m)
/// m.addEventListener("onResize", logo)
  
 ///// button home
 buttonHome.setModel(m)
 m.addEventListener("onResize",buttonHome)
	
}

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


}
