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.HolderPrintView extends AbstractView {

	
var container:MovieClip           //container image for print
var bmp:BitmapData                //bitmap data
var pj:PrintJob                   //object print job
var chose_page:MovieClip          //page for print

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

	function HolderPrintView() {
		container = this.createEmptyMovieClip("mcContainer", 1)
		container._visible = false
	}
		
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onLoad() {
				
	}
	
//////////////////////////////////////////////////////////////////////////////////////////////////

   function onSetPrintPage() {
	   var m:BookModel = BookModel(this.getModel())
	   var nr:Number = m.getPrintPage()
	   copy_page(nr)
   }

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

    function copy_page(nr_:Number) {
	   var m:BookModel = BookModel(this.getModel())
	   var page:PageView = m.getPage(nr_)
	   var content:MovieClip = page.content
	   var w:Number = Number(Configuration.PAGE_WIDTH)
	   var h:Number = Number(Configuration.PAGE_HEIGHT)
	   var margin:Number = 20
	   
	   /////draw
	   bmp = new BitmapData(w,h, true, 0xFF0000)
	   bmp.draw(page.bitmap)

	   ////atach
	   Drawing.rectangle(container, 0, 0, w + margin * 2, h + margin * 2, ["0xFFFFFF",0])
	   var container_bitmap:MovieClip = container.createEmptyMovieClip("mcContainerBitmap", 1)
	   container_bitmap._x = margin
	   container_bitmap._y = margin
	   container_bitmap.attachBitmap(page.bitmap, 1, "auto", true)
	 	   
	   
	   var pj:PrintJob = new PrintJob()
	   var success= pj.start();
				
				if (success) {
					//////optional
					var xMiner = -margin
					var xMaxer = pj.pageWidth;
					var yMiner = -margin
					var yMaxer = pj.pageHeight;
					var maxer_miner = { xMin:xMiner, xMax:xMaxer, yMin:yMiner ,yMax:yMaxer }
					
					/////rescale
					var resize:Resize = new Resize(pj.paperWidth, pj.paperHeight, container._width, container._height)
					var new_size:Object = resize.min()
					container._width = new_size.w 
					container._height = new_size.h 															
					
					pj.addPage(container,null,{printAsBitmap:true});
					///trace("xMiner = "+xMiner+" / xMaxer = "+ pj.pageWidth+"yMiner = "+yMiner+" /  yMaxer = "+yMaxer)
					//trace(pj.pageWidth+ " / "+pj.pageHeight +" | | "+pj.paperWidth+" / "+pj.paperHeight)
					pj.send();
				}
   }

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



 
}
