var EzZoom_ua = "msie";
var W = navigator.userAgent.toLowerCase();
if ( W.indexOf( "opera" ) != -1 ) {
	EzZoom_ua = "opera"
} else if ( W.indexOf( "msie" ) != -1 ) {
	EzZoom_ua = "msie"
} else if ( W.indexOf( "safari" ) != -1 ) {
	EzZoom_ua = "safari"
} else if ( W.indexOf( "mozilla" ) != -1 ) {
	EzZoom_ua = "gecko"
}
var EzZoom_zooms = new Array();

/* Funções de auxílio */
function EzZoom_$( id )
{
	return document.getElementById( id );
};

function EzZoom_getStyle( el, styleProp ) {
	if ( el.currentStyle ) {
		var y = el.currentStyle[styleProp];
		y = parseInt( y ) ? y: "0px";
	} else if ( window.getComputedStyle ) {
		var css = document.defaultView.getComputedStyle( el, null );
		var y = css ? css[styleProp] : null;
	}
	return y;
};

function EzZoom_getBounds( e ) {
	if ( e.getBoundingClientRect ) {
		var r = e.getBoundingClientRect();
		var wx = 0;
		var wy = 0;
		if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			wy = document.body.scrollTop;
			wx = document.body.scrollLeft;
		} else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			wy = document.documentElement.scrollTop;
			wx = document.documentElement.scrollLeft;
		}
		return {
			"left": r.left + wx,
			"top": r.top + wy,
			"right": r.right + wx,
			"bottom": r.bottom + wy
		}
	}
};

function EzZoom_getEventBounds( e )
{
	var x = 0;
	var y = 0;

	if ( EzZoom_ua == "msie" )
	{
		y = e.clientY;
		x = e.clientX;
		if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			y = e.clientY + document.body.scrollTop;
			x = e.clientX + document.body.scrollLeft;
		}
		else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			y = e.clientY + document.documentElement.scrollTop;
			x = e.clientX + document.documentElement.scrollLeft;
		}
	}
	else
	{
		y = e.clientY;
		x = e.clientX;

		/* Correção para pegar a posição do mouse em relação a DIV cont */
		if ( EzZoom_$( "cont" ) )
		{
			y += EzZoom_$( "cont" ).scrollTop;
			x += EzZoom_$( "cont" ).scrollLeft;
		}
		else
		{
			y += window.pageYOffset;
			x += window.pageXOffset;
		}
	}

	return {
		"x": x,
		"y": y
	}
};

function EzView_ia()
{
	return false;
};

function EzZoom_extendElement()
{
	var args = arguments;
	if ( !args[1] ) args = [this, args[0]];
	for ( var property in args[1] ) args[0][property] = args[1][property];
	return args[0];
};

function EzZoom_addEventListener( obj, event, listener )
{
	if ( EzZoom_ua == "gecko" || EzZoom_ua == "opera" || EzZoom_ua == "safari" ) {
		try {
			obj.addEventListener( event, listener, false );
		} catch( e ) {}
	} else if ( EzZoom_ua == "msie" ) {
		obj.attachEvent( "on" + event, listener );
	}
};

function EzZoom_removeEventListener( obj, event, listener ) {
	if ( EzZoom_ua == "gecko" || EzZoom_ua == "opera" || EzZoom_ua == "safari" )
	{
		obj.removeEventListener( event, listener, false );
	}
	else if ( EzZoom_ua == "msie" )
	{
		obj.detachEvent( "on" + event, listener );
	}
};

function EzZoom_concat()
{
	var result = [];
	for ( var i = 0; i < arguments.length; i++ ) for ( var j = 0; j < arguments[i].length; j++ ) result.push( arguments[i][j] );
	return result;
};

function EzZoom_withoutFirst( sequence, skip )
{
	result = [];
	for ( var i = skip; i < sequence.length; i++ ) result.push( sequence[i] );
	return result;
};

function EzZoom_createMethodReference( object, methodName )
{
	var args = EzZoom_withoutFirst( arguments, 2 );
	return function() {
		object[methodName].apply( object, EzZoom_concat( args, arguments ) );
	}
};

function EzZoom_stopEventPropagation( e )
{
	if ( EzZoom_ua == "gecko" || EzZoom_ua == "safari" || EzZoom_ua == "opera" )
	{
		e.cancelBubble = true;
		e.preventDefault();
		e.stopPropagation();
	}
	else if ( EzZoom_ua == "msie" )
	{
		window.event.cancelBubble = true;
	}
};

function EzZoom_findSelectors( id, zoom )
{
	var aels = window.document.getElementsByTagName( "A" );

	for ( var i = 0; i < aels.length; i++ )
	{
		if ( aels[i].rel == id )
		{
			EzZoom_addEventListener( aels[i], "click", function( event )
			{
				if ( EzZoom_ua != "msie" ) {
					this.blur();
				} else {
					window.focus();
				}
				EzZoom_stopEventPropagation( event );
				return false;
			} );

			EzZoom_addEventListener( aels[i], zoom.settings["thumb_change"], EzZoom_createMethodReference( zoom, "replaceZoom", aels[i] ) );

			aels[i].style.outline = "0";
			aels[i].mzextend = EzZoom_extendElement;
			aels[i].mzextend(
			{
				zoom: zoom,
				selectThisZoom: function() {
					this.zoom.replaceZoom( null, this );
				}
			} );

			/*  Carrega o Zoom antes mesmo de usar
			var img					= document.createElement( "IMG" );
				img.src				= aels[i].href;
				img.style.position	= "absolute";
				img.style.left		= "-10000px";
				img.style.top		= "-10000px";

			document.body.appendChild( img );

			var img					= document.createElement( "IMG" );
				img.src				= aels[i].rev;
				img.style.position	= "absolute";
				img.style.left		= "-10000px";
				img.style.top		= "-10000px";

			document.body.appendChild( img );
			*/
		}
	}
};

function EzZoom_stopZooms() {
	while ( EzZoom_zooms.length > 0 )
	{
		var zoom = EzZoom_zooms.pop();
			zoom.stopZoom();

		delete zoom;
	};
};

function EzZoom_findZooms()
{
	/* Verifica se existe imagem de loading */
	var loadingText = "Carregando...";
	var loadingImg = "";
	var iels = window.document.getElementsByTagName( "IMG" );

	for ( var i = 0; i < iels.length; i++ ) {
		if ( /EzZoomLoading/.test( iels[i].className ) ) {
			if ( iels[i].alt != "" ) loadingText = iels[i].alt;
			loadingImg = iels[i].src;
			break;
		}
	}

	/* Verifica quais links tem a class igual a "EzZoom". o que caracteriza uma imagem com zoom */
	var aels = window.document.getElementsByTagName( "A" );

	for ( var i = 0; i < aels.length; i++ ) {
		if ( /EzZoom/.test( aels[i].className ) )
		{
			/* Remove todos os nodos até que o primeiro nodo seja uma imagem */
			while ( aels[i].firstChild )
			{
				if ( aels[i].firstChild.tagName != "IMG" )
				{
					aels[i].removeChild( aels[i].firstChild )
				}
				else
				{
					break;
				}
			}
			/* Caso não encontre nenhum nodo imagem dentro do link */
			if ( aels[i].firstChild.tagName != "IMG" )
			{
				//throw "Invalid EzZoom invocation!";
				return;
			}

			/* Cria uma variavel para concatenar com novos elementos */
			var rand = "Zooom";//Math.round( Math.random() * 1000000 );

			/* Força a exibição do link e configura */
			aels[i].style.position			= "relative";
			aels[i].style.display			= "block";
			aels[i].style.outline			= "0";
			aels[i].style.textDecoration	= "none";
			
			/* Remove todos os eventos onclick adicionados a este link e força o retorno false */
			EzZoom_addEventListener( aels[i], "click", function( event )
			{
				if ( EzZoom_ua != "msie" ) {
					this.blur();
				}
				EzZoom_stopEventPropagation( event );
				return false;
			} );

			/* Caso o link não tenha Id, adiciona */
			if ( aels[i].id == "" )
			{
				aels[i].id = "sc" + rand;
			}

			/* Caso seja IE adiciona o zIndex */
			if ( EzZoom_ua == "msie" )
			{
				aels[i].style.zIndex = 0;
			}
			
			/* Define a variavel "smallImg" igual a imagem onde será feito o controle de movimento do zoom */
			var smallImg = aels[i].firstChild;
			//smallImg.id = "sim" + rand;

			/* Remove o container caso ele exista */
			if ( EzZoom_$( "bcZooom" ) != null )
			{
				EzZoom_$( "bcZooom" ).parentNode.removeChild( EzZoom_$( "bcZooom" ) );
			}

			/* Cria o container para o zoom */
			var bigCont = document.createElement( "DIV" );
				bigCont.id = "bc" + rand;

			/* Inicia a verificação o atributo REL, pois nele ficam as configurações do zoom */
			/* Verifica se existe a configuração de opacidade */
			re = new RegExp( /opacity(\s+)?:(\s+)?(\d+)/i );
			matches = re.exec( aels[i].rel );
			var opacity = 50;
			if ( matches )
			{
				opacity = parseInt( matches[3] );
			}
			
			/* Verifica se existe a configuração de evento em que as thumbs devem ser exibidas */
			re = new RegExp( /thumb\-change(\s+)?:(\s+)?(click|mouseover)/i );
			matches = re.exec( aels[i].rel );
			var thumb_change = "click";
			if ( matches )
			{
				thumb_change = matches[3];
			}
			
			/* Verifica se existe a configuração de largura do zoom */
			re = new RegExp( /zoom\-width(\s+)?:(\s+)?(\w+)/i );
			var zoomWidth = -1;
			matches = re.exec( aels[i].rel );
			bigCont.style.width = "300px";
			if ( matches )
			{
				bigCont.style.width = matches[3];
				zoomWidth = matches[3];
			}
			
			/* Verifica se existe a configuração de altura do zoom */
			re = new RegExp( /zoom\-height(\s+)?:(\s+)?(\w+)/i );
			var zoomHeight = -1;
			matches = re.exec( aels[i].rel );
			bigCont.style.height = "300px";
			if ( matches )
			{
				bigCont.style.height = matches[3];
				zoomHeight = matches[3];
			}

			/* Verifica se existe a configuração de posição do zoom */
			re = new RegExp( /zoom\-position(\s+)?:(\s+)?(\w+)/i );
			matches = re.exec( aels[i].rel );
			var position = "right";
			if ( matches ) {
				switch ( matches[3] ) {
				case "left":
					position = "left";
					break;
				case "bottom":
					position = "bottom";
					break;
				case "top":
					position = "top";
					break;
				case "custom":
					position = "custom";
					break;
				case "inner":
					position = "inner";
					break;
				}
			}

			/* Verifica se existe a configuração se é necessário clicar e arrastar do zoom */
			re = new RegExp( /drag\-mode(\s+ )?:(\s+)?(true|false)/i );
			matches = re.exec( aels[i].rel );
			var drag_mode = false;
			if ( matches ) {
				if ( matches[3] == "true" ) drag_mode = true;
			}

			/* Verifica se existe a configuração de sempre exibir o zoom */
			re = new RegExp( /always\-show\-zoom(\s+)?:(\s+)?(true|false)/i );
			matches = re.exec( aels[i].rel );
			var bigImage_always_visible = false;
			if ( matches )
			{
				if ( matches[3] == "true" ) bigImage_always_visible = true;
			}

			/* Configura o container do zoom */
				bigCont.style.overflow = "hidden";
				bigCont.className = "EzZoomBigImageCont";
				bigCont.style.zIndex = 100;
				bigCont.style.display = "none";
				bigCont.style.visibility = "hidden";

			if ( position != "custom" )
			{
				bigCont.style.position = "absolute";
			}
			else
			{
				bigCont.style.position = "relative";
			}

			/* Cria a div que vai ser o zoom */
			var bigImg = document.createElement( "IMG" );
				bigImg.id = "bim" + rand;
				bigImg.src = aels[i].href;
				bigCont.appendChild( bigImg );

			if ( position != "custom" )
			{
				aels[i].appendChild( bigCont );
			}
			else
			{
				EzZoom_$( aels[i].id + "-big" ).appendChild( bigCont );
			}

			/* Coloca todas as configurações em um objeto */
			var settings = {
				bigImage_always_visible: bigImage_always_visible,
				drag_mode: drag_mode,
				header: aels[i].title,
				opacity: opacity,
				thumb_change: thumb_change,
				position: position,
				loadingText: loadingText,
				loadingImg: loadingImg,
				zoomWidth: zoomWidth,
				zoomHeight: zoomHeight
			};
			if ( position == "inner" ) {
				aels[i].title = "";
			}

			
			/* Passa as configurações para dar inicio ao zoom para este link/imagem */
			//var zoom = new EzZoom( aels[i].id, "sim" + rand, bigCont.id, "bim" + rand, settings );
			var zoom = new EzZoom( aels[i].id, "FotoPrincipal", bigCont.id, "bim" + rand, settings );
			
			aels[i].mzextend = EzZoom_extendElement;
			aels[i].mzextend( {
				zoom: zoom
			} );

			/* Inicia o controle sobre o passar do mouse */
			zoom.initZoom();
			/* Inicia o controle sobre as thumbs */
			EzZoom_findSelectors( aels[i].id, zoom );
		}
	}
};

/* EzZoom */
function EzZoom( smallImageContId, smallImageId, bigImageContId, bigImageId, settings )
{
	//this.version = "1.1";
	/* Cria as variaveis deste zoom */
	this.recalculating = false;
	this.smallImageCont = EzZoom_$( smallImageContId );
	this.smallImage = EzZoom_$( smallImageId );
	this.bigImageCont = EzZoom_$( bigImageContId );
	this.bigImage = EzZoom_$( bigImageId );
	this.pup = null;
	this.settings = settings;

	if ( !this.settings["header"] )
	{
		this.settings["header"] = "";
	}

	this.bigImageSizeX = 0;
	this.bigImageSizeY = 0;
	this.smallImageSizeX = 0;
	this.smallImageSizeY = 0;
	this.popupSizeX = 20;
	this.popupSizey = 20;
	this.positionX = 0;
	this.positionY = 0;
	this.bigImageContStyleTop = "";

	/* Verifica se a imagem de loading existe e configura */
	this.loadingCont = null;
	if ( this.settings["loadingImg"] != "" )
	{
		this.loadingCont = document.createElement( "DIV" );
		this.loadingCont.style.position 	= "absolute";
		this.loadingCont.style.visibility	= "hidden";
		this.loadingCont.className			= "EzZoomLoading";
		this.loadingCont.style.display		= "block";
		this.loadingCont.style.textAlign	= "center";
//		this.loadingCont.innerHTML = this.settings["loadingText"] + "<br/><img border="0" alt="" + this.settings["loadingText"] + "" src="" + this.settings["loadingImg"] + ""/>";
		this.loadingCont.innerHTML			= '<img border="0" alt="" + this.settings["loadingText"] + "" src="" + this.settings["loadingImg"] + ""/>';
		this.bigImageCont.appendChild( this.loadingCont );
	}

	//this.baseuri = "";
	/* Hack para o safari */
	this.safariOnLoadStarted = false;

	/* Adiciona o zoom atual ao array de zoom"s */
	EzZoom_zooms.push( this );

	/* Adiciona os eventos de movimentação do mouse */
	this.checkcoords_ref = EzZoom_createMethodReference( this, "checkcoords" );
	this.mousemove_ref = EzZoom_createMethodReference( this, "mousemove" );
};

EzZoom.prototype.initZoom = function()
{
	/* Verifica se a imagem já carregou ( && !this.bigImage.complete ) */
	if ( this.loadingCont != null && this.smallImage.width != 0 && this.smallImage.height != 0 )
	{
		this.loadingCont.style.left = ( parseInt( this.smallImage.width ) / 2 - parseInt( this.loadingCont.offsetWidth ) / 2 ) + "px";
		this.loadingCont.style.top = ( parseInt( this.smallImage.height ) / 2 - parseInt( this.loadingCont.offsetHeight ) / 2 ) + "px";
		this.loadingCont.style.visibility = "visible";
	}

	/* Verifica se é safari e adiciona o listener enquanto a imagem do zoom não carregar */
	if ( EzZoom_ua == "safari" )
	{
		if ( !this.safariOnLoadStarted )
		{
			EzZoom_addEventListener( this.bigImage, "load", EzZoom_createMethodReference( this, "initZoom" ) );
			this.safariOnLoadStarted = true;
			return;
		}
	}
	else
	{
		if ( !this.bigImage.complete || !this.smallImage.complete )
		{
			setTimeout( EzZoom_createMethodReference( this, "initZoom" ), 100 );
			return;
		}
	}

	this.bigImage.style.borderWidth = "0px";
	this.bigImage.style.padding		= "0px";

	this.bigImageSizeX				= 1200;//this.bigImage.width;
	this.bigImageSizeY				= 1200;//this.bigImage.height;

	this.smallImageSizeX			= this.smallImage.width;
	this.smallImageSizeY			= this.smallImage.height;

	/* Verifica as dimensões e caso sejam zeradas chama novamente o listener */
	if ( this.bigImageSizeX == 0 || this.bigImageSizeY == 0 || this.smallImageSizeX == 0 || this.smallImageSizeY == 0 )
	{
		setTimeout( EzZoom_createMethodReference( this, "initZoom" ), 100 );
		return;
	}

	/*  */
	if ( EzZoom_ua == "opera" || ( EzZoom_ua == "msie" && !( document.compatMode && "backcompat" == document.compatMode.toLowerCase() ) ) )
	{
		this.smallImageSizeX -= parseInt( EzZoom_getStyle( this.smallImage, "paddingLeft" ) );
		this.smallImageSizeX -= parseInt( EzZoom_getStyle( this.smallImage, "paddingRight" ) );
		this.smallImageSizeY -= parseInt( EzZoom_getStyle( this.smallImage, "paddingTop" ) );
		this.smallImageSizeY -= parseInt( EzZoom_getStyle( this.smallImage, "paddingBottom" ) );
	}

	/* Verificase se existe o loading, então esconde */
	if ( this.loadingCont != null )
	{
		this.loadingCont.style.visibility = "hidden";
	}

	/* Inicia a configuração da posição do zoom */
	this.smallImageCont.style.width = this.smallImage.width + "px";
	this.bigImageCont.style.top 	= "-10000px";
	this.bigImageContStyleTop 		= "0px";

	var r = EzZoom_getBounds( this.smallImage );

	if ( !r )
	{
		this.bigImageCont.style.left = this.smallImageSizeX + parseInt( EzZoom_getStyle( this.smallImage, "borderLeftWidth" ) ) + parseInt( EzZoom_getStyle( this.smallImage, "borderRightWidth" ) ) + parseInt( EzZoom_getStyle( this.smallImage, "paddingLeft" ) ) + parseInt( EzZoom_getStyle( this.smallImage, "paddingRight" ) ) + 15 + "px"
	}
	else
	{
		this.bigImageCont.style.left = ( r[ "right" ] - r[ "left" ] + 15 ) + "px";
	}

	switch ( this.settings[ "position" ] )
	{
		case "left":
			this.bigImageCont.style.left = "-" + ( 15 + parseInt( this.bigImageCont.style.width ) ) + "px";
			break;
		case "bottom":
			if ( r ) {
				this.bigImageContStyleTop = r["bottom"] - r["top"] + 15 + "px";
			} else {
				this.bigImageContStyleTop = this.smallImage.height + 15 + "px";
			}
			this.bigImageCont.style.left = "0px";
			break;
		case "top":
			this.bigImageContStyleTop = "-" + ( 15 + parseInt( this.bigImageCont.style.height ) ) + "px";
			this.bigImageCont.style.left = "0px";
			break;
		case "custom":
			this.bigImageCont.style.left = "0px";
			this.bigImageContStyleTop = "0px";
			break;
		case "inner":
			this.bigImageCont.style.left = "0px";
			this.bigImageContStyleTop = "0px";
			if ( this.settings["zoomWidth"] == -1 ) {
				this.bigImageCont.style.width = this.smallImageSizeX + "px";
			}
			if ( this.settings["zoomHeight"] == -1 ) {
				this.bigImageCont.style.height = this.smallImageSizeY + "px";
			}
			break;
	}

	/* Recalcula as dimenções do pup ( quadrado que fica encima da image, o foco ) */
	if ( this.pup != null )
	{
		this.recalculatePopupDimensions();
		return;
	}

	/* Inicia a configuração do container do zoom */
	this.initBigContainer();

	/* Inicia a configuração do pup */
	this.initPopup();


	EzZoom_addEventListener( window.document, "mousemove", this.checkcoords_ref );
	EzZoom_addEventListener( this.smallImageCont, "mousemove", this.mousemove_ref );


	if ( this.settings && this.settings["drag_mode"] == true )
	{
		EzZoom_addEventListener( this.smallImageCont, "mousedown", EzZoom_createMethodReference( this, "mousedown" ) );
		EzZoom_addEventListener( this.smallImageCont, "mouseup", EzZoom_createMethodReference( this, "mouseup" ) );
	}

	if ( this.settings && ( this.settings["drag_mode"] == true || this.settings["bigImage_always_visible"] == true ) )
	{
		this.positionX = this.smallImageSizeX / 2;
		this.positionY = this.smallImageSizeY / 2;
		this.showrect();
	}
};

EzZoom.prototype.recalculatePopupDimensions = function()
{
	this.popupSizeX = parseInt( this.bigImageCont.style.width ) / ( this.bigImageSizeX / this.smallImageSizeX );

	/* Verifica se tem mensagem de header para calcular a altura */
	if ( this.settings && this.settings["header"] != "" )
	{
		this.popupSizeY = ( parseInt( this.bigImageCont.style.height ) - 19 ) / ( this.bigImageSizeY / this.smallImageSizeY );
	}
	else
	{
		this.popupSizeY = parseInt( this.bigImageCont.style.height ) / ( this.bigImageSizeY / this.smallImageSizeY );
	}

	/* Calcula a largura */
	if ( this.popupSizeX > this.smallImageSizeX ) {
		this.popupSizeX = this.smallImageSizeX;
	}
	if ( this.popupSizeY > this.smallImageSizeY ) {
		this.popupSizeY = this.smallImageSizeY;
	}

	this.popupSizeX = Math.round( this.popupSizeX );
	this.popupSizeY = Math.round( this.popupSizeY );

	if ( !( document.compatMode && "backcompat" == document.compatMode.toLowerCase() ) )
	{
		var bw = parseInt( EzZoom_getStyle( this.pup, "borderLeftWidth" ) );
		this.pup.style.width = ( this.popupSizeX - 2 * bw ) + "px";
		this.pup.style.height = ( this.popupSizeY - 2 * bw ) + "px";
	}
	else
	{
		this.pup.style.width = this.popupSizeX + "px";
		this.pup.style.height = this.popupSizeY + "px";
	}
};

EzZoom.prototype.initPopup = function()
{
	/* Verifica se a pup já existe */
	if ( EzZoom_$( "EzZoomPup" ) != null )
	{
		this.pup = EzZoom_$( "EzZoomPup" );
	}
	else
	{
		this.pup = document.createElement( "DIV" );
		this.pup.id = "EzZoomPup";
	}

	/* Configura a pup */
	this.pup.className					= "EzZoomPup";
	this.pup.style.zIndex				= 10;
	this.pup.style.visibility			= "hidden";
	this.pup.style.position				= "absolute";
	this.pup.style[ "opacity" ]			= parseFloat( this.settings[ "opacity" ] / 100.0 );
	this.pup.style[ "-moz-opacity" ]	= parseFloat( this.settings[ "opacity" ] / 100.0 );
	this.pup.style[ "-html-opacity" ]	= parseFloat( this.settings[ "opacity" ] / 100.0 );
	this.pup.style[ "filter" ]			= "alpha( Opacity=" + this.settings[ "opacity" ] + " )";
	this.smallImageCont.appendChild( this.pup );

	/* Configura as dimenções */
	this.recalculatePopupDimensions();

	/* Desabilita a seleção */
	this.smallImageCont.unselectable = "on";
	this.smallImageCont.style.MozUserSelect = "none";
	this.smallImageCont.onselectstart = EzView_ia;
	this.smallImageCont.oncontextmenu = EzView_ia;
};

EzZoom.prototype.initBigContainer = function()
{
	var bigimgsrc = this.bigImage.src;

	if ( this.bigImageSizeY < parseInt( this.bigImageCont.style.height ) )
	{
		this.bigImageCont.style.height = this.bigImageSizeY + "px";
		if ( this.settings && this.settings[ "header" ] != "" )
		{
			this.bigImageCont.style.height = ( 19 + this.bigImageSizeY ) + "px";
		}
	}

	if ( this.bigImageSizeX < parseInt( this.bigImageCont.style.width ) )
	{
		this.bigImageCont.style.width = this.bigImageSizeX + "px";
	}

	while ( this.bigImageCont.firstChild )
	{
		this.bigImageCont.removeChild( this.bigImageCont.firstChild );
	}

	if ( EzZoom_ua == "msie" ) {
		var f 					= document.createElement( "IFRAME" );
			f.style.left		= "0px";
			f.style.top			= "0px";
			f.style.position	= "absolute";
			f.src				= "javascript:'';";
			f.style.filter		= "progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=0 )";
			f.style.width		= this.bigImageCont.style.width;
			f.style.height		= this.bigImageCont.style.height;
			f.frameBorder		= 0;

		this.bigImageCont.appendChild( f );
	}

	/* Título do zoom, inserido sobre o zoom */
	/*if ( this.settings && this.settings["header"] != "" )
	{
		var f					= document.createElement( "DIV" );
			f.className			= "EzZoomHeader";
			f.id				= "EzZoomHeader" + this.bigImageCont.id;
			f.style.position	= "relative";
			f.style.zIndex		= 10;
			f.style.left		= "0px";
			f.style.top			= "0px";
			f.style.padding		= "3px";
			f.innerHTML			= this.settings[ "header" ];

		this.bigImageCont.appendChild( f );
	}*/

	var ar1 = document.createElement( "DIV" );
		ar1.style.overflow = "hidden";

	this.bigImageCont.appendChild( ar1 );

	this.bigImage					= document.createElement( "IMG" );
	this.bigImage.src 				= bigimgsrc;
	this.bigImage.style.position	= "relative";
	this.bigImage.style.borderWidth	= "0px";
	this.bigImage.style.padding		= "0px";
	this.bigImage.style.left		= "0px";
	this.bigImage.style.top			= "0px";

	ar1.appendChild( this.bigImage );
};

EzZoom.prototype.stopZoom = function() {
	if ( this.smallImageCont && EzZoom_$( "EzZoomPup" ) )
	{
		this.smallImageCont.removeChild( EzZoom_$( "EzZoomPup" ) );
	}

	EzZoom_removeEventListener( window.document, "mousemove", this.checkcoords_ref );
	EzZoom_removeEventListener( this.smallImageCont, "mousemove", this.mousemove_ref );
	if ( this.settings[ "position" ] == "custom" )
	{
		this.bigImageCont.parentNode.removeChild( this.bigImageCont );
	}
	else
	{
		this.smallImageCont.removeChild( this.bigImageCont );
	}
};

/* Função que controla o onmouseover */
EzZoom.prototype.checkcoords = function( e )
{
	var r 		= EzZoom_getEventBounds( e );
	var x		= r[ "x" ];
	var y		= r[ "y" ];
	var smallY	= 0;
	var smallX	= 0;
	var tag		= this.smallImage;

	while ( tag && tag.tagName != "BODY" && tag.tagName != "HTML" )
	{
		smallY += tag.offsetTop;
		smallX += tag.offsetLeft;
		tag		= tag.offsetParent;
	}

	if ( EzZoom_ua == "msie" )
	{
		var r	= EzZoom_getBounds( this.smallImage );
		smallX	= r["left"];
		smallY	= r["top"];
	}

	smallX += parseInt( EzZoom_getStyle( this.smallImage, "borderLeftWidth" ) );
	smallY += parseInt( EzZoom_getStyle( this.smallImage, "borderTopWidth" ) );

	if ( EzZoom_ua != "msie" || !( document.compatMode && "backcompat" == document.compatMode.toLowerCase() ) )
	{
		smallX += parseInt( EzZoom_getStyle( this.smallImage, "paddingLeft" ) );
		smallY += parseInt( EzZoom_getStyle( this.smallImage, "paddingTop" ) );
	}

	if ( x > parseInt( smallX + this.smallImageSizeX ) )
	{
		this.hiderect();
		return false;
	}

	if ( x < parseInt( smallX ) )
	{
		this.hiderect();
		return false;
	}

	if ( y > parseInt( smallY + this.smallImageSizeY ) )
	{
		this.hiderect();
		return false;
	}

	if ( y < parseInt( smallY ) )
	{
		this.hiderect();
		return false;
	}

	if ( EzZoom_ua == "msie" )
	{
		this.smallImageCont.style.zIndex = 300;
	}

	return true;
};

EzZoom.prototype.mousedown = function( e ) {
	EzZoom_stopEventPropagation( e );
	this.smallImageCont.style.cursor = "move";
};

EzZoom.prototype.mouseup = function( e ) {
	EzZoom_stopEventPropagation( e );
	this.smallImageCont.style.cursor = "default";
};

EzZoom.prototype.mousemove = function( e )
{
	EzZoom_stopEventPropagation( e );

	for ( i = 0; i < EzZoom_zooms.length; i++ )
	{
		if ( EzZoom_zooms[i] != this )
		{
			EzZoom_zooms[i].checkcoords( e );
		}
	}
	if ( this.settings && this.settings["drag_mode"] == true )
	{
		if ( this.smallImageCont.style.cursor != "move" )
		{
			return;
		}
	}
	if ( this.recalculating )
	{
		return;
	}
	if ( !this.checkcoords( e ) )
	{
		return;
	}

	this.recalculating = true;
	var smallImg = this.smallImage;
	var smallX = 0;
	var smallY = 0;

	if ( EzZoom_ua == "gecko" || EzZoom_ua == "opera" || EzZoom_ua == "safari" )
	{
		var tag = smallImg;
		while ( tag.tagName != "BODY" && tag.tagName != "HTML" )
		{
			smallY += tag.offsetTop;
			smallX += tag.offsetLeft;
			tag = tag.offsetParent;
		}
	}
	else
	{
		var r = EzZoom_getBounds( this.smallImage );
		smallX = r["left"];
		smallY = r["top"];
	}

	smallX += parseInt( EzZoom_getStyle( this.smallImage, "borderLeftWidth" ) );
	smallY += parseInt( EzZoom_getStyle( this.smallImage, "borderTopWidth" ) );
	if ( EzZoom_ua != "msie" || !( document.compatMode && "backcompat" == document.compatMode.toLowerCase() ) )
	{
		smallX += parseInt( EzZoom_getStyle( this.smallImage, "paddingLeft" ) );
		smallY += parseInt( EzZoom_getStyle( this.smallImage, "paddingTop" ) );
	}

	var r = EzZoom_getEventBounds( e );
	var x = r["x"];
	var y = r["y"];
	this.positionX = x - smallX;
	this.positionY = y - smallY;
	if ( ( this.positionX + this.popupSizeX / 2 ) >= this.smallImageSizeX )
	{
		this.positionX = this.smallImageSizeX - this.popupSizeX / 2;
	}
	if ( ( this.positionY + this.popupSizeY / 2 ) >= this.smallImageSizeY )
	{
		this.positionY = this.smallImageSizeY - this.popupSizeY / 2;
	}
	if ( ( this.positionX - this.popupSizeX / 2 ) <= 0 )
	{
		this.positionX = this.popupSizeX / 2;
	}
	if ( ( this.positionY - this.popupSizeY / 2 ) <= 0 )
	{
		this.positionY = this.popupSizeY / 2;
	}
	setTimeout( EzZoom_createMethodReference( this, "showrect" ), 5 );
};

EzZoom.prototype.showrect = function()
{
	var pleft	= this.positionX - this.popupSizeX / 2;
	var ptop	= this.positionY - this.popupSizeY / 2;
	var perX	= pleft * ( this.bigImageSizeX / this.smallImageSizeX );
	var perY	= ptop * ( this.bigImageSizeY / this.smallImageSizeY );

	if ( document.documentElement.dir == "rtl" )
	{
		perX = ( this.positionX + this.popupSizeX / 2 - this.smallImageSizeX ) * ( this.bigImageSizeX / this.smallImageSizeX );
	}

	pleft += parseInt( EzZoom_getStyle( this.smallImage, "borderLeftWidth" ) );
	ptop += parseInt( EzZoom_getStyle( this.smallImage, "borderTopWidth" ) );

	if ( EzZoom_ua != "msie" || !( document.compatMode && "backcompat" == document.compatMode.toLowerCase() ) )
	{
		pleft += parseInt( EzZoom_getStyle( this.smallImage, "paddingLeft" ) );
		ptop += parseInt( EzZoom_getStyle( this.smallImage, "paddingTop" ) );
	}

	this.pup.style.left			= pleft + "px";
	this.pup.style.top			= ptop + "px";
	this.pup.style.visibility	= "visible";

	if ( ( this.bigImageSizeX - perX ) < parseInt( this.bigImageCont.style.width ) )
	{
		perX = this.bigImageSizeX - parseInt( this.bigImageCont.style.width );
	}

	var headerH = 0;
	/*if ( this.settings && this.settings["header"] != "" )
	{
		headerH = 19;
	}*/

	if ( this.bigImageSizeY > ( parseInt( this.bigImageCont.style.height ) - headerH ) )
	{
		if ( ( this.bigImageSizeY - perY ) < ( parseInt( this.bigImageCont.style.height ) - headerH ) )
		{
			perY = this.bigImageSizeY - parseInt( this.bigImageCont.style.height ) + headerH;
		}
	}

	this.bigImage.style.left			= ( - perX ) + "px";
	this.bigImage.style.top				= ( - perY ) + "px";

	this.bigImageCont.style.top			= this.bigImageContStyleTop;
	this.bigImageCont.style.display		= "block";
	this.bigImageCont.style.visibility	= "visible";

	this.bigImage.style.display			= "block";
	this.bigImage.style.visibility		= "visible";
	this.recalculating					= false;
};

/* Função chamada no onmouseout */
EzZoom.prototype.hiderect = function() {
	if ( this.settings && this.settings["bigImage_always_visible"] == true )
	{
		return;
	}
	if ( this.pup )
	{
		this.pup.style.visibility = "hidden";
	}
	if ( this.bigImageCont )
	{
		this.bigImageCont.style.display		= "none";
		this.bigImageCont.style.visibility	= "hidden";
	}
	this.bigImageCont.style.top = "-10000px";
	if ( EzZoom_ua == "msie" )
	{
		this.smallImageCont.style.zIndex = 0;
	}
};

EzZoom.prototype.replaceThumbsBorder = function( ael )
{
	var ThumbsLink = EzZoom_$( "Thumbs" ).getElementsByTagName( "A" );
	var Thumbs = EzZoom_$( "Thumbs" ).getElementsByTagName( "IMG" );

	for ( var i=0; i< ThumbsLink.length; i++ )
	{
		if ( ael.id == ThumbsLink[ i ].id )
		{
			Thumbs[ i ].style.borderColor = "#333";
		}
		else
		{
			Thumbs[ i ].style.borderColor = "#E1E1E1";
		}
	}
};

/* Função chamada na troca de zoom (ao clicar em uma thumb) */
EzZoom.prototype.replaceZoom = function( ael, e )
{

	if ( EzZoom_$( "swf_video" ) )
	{
		showVideo( false );
	}

	if ( ael.href == this.bigImage.src )
	{
		return;
	}

	if ( ael.href )
	{
		var newBigImage = document.createElement( "IMG" );
			newBigImage.id = this.bigImage.id;
			newBigImage.src = ael.href;

		var p = this.bigImage.parentNode;
			p.replaceChild( newBigImage, this.bigImage );

		this.bigImage = newBigImage;
		this.bigImage.style.position = "relative";
	}
	else
	{
		EzZoom_stopZooms();

		this.bigImage.src = "";
	}

	this.replaceThumbsBorder( ael );

	this.smallImage.src = ael.rev;

	/*if ( ael.title != "" && EzZoom_$( "EzZoomHeader" + this.bigImageCont.id ) )
	{
		EzZoom_$( "EzZoomHeader" + this.bigImageCont.id ).firstChild.data = ael.title;
	}*/

	if ( ael.href )
	{
		this.safariOnLoadStarted = false;
		this.initZoom();
	}

	this.smallImageCont.href = ael.href;

	if ( ael.href )
	{
		try
		{
			EzThumb.refresh();
		}
		catch( e ) {}
	}
};


if ( EzZoom_ua == "msie" ) try
{
	document.execCommand( "BackgroundImageCache", false, true );
} catch( e ) {};


EzZoom_addEventListener( window, "load", EzZoom_findZooms );



