/*
CIEBIT
Script de Imagens em jQuery
Criado:		11-12-2011
Alterado:	19-12-2011
*/

$(document).ready(function(){
	//Função para esconder imagem
	var Esconder = function(event){
		event.preventDefault();
		$('.fer_imagem_fundo').fadeOut('slow', function(){
				$(this).remove();
		});
		$('.fer_imagem_ampla').fadeOut('slow', function(){
				$(this).remove();
		});
	};
	
	//Ampliação de Imagem
	$('.fotos_ampli img').click(function(event){
		//Cancelando ação padrão
		event.preventDefault();
		var caminho, pos_x, pos_y;
		
		caminho = $(this).parent().attr('href');
		
		//Criando fundo e imagem
		$('<div></div>').attr('class', 'fer_imagem_fundo').css('opacity', '0.80').prependTo('body').hide().fadeIn('slow');
		$('<img>').attr({'src': caminho, 'class':'fer_imagem_ampla'}).prependTo('body').hide().load(function(){
			pos_x = $(window).width() - $(this).width();
			pos_x = pos_x / 2;
			pos_y = $(window).height() - $(this).height();
			pos_y = pos_y / 2;
			$(this).css({top: pos_y, left: pos_x}).fadeIn('slow');
		});
		

	});
	
	//Ação ao clicar na página
	$('.fer_imagem_fundo').live('click', Esconder);
	$('.fer_imagem_ampla').live('click', Esconder);
});
