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

class templateBook.mvctemplate.CarouselContainerView extends AbstractView {
			 
/////////////////////////////////////////////////////////////////////////////////////////

var __container:MovieClip        //container for carousel
var __loader:MovieClipLoader     //loader
var __shov:Boolean = false       //show OR hide carousel
var tweenAlpha:Tween             //tween alpha
var bcg_big:MovieClip            //backgroud main
var bcg_carousel:MovieClip       //bacground carousel
var btn_close:MovieClip          //button closes


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

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

function CarouselContainerView(){
	__container=this.createEmptyMovieClip("mcContainer",1)
}
 
/////////////////////////////////////////////////////////////////////////////////////////

function onLoad() {
	var m:BookModel = BookModel(this.getModel())
	
	////color bcg big
	if (Configuration.CAROUSEL_BCG_BIG_COLOR != undefined) {
		NewColor.setColor(bcg_big, Configuration.CAROUSEL_BCG_BIG_COLOR.split(",")[0])
		bcg_big._alpha=Configuration.CAROUSEL_BCG_BIG_COLOR.split(",")[1]
	}
	
	//color bcg
	if (Configuration.CAROUSEL_BCG_COLOR != undefined) {
		NewColor.setColor(bcg_carousel.bcg, Configuration.CAROUSEL_BCG_COLOR.split(",")[0])
		bcg_carousel.bcg._alpha=Configuration.CAROUSEL_BCG_COLOR.split(",")[1]
	}
		
	///glow for background
		var obj=bcg_carousel.filters[0]
		obj.color = Configuration.CAROUSEL_GLOW_COLOR
		bcg_carousel.filters = new Array(obj)
		if(Configuration.CAROUSEL_GLOW_VISIBLE=="false"){
		bcg_carousel.filters = new Array()
		}
		
	//button close carousel
		if (Configuration.CAROUSEL_BUTTON_CLOSE_BCG_COLOR != undefined) {
			NewColor.setColor(btn_close.bcg, Configuration.CAROUSEL_BUTTON_CLOSE_BCG_COLOR);
		}
        if (Configuration.CAROUSEL_BUTTON_CLOSE_SYMBOL_COLOR != undefined) {
			NewColor.setColor(btn_close.symbol, Configuration.CAROUSEL_BUTTON_CLOSE_SYMBOL_COLOR);
		}	

	//add events for btn close
	btn_close.onPress = Delegate2.create(this, onPressClose);
		
}

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

function onPressClose() {
	hide();
}

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

function onShowListBook() {
	show()
	loadToContainer("carousel.swf");	
}

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

function onHideListBook() {
		
}

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

function show() {
   this._alpha = 0
   _visible = true
   tweenAlpha.stop();
   tweenAlpha=new Tween(this, '_alpha', Strong.easeOut, 0, 100, 1, true);
}

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

function hide() {
   tweenAlpha.stop();
   tweenAlpha = new Tween(this, '_alpha', Strong.easeInOut, this._alpha, 0, 1, true);	
   tweenAlpha.onMotionFinished=Delegate2.create(this,onHideEnd)
}

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

function onHideEnd() {
	_visible = false
}

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

function loadToContainer(str_:String) {
	    if(!__loader){
	    __loader = new MovieClipLoader()
		__loader.addListener(this)
		}
		__loader.loadClip(str_, __container)
}

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

function removeContainer() {
	__loader.unloadClip(__container)	
}

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

function onLoadInit(target:MovieClip) {
     	var m:BookModel = BookModel(this.getModel())
	    target.model_book=m
    	target.loadDate("xml/books.xml",m.current_book) ////load date XML for carousel
}

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

function onLoadComplete(target:MovieClip) {
	
}

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

function onResize() {
	var m:BookModel = BookModel(this.getModel())
	var book_view:ContainerBookView=m.__container.__containerBook
		
	this._x = m.__width/2
	this._y = m.__height / 2//m.autoSizeMarginH_up+m.getAreaHeight()/2
		
	///bcg
	bcg_big._width = Stage.width + 200
	bcg_big._height = Stage.height + 200
	
	//bcg carousel
	bcg_carousel._width = Stage.width + 200
	bcg_carousel._height = 420
	
	///position for button close
	btn_close._x = m.getAreaWidth()/2 - btn_close._width -10
	btn_close._y = -bcg_carousel._height/2 - 25;

}

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

}

