//Stage.scaleMode = "noScale"
//Stage.align = "TL"
//page1._visible = false
//_root.By = page1._x
//--------------------------------------------------------------------------------LIBRERIE
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.net.FileReference;
//------------------------------------------------------------------------------- I DICHIARAZIONE VARIABILI
var myMatrix:Matrix = new Matrix();
var myColorTransform:ColorTransform = new ColorTransform();
var blendMode:String = "normal";
var smooth:Boolean = true;
var fileRef:FileReference = new FileReference();
//-------------------------------------------------------------------------------- II DICHIARAZIONE VARIABILI
var imagesData = []
var depser = 16
var home = this
var count = 0
var waiter = 10
var breaker = 15 			//numero massimo di immagini per pagina
var stopper = breaker
/*function newWindowHandler()
{
	getURL(_root.tgt, "_blank")
}
*/
//_level0.ppp = _level0.img.split("-")[0] || 1
//_global.vGGG = Number(_level0.img.split("-")[0]) || 1
//-------------------------------------------------------------------------------- VISUALIZZA O NO BARRA 
//-------------------------------------------------------------------------------- CARICAMENTO INIZIALE
loader._visible = false
/*onMouseMove = function()
	{
	updateAfterEvent()
	}
*/
_global.DDDD = []
// ----------------------------------------------------------------------- FUNZIONE DI TRASCINAMENTO E INGRANDIMENTO
MovieClip.prototype.addFunc = function()
{
	
//-----------------------------------------------------------------------------------	
	
	this.container.onRollOver = this.div.onRollOver = function()
	{
		//this._parent.bg.gotoAndPlay(2)
	}
	
	
//-----------------------------------------------------------------------------------
	
	this.container.onRollOut = this.div.onRollOut = function()
	{
		//this._parent.bg.gotoAndPlay(11)
	}
	
//-----------------------------------------------------------------------------------	TRASCINAMENTO FOTINE
	this.container.onPress = function()
	{
		mx.behaviors.DepthControl.bringToFront(this._parent);						//  PORTA IN PRIMO PIANO LA FOTO
		startDrag(this._parent, false, 40, 40, Stage.width-40, Stage.height-40)		//  MUOVE LA FOTO CON DRAG
	}
//-----------------------------------------------------------------------------------	PERMETTE IL RILASCIO
	this.container.onRelease = function()
	{
		stopDrag();
	}
	
//-----------------------------------------------------------------------------------
		
	this.container.onReleaseOutside = this.div.onReleaseOutside = function()
	{
		stopDrag();
	}
//-----------------------------------------------------------------------------------		APRE LA FINESTRA GRANDE
	
	this.div.onRelease = function()
	{
		_global.Text = this._parent.C  // C E' IL TESTO DELLA  FOTO NELL'XML CONTRASSEGNATA DAL CAMPO CDATA
		//this._parent.bg.gotoAndStop(1)
		_global.toDes.onPress()  		// CHIUDE LA PRIMA FINESTRA ALL'APERTURA DI UNA SECONDA FINESTRA
		//this._visible = false
		_global.cMc = this._parent		
		mx.behaviors.DepthControl.bringToFront(_global.cMc); // CMC VARIABILE PORTA IN PRIMO PIANO CON PRIORITA
		//stopDrag();
		//this._parent.noFade = true;
		
		this._parent.mover()			//FUNZIONE DI APERTURA 
		
		//_root.cI = Number(_global.vGGG) + "-" + (Number(this._parent.CCC+1) - breaker * (Number(_global.vGGG)-1))
		
		//fscommand("gotoAnchor", _root.cI)
	}
}
MovieClip.prototype.alpher = function()
{
	if (this.container.c._width)
	{
		this.myBitmapData = new BitmapData(this.container.c._width, this.container.c._height)
		this.myRectangle = new Rectangle(0, 0, this.container.c._width, this.container.c._height);
		this.myBitmapData.draw(this.container.c, myMatrix, null, blendMode, this.myRectangle, smooth);
		
		if(this.myBitmapData.getPixel(0,0) != undefined)
		{
			delete this.onEnterFrame;
    		this.container.attachBitmap(this.myBitmapData, 1, "auto", true)
			for (k=0;k<_global.DDDD.length;k++)
			{
				this == _global.DDDD[k] ? this.container._alpha = 50 : null
			}
			
			var Y = this
			this._x = _global.MUSTBEPAGE ? 10000 : this.WW/2 + random(Stage.width - this.WW*1.5)
			this._y = _global.MUSTBEPAGE ? 10000 : this.HH + random(Stage.height - this.HH*1.8)
			this._rotation = random(20) - random(30)
			this.RR = this._rotation
    		this._visible = true
			this.bg._width = this.container._width+6
			this.bg._height = this.container._height+6
			this.container._x += this.bg._x - this.container._x - this.container._width/2
			this.container._y += this.bg._y - this.container._y - this.container._height/2
			this.div._x = this.container._x + this.container._width - 16
			this.div._y = this.container._y + this.container._height - 12
			this.c = new Tween(this, "_alpha", Strong.easeOut, 0, 100, 5, false)
			this.a = new Tween(this, "_xscale", Strong.easeOut, 50, this.WW, 12, false)
			this.b = new Tween(this, "_yscale", Strong.easeOut, 40, this.HH, 12, false)
			count++
			this.addFunc()
	
			if(count == stopper || !Boolean(imagesData[count+1].length)){dest(Y)}
			else{displayClip()}
    	}
	}
}
function dest(h)
{
	h._xscale = h.WW
	h._yscale = h.HH
	if(!_root.nml)
	{
		callSelected();
		_root.nml = true
	}
}
//-------------------------------------------------------------------------------		FUNZIONE CHE EFFETTUA 
//------------------------------------------------------------------------------- 		IL MOVIMENTO
MovieClip.prototype.mover = function()
{
	_global.toDes = this
	/*delete this.container.onPress	
	delete this.container.onRollOver
	delete this.container.onRollOut	
	delete this.container.onRelease
	delete this.container.onReleaseOutside
	delete this.div.onPress	
	delete this.div.onRollOver
	delete this.div.onRollOut	
	delete this.div.onRelease
	delete this.div.onReleaseOutside
	*/
	var hm = this
	this.tempX = this._x
	this.tempY = this._y
	this.tempWsc = this._xscale
	this.tempHsc = this._yscale
	this.tempWt = this._width
	this.tempHt = this._height
 
	this.wratio = (Stage.width-100)/this.W
	this.hratio = (Stage.height-100)/this.H
	this.ratio = this.W/this.H
	this.aaM = new Tween(this.container, "_alpha", Strong.easeOut, this.container._alpha, 0, 10, false)
	this.xM = new Tween(this, "_x", Strong.easeOut, this._x, Stage.width/2, 20, false)
	this.rM = new Tween(this, "_rotation", Strong.easeOut, this._rotation, 0, 20, false)
	this.yM = new Tween(this, "_y", Strong.easeOut, this._y, Stage.height/2, 20, false)
	if(this.W > Stage.width - 100 || this.H > Stage.height - 100)
	{
		if(Number(this.W) > Number(this.H))
		{
			if(Stage.height > Stage.width)
			{
				this.W *= this.wratio;this.H = (this.W/this.ratio)
			}
		else
		{
			this.H *= this.hratio;this.W = (this.H*this.ratio)
		}
	}
	else
	{
		if(Stage.height > Stage.width)
		{
			this.W *= this.wratio;this.H = (this.W/this.ratio)
		}
		else
		{
			this.H *= this.hratio;this.W = (this.H*this.ratio)
		}
	}
}
this.xS = new Tween(this, "_width", Strong.easeOut, this._width, Number(this.W)+5, 20, false)
this.yS = new Tween(this, "_height", Strong.easeOut, this._height, Number(this.H)+4, 20, false)
this.xS.onMotionFinished = function()
{
	mx.behaviors.DepthControl.bringToFront(_root.bigI);
	mx.behaviors.DepthControl.bringToFront(_root.loader);
	_root.loader._x = Stage.width/2
	_root.loader._y = Stage.height/2
	_root.bigI.createEmptyMovieClip("cc", 0)
	_root.bigI.cc.loadMovie(hm.B)
	_root.tgt = hm.B
	_root.nm = hm.B.slice(hm.B.lastIndexOf("/")+1, hm.B.length)
	_root.bigI._visible = false
	_root.bigI._rotation = 0
	var fgh = 15
	
	_root.onEnterFrame = function()
	{
		this.ldd = Math.round((_root.bigI.cc.getBytesLoaded()/_root.bigI.cc.getBytesTotal())*100)
        fgh--
		if(fgh <= 0){_root.loader._visible = true;_root.loader.gotoAndStop(ldd)}
		if(this.ldd > 99)
		{
			if(_root.bigI._width > 0)
			{
				delete _root.onEnterFrame
				_root.myBitmapData1 = new BitmapData(_root.bigI.cc._width, _root.bigI.cc._height)
	        	var myRectangle1 = new Rectangle(0, 0, _root.bigI.cc._width, _root.bigI.cc._height);
	        	_root.myBitmapData1.draw(_root.bigI, myMatrix, null, blendMode, myRectangle1, smooth);
				_root.bigI.attachBitmap(_root.myBitmapData1, 0, "always", true)
				_root.loader._visible = false
				_root.bigI._width = hm._width - 6
	        	_root.bigI._height = hm._height - 5
				_root.bigI._x = Stage.width/2 - hm.W/2 + .3
	        	_root.bigI._y = hm._y - hm._height/2+2
           		_root.bigI._visible = true
				_root.bigI.menu = imageMenu;
				
				if(_global.DDDD.length < imagesData.length)
				{
             		_global.DDDD.push(hm)
            	}
				
				msk2._width = _root.bigI._width
				msk2._height = _root.bigI._height
				msk2._x = _root.bigI._x + _root.bigI._width
				msk2._y = _root.bigI._y + _root.bigI._height
				msk2._rotation = 180
				mx.behaviors.DepthControl.bringToFront(msk2)
				msk2.tw = new Tween(msk2, "_height", Strong.easeOut, bigI._height, 0, 40, false)
				msk2.tw.onMotionFinished = function()
				{
					comenter._visible = true
					comenter._x = bigI._x + bigI._width/2 - comenter._width/4
					comenter.YY = bigI._y + bigI._height + 14
					comenter._y = bigI._y + bigI._height
					comenter.v = new Tween(comenter, "_y", Strong.easeOut, comenter._y-comenter._height, comenter.YY+1, 15, false)
					comenter.v.onMotionFinished = function()
					{
						mx.behaviors.DepthControl.bringToFront(comenter)
					}
				}
			}
		}
	}
}
this.onPress = function()
{
	delete this.onPress
	msk2.tw.fforward()
	killTip()
	
	_root.myBitmapData1.dispose()
	delete _root.myBitmapData1
	_root.loader._visible = false;
	_root.loader.gotoAndStop(1)
	delete this.xS.onMotionFinished
	delete _root.onEnterFrame
	_root.bigI._visible = false
	_root.bigI._y = 10000
	this.container._alpha = 100
	
	var hm = this
	this.aM = new Tween(this.container, "_alpha", Strong.easeOut, 100, 50, 20, false)
	this.xM = new Tween(this, "_x", Strong.easeOut, this._x, this.tempX, 20, false)
	this.yM = new Tween(this, "_y", Strong.easeOut, this._y, this.tempY, 20, false)
	this.xS = new Tween(this, "_xscale", Strong.easeOut, this._xscale, this.tempWsc, 20, false)
	this.pR = new Tween(this, "_rotation", Strong.easeOut, this._rotation, this.RR, 20, false)
	this.yS = new Tween(this, "_yscale", Strong.easeOut, this._yscale, this.tempHsc, 20, false)
	
	this.yS.onMotionFinished = function()
	{
		//-------------
		hm.div._visible = true
    	hm.addFunc()
		//--------------
	}
}
}
var xml = new XML()
xml.ignoreWhite = true
xml.load("images.xml")
xml.onLoad = function(ok)
{
	ok ? parseXML() : trace("XML!")
}