import templateBook.mvctemplate.*
import templateBook.mvc.*
import templateBook.I.*
import flash.display.BitmapData
import templateBook.util.Observable
import templateBook.Configuration
import mx.transitions.Tween;

class templateBook.mvctemplate.AreaHornView extends AbstractView {
	
var oldCurrentRight:SheetView		
var oldCurrentLeft:SheetView

var right_down:MovieClip
var left_down:MovieClip
var right_up:MovieClip
var left_up:MovieClip

var right:SheetView
var left:SheetView 

var __inter
	
/////////////////////////////////////////////////////////////////////////////////////////

public function defaultController (model:Observable):Controller {
  return null;
 }
 
/////////////////////////////////////////////////////////////////////////////////////////

function AreaHornView(){
	  
}
 
/////////////////////////////////////////////////////////////////////////////////////////

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

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

function onResize(){
	var m:BookModel = BookModel(this.getModel())
	var book:Book=m.__container
	
	this._x = Configuration.PAGE_WIDTH
	this._y =0// Configuration.PAGE_HEIGHT*2
	
}

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

function onSetPage()
{
	 create_area_right()
}

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

function onTweenPageEnd() {
	  var m:BookModel = BookModel(this.getModel())
	   
	  if(m.__currentLeft!=undefined){
	  oldCurrentLeft = m.__currentLeft
	  }
	  
	  if(m.__currentRight!=undefined){
	  oldCurrentRight = m.__currentRight
	  }
	  
	 show()
}

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

function onSheetBackEnd() {
	// hide()
	/// show()	
	if(hitTestMc(right_up)){
	onRollOverRight("up")
	}
	
	if(hitTestMc(right_down)){
	onRollOverRight("down")
	}
	
	if (hitTestMc(left_up)) {
		onRollOverLeft("up")
	}
	
	if (hitTestMc(left_down)) {
		onRollOverLeft("down")
	}
}

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

function hitTestMc(mc_:MovieClip) {
	if (mc_.hitTest(_root._xmouse, _root._ymouse, true)) {
		return true;
	}else {
		return false;
	}
	
}

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

function onStartDragSheet() {
	//hide()
}

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

function onSheetBackStart() {
	//hide()
}

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

function show() {
	 var m:BookModel = BookModel(this.getModel())
	 m.__hornVisible=true
	 right_down._visible=true
	 left_down._visible=true
	 right_up._visible=true
	 left_up._visible=true	
}

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

function hide() {
	 var m:BookModel = BookModel(this.getModel())
	 m.__hornVisible=false
	 right_down._visible=false
	 left_down._visible=false
	 right_up._visible=false
	 left_up._visible=false
	
}

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

function onTweenPageStart(){
   	 hide()
}

////////////create area horn///////////////////////////////////////////////////////////////////////////////////////////

function create_area_right() {
	clearInterval(__inter)
	var m:BookModel = BookModel(this.getModel())
	var margin:Number=1
	
	//////right down
	right_down = create_clip("right_down_",1)
	right_down._x = (Configuration.PAGE_WIDTH+Configuration.FRAME_SHEET*2)-Configuration.HORN_AREA-margin
	right_down._y = (Configuration.PAGE_HEIGHT + Configuration.FRAME_SHEET * 2) - Configuration.HORN_AREA - margin
	right_down.onRollOver = Delegate2.create(this, this.onRollOverRight,"down")
	///right_down.onRollOut = Delegate2.create(this, this.onRollOutRight)
	//right_down.onReleaseOutside = Delegate2.create(this, this.onRollOutRight)
	
	
	
	//////left down
	left_down = create_clip("left_down_",2)
	left_down._x = -(Configuration.PAGE_WIDTH+Configuration.FRAME_SHEET*2)+margin
	left_down._y = (Configuration.PAGE_HEIGHT + Configuration.FRAME_SHEET * 2) - Configuration.HORN_AREA - margin
	left_down.onRollOver = Delegate2.create(this, this.onRollOverLeft,"down")
	///left_down.onRollOut = Delegate2.create(this, this.onRollOutLeft)
	//left_down.onReleaseOutside = Delegate2.create(this, this.onRollOutRight)
	
		
	//////right up
	right_up = create_clip("right_up_",3)
	right_up._x = (Configuration.PAGE_WIDTH+Configuration.FRAME_SHEET*2)-Configuration.HORN_AREA-margin
	right_up._y =  margin
	right_up.onRollOver = Delegate2.create(this, this.onRollOverRight,"up")
	///right_up.onRollOut=Delegate2.create(this,this.onRollOutRight)
	//right_up.onReleaseOutside = Delegate2.create(this, this.onRollOutRight)
	
	//////left up
	left_up = create_clip("left_up_",4)
	left_up._x = -(Configuration.PAGE_WIDTH+Configuration.FRAME_SHEET*2)+margin
	left_up._y =  margin
	left_up.onRollOver = Delegate2.create(this, this.onRollOverLeft,"up")
	//left_up.onRollOut = Delegate2.create(this, this.onRollOutLeft)
	//left_up.onReleaseOutside = Delegate2.create(this, this.onRollOutRight)
}
 
//////////////////////////////////////////////////////////////////////////////////////////////////////

function create_clip(name_,dep_) {
	var dep:Number=dep_//this.getNextHighestDepth()
	var mc:MovieClip = this.createEmptyMovieClip(name_+dep, dep)
	Drawing.rectangle(mc, 0, 0, Configuration.HORN_AREA, Configuration.HORN_AREA, ["0xFF0000",0])
	mc.useHandCursor=false
	return mc;
}

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

function reset() {
	  delete this.onEnterFrame	
	  hide()
}

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

private function onRollOverRight(pos_) {
	var m:BookModel = BookModel(this.getModel())
	
	
	if(m.blockade_page_over==false&&m.__blockade==false&&m.__container.__containerClip.__shov==false&&m.allVisibleBook()==true&&Configuration.DRAG_PAGE=="true"){
	//if(this._visible==true&&m.__container.__containerClip.__shov==false&&m.allVisibleBook()==true&&Configuration.DRAG_PAGE=="true"){
	
	if (pos_ == "up") {
		m.__position="up"
	}else {
		m.__position="down"
	}
	right =  m.__currentRight
	
	delete this.onEnterFrame
	
		if(m.__position=="up"){		
	right._sx = 0
	right._sy = 0
		}else {
		right._sx = 0
	right._sy = right.__height
			
	}
	
	right.stopTweny()
	right.setFirstXY()
	right.OEF(right._xmouse,right._ymouse)
	this.onEnterFrame = function() {
		right.OEF(right._xmouse, right._ymouse)
		
		if (!this.hitTest(_root._xmouse, _root._ymouse, true)) {
			onRollOutRight()
		}
	}
	}
	
	
	
	
}

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

function onRollOutRight() {
	var m:BookModel = BookModel(this.getModel())
	delete this.onEnterFrame
	if(m.__hornVisible==true){
	m.__currentRight.pageExit(undefined, "horn")
	}
}

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

function onRollOverLeft(pos_) {

	var m:BookModel = BookModel(this.getModel())
	
	if(m.blockade_page_over==false&&m.__blockade==false&&m.__container.__containerClip.__shov==false&&m.allVisibleBook()==true&&Configuration.DRAG_PAGE=="true"){
	//if(this._visible==true&&m.__container.__containerClip.__shov==false&&m.allVisibleBook()==true&&Configuration.DRAG_PAGE=="true"){
	
	
	if (pos_ == "up") {
		m.__position="up"
	}else {
		m.__position="down"
	}
	
	var book:Book = m.__container
	if(m.__currentLeft!=undefined){
	oldCurrentLeft = m.__currentLeft
	}
	
	left =m.__currentLeft 
		
	 delete this.onEnterFrame
	 
		if(m.__position=="up"){		
	left._sx = left.__width
	left._sy = 0
		}else {
		left._sx = left.__width
	left._sy = left.__height
			
		}
		
		
	 left.setFirstXY()
	left.OEF(left._xmouse, left._ymouse)
	 
	left.stopTweny()
	this.onEnterFrame = function() {
		
	left.OEF(left._xmouse, left._ymouse)
	
	if (!this.hitTest(_root._xmouse, _root._ymouse, true)) {
			onRollOutLeft()
	}
		
	}
	
	
	}
	
}

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

function onRollOutLeft() {

  var m:BookModel=BookModel(this.getModel())
   delete this.onEnterFrame
  if(m.__hornVisible==true){
  m.__currentLeft.pageExit(undefined, "horn")
   }

}

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

function dispose() {
	delete this.onEnterFrame	
}

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



}

