import mx.controls.streamingmedia.HMiniPlayBarTray;
import mx.transitions.easing.Strong;
import mx.transitions.Tween;
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 PrintJob

class templateBook.mvctemplate.PrintChooseView extends AbstractView {
	
var container:MovieClip             //container
var left:MovieClip                  //button left
var right:MovieClip                 //button right
var mcClose:MovieClip               //button close
var tweenShov:Tween                 //tween show print
var tweenHide:Tween                 //tween hide print
var background:MovieClip            //background  
var title:TextField                 //title
var tweenLeft:Tween                 //tween button left
var tweenRight:Tween                //tween button right
var rectangle_over:MovieClip        //rectangle if mouse over
var background_big:MovieClip        //background print

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

	function PrintChooseView() {
		_visible=false
	}
		
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onLoad() {
		
		////create_background_big
		background_big = this.createEmptyMovieClip("background_big", 1);
		Drawing.rectangle(background_big, 0, 0,Stage.width,Stage.height, [Configuration.PRINT_BIG_BCG_COLOR.split(",")[0], Configuration.PRINT_BIG_BCG_COLOR.split(",")[1]]);
		container.swapDepths(2);
		background_big.onPress = function() { }
		background_big.enabled = false
		
		
		///glow for background
		var bcg_print:MovieClip = container.background;
		var obj=bcg_print.filters[0]
		obj.color = Configuration.GLOW_COLOR_BCG_PRINT
		bcg_print.filters = new Array(obj)
	    if (Configuration.GLOW_COLOR_BCG_PRINT_VISIBLE == "false") {
		bcg_print.filters = new Array()
		}
		
		
		left = container.left
		right = container.right
		mcClose = container.mcClose
		background = container.background
		title = container.title
		
		left.onPress = Delegate2.create(this, onPressLeft)
		left.onRollOver = Delegate2.create(this, onRollOverLeft)
		left.onRollOut = Delegate2.create(this, onRollOutLeft)
		
		right.onPress = Delegate2.create(this, onPressRight)
		right.onRollOver = Delegate2.create(this, onRollOverRight)
		right.onRollOut = Delegate2.create(this, onRollOutRight)
		
		mcClose.onPress = Delegate2.create(this, onPressClose)
		mcClose.onRollOver = Delegate2.create(this, onRollOverClose)
		mcClose.onRollOut = Delegate2.create(this, onRollOutClose)
		
		////color
		var colorBcg = Configuration.COLOR_BACKGROUND_PRINT.split(",")[0]
		var alphaBcg=  Configuration.COLOR_BACKGROUND_PRINT.split(",")[1]
		NewColor.setColor(background.background2, colorBcg)
		background.background2._alpha = alphaBcg
		
		/////title
		title.text = Configuration.TITLE_PRINT
		title.textColor = Configuration.COLOR_TITLE_PRINT
		
		/////button close symbol
		if(Configuration.COLOR_SYMBOL_CLOSE_PRINT!=undefined){
		NewColor.setColor(mcClose.symbol, Configuration.COLOR_SYMBOL_CLOSE_PRINT)
		}
		/////button close bcg
		if(Configuration.COLOR_BCG_CLOSE_PRINT!=undefined){
		NewColor.setColor(mcClose.bcg, Configuration.COLOR_BCG_CLOSE_PRINT)
		}
				
		
		////color page
		NewColor.setColor(left.bcg.symbol, Configuration.COLOR_PAGE_PRINT)
		NewColor.setColor(right.bcg.symbol, Configuration.COLOR_PAGE_PRINT)
		
		/////COLOR glow page
		var obj=left.filters[0]
	    obj.color = Configuration.COLOR_GLOW_PAGE_PRINT
		left.filters = new Array(obj)
		
		
		var obj=right.filters[0]
	    obj.color = Configuration.COLOR_GLOW_PAGE_PRINT
		right.filters = new Array(obj)
		
		
		////title page
		left.bcg.title.text = Configuration.TITLE_LEFT_PAGE_PRINT
		left.bcg.title.textColor= Configuration.COLOR_TITLE_PAGE_PRINT
		right.bcg.title.text = Configuration.TITLE_RIGHT_PAGE_PRINT
		right.bcg.title.textColor= Configuration.COLOR_TITLE_PAGE_PRINT
		
		
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////

    function onChoosePrint() {
		shov()
	}
	
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onPressClose() {
		hide()		
	}
	
//////////////////////////////////////////////////////////////////////////////////////////////////

   function onRollOverClose() {
	   delete mcClose.symbol.onEnterFrame
	   mcClose.symbol.play()
   }

//////////////////////////////////////////////////////////////////////////////////////////////////
	
   function onRollOutClose() {
	   mcClose.symbol.onEnterFrame = function() {
		   this.prevFrame()
		   if (this._currentframe <= 1) {
			   delete this.onEnterFrame
		   }
		   
	   }
	   
   }

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

   function onPressLeft() {
	   var m:BookModel = BookModel(this.getModel())	   
	   m.printPage(m.__currentLeft.__nr)
	   hide()
	   
	 
		onRollOutLeft();
		
   }
 
  //////////////////////////////////////////////////////////////////////////////////////////////////
  
  function onRollOverLeft() {
	  
	//color text 
	left.bcg.title.textColor = Configuration.COLOR_TITLE_PAGE_PRINT_OVER;
	//var obj=left.filters[0]
	//obj.color = Configuration.COLOR_GLOW_OVER_PAGE_PRINT
	/// left.filters = new Array(obj)	  
	//tweenLeft.stop() 	 
	// tweenLeft=new Tween(left.bcg, '_y', Strong.easeInOut,left.bcg._y,15, .5, true)
	rectangle_over = left.bcg.mc_empty.attachMovie("_print_rect_over", "_print_rect_over_", 1);
	   
	  if( Configuration.PRINT_BUTTON_OVER_COLOR ){
	  NewColor.setColor(rectangle_over, Configuration.PRINT_BUTTON_OVER_COLOR)
	  }

  }
  
  //////////////////////////////////////////////////////////////////////////////////////////////////
   
  function onRollOutLeft() {
	  ///color text
	  left.bcg.title.textColor = Configuration.COLOR_TITLE_PAGE_PRINT
	  /// tweenLeft.stop()
	  ///tweenLeft=new Tween(left.bcg, '_y', Strong.easeInOut,left.bcg._y,0, .5, true)
	  rectangle_over.removeMovieClip();
	  // var obj=left.filters[0]
	  //obj.color = Configuration.COLOR_GLOW_PAGE_PRINT
	  /// left.filters = new Array(obj)
  }
  
   //////////////////////////////////////////////////////////////////////////////////////////////////
  
  function onRollOverRight() {
	  //color text 
	  right.bcg.title.textColor = Configuration.COLOR_TITLE_PAGE_PRINT_OVER;
	  //var obj=right.filters[0]
	  //obj.color = Configuration.COLOR_GLOW_OVER_PAGE_PRINT
	  //right.filters = new Array(obj)	 
	  ///tweenRight.stop() 	 
	  ///tweenRight=new Tween(right.bcg, '_y', Strong.easeInOut,right.bcg._y,15, .5, true)
	  rectangle_over = right.bcg.mc_empty.attachMovie("_print_rect_over", "_print_rect_over_", 1);
	   if( Configuration.PRINT_BUTTON_OVER_COLOR ){
	     NewColor.setColor(rectangle_over, Configuration.PRINT_BUTTON_OVER_COLOR)
	   }
  }
  
  //////////////////////////////////////////////////////////////////////////////////////////////////
   
  function onRollOutRight() {
	  //color text 
	  right.bcg.title.textColor = Configuration.COLOR_TITLE_PAGE_PRINT;
	  //var obj=right.filters[0]
	  //obj.color = Configuration.COLOR_GLOW_PAGE_PRINT
	  ///right.filters = new Array(obj)
	  //tweenRight.stop()
	  //tweenRight=new Tween(right.bcg, '_y', Strong.easeInOut,right.bcg._y,0, .5, true)
	  rectangle_over.removeMovieClip();
  }
  
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 function onPressRight() {
	 var m:BookModel = BookModel(this.getModel())
	 m.printPage(m.__currentRight.__nr)
	 hide()
	 onRollOutRight()
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 function onResize() {
	 var m:BookModel = BookModel(this.getModel())
	 container._x = m.__width/2-325/2
	 container._y = m.__container.__containerBook._y + m.getHeightCurrent()/2-160/2
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 function shov() {
	 reset_tween()
	 _visible = true
	 this._alpha = 0
	 tweenShov.stop()
	 tweenShov = new Tween(this, '_alpha', Strong.easeInOut,this._alpha,100, 1, true)
	 tweenShov.onMotionFinished=Delegate2.create(this,shovEnd)
 }

//////////////////////////////////////////////////////////////////////////////////////////////////
 
  function shovEnd() {
	
  }
 
//////////////////////////////////////////////////////////////////////////////////////////////////

function reset_tween() {
	tweenHide.stop()
	tweenShov.stop()
}
  
//////////////////////////////////////////////////////////////////////////////////////////////////

  function hide() {
	reset_tween()  
	tweenHide = new Tween(this, '_alpha', Strong.easeInOut,this._alpha,0,1,true)
	tweenHide.onMotionFinished = Delegate2.create(this, hideEnd)
	tweenLeft.stop()
	tweenRight.stop()
	left.bcg._y = 0
	right.bcg._y = 0
}
  
//////////////////////////////////////////////////////////////////////////////////////////

   function hideEnd() {
	   reset_tween()
	   _visible=false	   
   }
	  
	
//////////////////////////////////////////////////////////////////////////////////////////////////

   function onSetPrintPage() {
	 
   }

//////////////////////////////////////////////////////////////////////////////////////////
 
}
