import mx.controls.streamingmedia.HMiniPlayBarTray;
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;
      
class templateBook.mvctemplate.ThumbView extends AbstractView {
	 
var bcg:MovieClip                     //background thumb
var nr:Number                         //number thumb
var loader:MovieClipLoader            //loader
var content:MovieClip                 //container for image
var bmp:BitmapData                    //bitmap data
var thumbWidth:Number                 //thumb width
var thumbHeight:Number                //thumb height
var marginW:Number = 0                //space width thumb-background
var marginH:Number = 0                //space height thumb-background
var tf_nr:TextField                   //numer thumb
var inter:Number                      //handler for setInterval
var itsBitmap:Boolean = false         //if its Bitmap
var doublePage:Boolean = false        //if double page
var mc_line:MovieClip                 //line for thumb
/////////////////FRAME
var frame:MovieClip                   //frame for thumb
var colorFrame                        //color frame
var alphaFrame:Number                 //alpha frame
var spaceFrame:Number                 //space frame
var sizeFrame:Number                  //size frame
////////// CONFIGURATION
var colorGlowNormal                   //glow   
var colorGlowSelect                   //glow select
var colorBcg                          //background color
var colorNumberPage                   //color for number page

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

	function ThumbView() {
		colorGlowNormal = Configuration.COLOR_GLOW_NORMAL_THUMB_LIST
		colorGlowSelect = Configuration.COLOR_GLOW_SELECT_THUMB_LIST
		colorBcg = Configuration.COLOR_BACKGROUND_THUMB_LIST
		colorNumberPage = Configuration.COLOR_NUMBER_PAGE_THUMB_LIST
		var m:BookModel = BookModel(BookModel.getInstance())
		thumbWidth = m.thumbWidth
		thumbHeight = m.thumbHeight
		content = this.createEmptyMovieClip("mcContent", 1)
		content._x = marginW
		content._y = marginH
		loader = new MovieClipLoader()
		loader.addListener(this)
		bcg._width = thumbWidth + 2 * marginW
		bcg._height = thumbHeight + 2 * marginH
		frame=this.createEmptyMovieClip("mcFrame",103)
	}
		
//////////////////////////////////////////////////////////////////////////////////////////////////

    function onLoad() {
		var m:BookModel = BookModel(BookModel.getInstance())
		if (Configuration.REVERSE_BOOK == "true") {
		tf_nr.text = String((m.getPageLength()-nr)+1)
		}else{
		tf_nr.text = String(nr)
		}
				
		tf_nr.textColor=colorNumberPage
		tf_nr.autoSize="right"
		tf_nr._x = thumbWidth-17//-tf_nr._width/2
		tf_nr._y = bcg._height / 2 - tf_nr._height / 2 + 138
		
		///position line
		mc_line._x = tf_nr._x - 5
		mc_line._y = m.thumbHeight+35
		NewColor.setColor(mc_line, colorNumberPage);

		if (doublePage == true&&nr%2!=0) {
		var mask:MovieClip = this.createEmptyMovieClip("maskBcg", 432324)
		mask._x = 3
		mask._y = 0
		Drawing.rectangle(mask,0,0,bcg._width,bcg._height,["0xFF0000",50])
		bcg.setMask(mask)	
		}
		NewColor.setColor(bcg.bcg,colorBcg)
		/*
		var obj=bcg.filters[0]
	    obj.color=colorGlowNormal
	    bcg.filters = new Array(obj)
		/*/
}

//////////////////////////////////////////////////////////////////////////////////////////
  
   function onPress() {
	 var m:BookModel = BookModel(BookModel.getInstance())
	 if(Configuration.REVERSE_BOOK=="true"){
	    var nr_page:Number = (m.getPageLength() - nr) + 1
	 }else {
	    var nr_page:Number = nr
	 }
	 m.setPage(nr_page)
	 m.hideThumbs()
	 clearInterval(inter)
   }
   
//////////////////////////////////////////////////////////////////////////////////////////   
 
function inter_setPage() {
	clearInterval(inter)
	 var m:BookModel = BookModel(BookModel.getInstance())
	  m.hideThumbs()
}

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

  function onRollOver() {
	  
  }

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

  function onRollOut() {
	  
  }

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

function select() {
	var space:Number = spaceFrame
	var w:Number = thumbWidth+space*2
	var h:Number = thumbHeight+space*2
	frame._x = -space
	frame._y = -space
	///////color glow
	/*
	var obj=bcg.filters[0]
	obj.color=colorGlowSelect
	bcg.filters=new Array(obj)
	/*/
	//////////////////frame ( optional )
	colorFrame = colorGlowSelect
		
	if(doublePage==false){
      Drawing.frame(frame, sizeFrame, w, h, [colorFrame, alphaFrame])
	}else {
		frame._x += 2
		frame._y += 2
		w -= 4
		h -= 4
		if (nr % 2 == 0) {
		frame.lineStyle(sizeFrame, colorFrame, alphaFrame)
		frame.moveTo(0, 0)
		frame.lineTo(0, h)
		frame.lineTo(w, h)
		frame.moveTo(0, 0)
		frame.lineTo(w,0)
		}else {
		frame.lineStyle(sizeFrame, colorFrame, alphaFrame)
		frame.moveTo(0, 0)
		frame.lineTo(w, 0)
		frame.lineTo(w, h)
		frame.lineTo(0,h)
			
		}
	}
   this.enabled=true
}

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

function unSelect() {
	/*
	var obj=bcg.filters[0]
	obj.color=colorGlowNormal
	bcg.filters = new Array(obj)
	/*/
	frame.clear();
	this.enabled=true
}
  
//////////////////////////////////////////////////////////////////////////////////////////

  function addBitmap(bmp_:BitmapData) {
	 // if (itsBitmap == false){
	  content.attachBitmap(bmp_,1,"auto",true)
	  var resize:Resize=new Resize(thumbWidth,thumbHeight,content._width,content._height)
	  var obj:Object = resize.min()
	  content._width = thumbWidth//obj.w
	  content._height = thumbHeight//obj.h
	  itsBitmap=true
	 // }
}

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

function loadImage(url_:String) {
	content.loadMovie(url_)
}

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

}
