/*MODAL GENERICO*/
function modal(obj){
	
	/*CREATE ELEMENTS*/
	$('body').append('<div class="bg_modal close_modal"></div><div class="content_generic_modal"><!-- --></div> ');
	Dimensoes = ___getPageSize();
	$('.bg_modal').width(___getPageSize()[0]).height(___getPageSize()[1]);
	/*OPACITY*/
	$('.content_generic_modal').css('opacity', 0);
	$('.bg_modal').css('opacity', 0);
	
	/*SELECTS HIDE*/
	$('select').css('visibility', 'hidden');

	/*SHOW BACKGROUND*/
	$('.bg_modal').fadeTo('fast', 0.5, function() {

		$('.content_generic_modal').load(obj, function() {
	        
			/*CENTRALIZE MODAL*/
			if(leftModal != 0 || topModal != 0){
				$('.content_generic_modal').css({
						marginTop: topModal, 
						marginLeft: leftModal,
						left: 0,
						top: 0
					}
				);
			} else {
				$('.content_generic_modal').css({
						marginTop: - parseInt($('.content_generic_modal').height()/2), 
						marginLeft: -parseInt($('.content_generic_modal').width()/2)
					}
				);
			}			
						
			/*MODAL HIDE*/
			$('.content_generic_modal').fadeTo('fast', 1);
			
			/*CLOSE MODAL*/
			$("a[@rel='close_modal']").click(
				function() {
				$("a[href*='modal']").bind('click',function(){
					$("a[href*='modal']").unbind('click');
					var url = $(this).attr('href').toLowerCase();
					modal(url);	
					return false;
				});
					close_modal();
					return false;
				}
			);
			
			$('.close_modal').click ( function () {
			$('.close_modal').unbind('click');
			$("a[href*='modal']").bind('click',function(){
				$("a[href*='modal']").unbind('click');
					var url = $(this).attr('href').toLowerCase();
					modal(url);	
					return false;
				});
			    close_modal();
			});
		});
	});

};

/*CLOSE MODAL*/
function close_modal(){
		$('.content_generic_modal').fadeTo('fast', 0, function(){
			$('.bg_modal').fadeTo('fast', 0, function(){
				$('.bg_modal').remove();
			});
			$('.content_generic_modal').remove();
		});
	$('select').css('visibility', 'visible');
};

$(document).ready ( function () {
	var url = ($("a[href*='modal']").attr("href") != undefined) ? $("a[href*='modal']").attr('href').toLowerCase() : null;
	
    if(url != null){
		$("a[href*='modal']").click(function(){
		$("a[href*='modal']").unbind('click');
			modal(url);	
			return false;
		});
		
		$("a[@rel='paginacao']").livequery('click',function(){
			var destino = $(this).attr('href');
			$.ajax({
				url: destino,
				success:function(data){
					$(".content_generic_modal").empty();
					$(".content_generic_modal").html(data);
					return false;
				},
				cache:false
			});
			return false;
		});
	}
});
function SetImagemPrincipal(Titulo,Descricao,URLThumb,Indice,URLImagem){
		oldImg = new Array();
		oldImg["src"]  = $.trim($("img[@rel='ImagemAmpliada']").attr('src'));
		oldImg["srcThumb"] = $.trim($("img[@rel='ImagemAmpliada']").attr('alt'));
		oldImg["titulo"] = $.trim($("#TituloGaleria").text());
		oldImg["descricao"] = $.trim($("#DescricaoGaleria").text());
		$("#DescricaoGaleria").livequery(function(){
			$(this).text(Descricao);
		});
		$("#TituloGaleria").livequery(function(){
			$(this).text(Titulo);
		});
		$("img[@rel='ImagemAmpliada']").attr('src',URLImagem);
		$("img[@rel='ImagemAmpliada']").attr('alt',URLThumb);
		$("img[@rel='"+Indice+"']").attr('src',oldImg["srcThumb"]);
		$("span[@rel='"+Indice+"']").text(oldImg["titulo"]);
		$("a[@rel='"+Indice+"']").attr('onclick',"javascript:return SetImagemPrincipal('"+oldImg["titulo"]+"','"+oldImg["descricao"]+"','"+oldImg["srcThumb"]+"','"+Indice+"','"+oldImg["src"]+"');");
	return false;
}

function OpenModalProjeto(idProjeto){
	Full = window.location.href;
	URLProjetos = Full.replace("carreira/jovens-profissionais-parceria-com-universidades.aspx","carreira/jovens-profissionais-parceria-com-universidades-modal.aspx?idProjeto="+idProjeto);
	modal(URLProjetos);
	
}