
import templateBook.template_form.mvctemplate.*
import templateBook.template_form.mvc.*
import templateBook.template_form.I.*

import flash.display.BitmapData
import templateBook.template_form.util.Observable

import mx.transitions.Tween
import mx.transitions.easing.*

import templateBook.template_form.Configuration




 
    

class templateBook.template_form.mvctemplate.IconView extends AbstractView {
		
var tween
var widthIcon:Number
var heightIcon:Number
var spaceIcon:Number
var positionX:Number
var positionY:Number
var container:MovieClip
var url_data_icon:String
var data_icon:XML
var dir:Number
var orientation:String
var loader:MovieClipLoader
var alphaOut:Number
var alphaOver:Number
var marginX:Number
var marginY:Number


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

function IconView(){

}

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

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

function onLoad() {
	
		// init() 
}

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

function onLoadLogo() {
	
	if(Configuration.ICON_VISIBLE=="true"){
         //  init()	
	}
}


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


function onChangedPositionMenu() {
	/*
	var m:LoaderModel = LoaderModel(this.getModel())	
	var template = m.currentNode.attributes.template
	var alpha:Number
	
	if (template == "book"||m.currentNode.attributes.social_icon=="false") {
	 alpha = 0	
	 this.tween('_alpha',alpha, .6, 'easeOutCubic');
	}else {
	 alpha = 100	
	 this.tween('_alpha',alpha, .6, 'easeOutCubic');
	}
    /*/
}

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

function onIntroEnd() {
	//var m:LoaderModel = LoaderModel(this.getModel())	
	//var template = m.currentNode.attributes.template
	//var alpha:Number
	
	//if (template != "book"||m.currentNode.attributes.social_icon==undefined) {
	 //this.tween('_alpha',100, .6, 'easeOutCubic');
	//}	

}


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

function init() {
	if(Configuration.ICON_VISIBLE=="true"){
	widthIcon = Number(Configuration.WIDTHICON)
	heightIcon = Number(Configuration.HEIGHTICON)
	spaceIcon = Number(Configuration.SPACEICON)
	url_data_icon = Configuration.URL_DATA_ICON
	dir = 0
	orientation = "h"
	alphaOut = Number(Configuration.ICON_ALPHAOUT)
	alphaOver = Number(Configuration.ICON_ALPHAOVER)
	marginX = Number(Configuration.ICON_MARGINX)
	marginY = Number(Configuration.ICON_MARGINY)
			
	
   loader = new MovieClipLoader()
   loader.addListener(this)
   
	
   load_data()
   onResize()		
	}
}

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

function onLoadMenuTree() {

	
}

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

function onResize(){
	//var m:LoaderModel=LoaderModel(this.getModel())
	this._x = 146
	this._y = 210
}

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

function load_data() {
	data_icon = new XML()
	data_icon.ignoreWhite = true
	data_icon.onLoad = Delegate2.create(this, onLoadData)
	data_icon.load(url_data_icon)
}

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

function onLoadData() {
	create_icon()
}


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

function getSize():Number {
	var size:Number
	var length:Number = data_icon.firstChild.childNodes.length	
	
	
	if (orientation == "h") {
		 size=(widthIcon+spaceIcon)*length-spaceIcon
	}else {
		 size=(heightIcon+spaceIcon)*length-spaceIcon	
	}
	
	return size;
}

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


private function create_icon() {
	
	
	
	container = this.createEmptyMovieClip("mcContainer", 1)
	
	for (var i = 0; i < data_icon.firstChild.childNodes.length; i++) {
		var node:XMLNode = data_icon.firstChild.childNodes[i]
		var path:String = node.attributes.path
		var redirect:String = node.attributes.redirect
			
		var item:MovieClip = container.createEmptyMovieClip("mcIcon" + i, i)
		item._alpha=alphaOut
		item.redirect=redirect
		var containerItem:MovieClip = item.createEmptyMovieClip("container", 1)
		
		/////////if horizontal
		if (orientation == "h") {
			
		if(dir==1){
		item._x = i * ( (widthIcon) + spaceIcon) 
		}else if(dir==-1) {
		item._x = i * ( (-widthIcon) - spaceIcon)  -  (widthIcon)
		}else {
		item._x = i * ( (widthIcon) + spaceIcon) 	
		container._x=-getSize()/2
		}
				
		}else {
			
		/////////if vertical
		if(dir==1){
		item._y = i * ( (heightIcon) + spaceIcon) 
		}else if(dir==-1){
		item._y = i * ( (-heightIcon) - spaceIcon)  -  (heightIcon)
		}else {
		item._y = i * ( (heightIcon) + spaceIcon)	
		container._y=-getSize()/2	
		}
						
		}
			
		////create area
		var area:MovieClip = item.createEmptyMovieClip("mcArea", 11)
		Drawing.rectangle(area, 0, 0, widthIcon, heightIcon, ["0xFF0000",0])
		
         ////add event		
		item.onPress = Delegate2.create(this, onPressIcon,item)
		item.onRollOver = Delegate2.create(this, onRollOverIcon,item)
		item.onRollOut = Delegate2.create(this, onRollOutIcon,item)
		
		////load image
		//containerItem.loadMovie(path)
		loader.loadClip(path,containerItem)
	}
}

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

function onLoadComplete(target:MovieClip) {
	target._alpha=0	
}

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

function onLoadInit(target:MovieClip) {
    target.tween('_alpha',100,0.5,'easeInOutCubic')     
}

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


function onPressIcon(icon_:MovieClip) {
	var redirect:String = icon_.redirect
	var url:String = redirect.split(",")[0]
	var window:String = redirect.split(",")[1]
	getURL(url,window)
}

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


function onRollOverIcon(icon_:MovieClip) {
	//icon_.container.tween('_y',-10,0.6,'easeOutCubic')
	icon_.tween('_alpha',alphaOver,0.6,'easeOutCubic')
	
	
}


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


function onRollOutIcon(icon_:MovieClip) {
	//icon_.container.tween('_y',0,0.6,'easeOutCubic')
   icon_.tween('_alpha',alphaOut,0.6,'easeOutCubic')
}

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


}

