﻿$(function(){
	$(".no-js").removeClass();
	$("body").fadeIn(300);
	modal();
	$('#twitter-widget').twitterSearch({
   	   	term:  'MovOpK',
   	   	title: false,
		bird: false,
		colorExterior: '#fff', 
    	colorInterior: '#fff'
   	});
});

function modal() {

/*
 *  1- Adicione "rel=disableModal" pra desativar o modal em links de conteudos para as páginas em "showPureContent"
 *	2- Ou Adicione "target_blank" pra desativar o modal em links de conteudos para as páginas em "showPureContent"
 *
 */

	$("a").live('click', function(event){ //
	var attrHre = $(this).attr("href");
	var attrTar = $(this).attr("target");
	var attrRel = $(this).attr("rel");
	var attrTitle = $(this).attr("title");

		if(attrRel.split("?")[0] == "/portal/portal/content/showPureContent.k" ||  attrRel.split("?")[0] == "http://www.tribancoseguros.com.br/portal/portal/content/showPureContent.k") {
			event.preventDefault();
	
			$(".modal").remove();
			$('<div class="modal"><div id="background">&nbsp;</div><div id="stage"><div class="title"><h2>Carregando...</h2></div><div class="content"><p class="carregando">Aguarde um instante.</p></div><p class="acoes"><a href="#" class="fechar">X</a></p></div></div>').fadeIn(600).insertAfter("#footer");
			$(".modal .content").load(attrRel);
			$('.modal .title h2').text($(this).attr("title"));
			$('#stage').css({"top": $(window).scrollTop() + 40});
			scrollModal();
		} else {}
	});


	$(window).scroll(scrollModal);

	function scrollModal() {
		$('#background').css({"top": $(window).scrollTop() });
	}
	function kill(event){
		event.preventDefault();
		$('.modal').fadeOut(600);
		removeHtml = setTimeout(function() {
			$('.modal').remove()
		}, 600);
	}

	$(document).keypress(function(event) {
               if (event.keyCode == '27') {
                       kill();
               }
       });

	$('.modal .fechar, #background').live('click', kill);
}
