var idPaisMapa = "";

$(document).ready(function() {
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 7){ $("body").addClass("ie") }

	$("#header .img").flash({ src: '/swf/bannerHome/banner_msf.swf', width: 950, height: 151, flashvars: { xml: ['/swf/bannerHome/banner.xml'].join(' ') } }, { version: 8 });
	$("#timeLine .flash").flash({ src: '/swf/linhadetempo.swf', width: '100%', height: '100%', wmode: 'transparent', align: 'middle', flashvars: { xml: ['/linha_tempo_xml.aspx'].join(' ') } }, { version: 8 });
	$("#flashQuizz").flash({ src: '/swf/quizz.swf', width: 716, height: 500, wmode: 'transparent' }, { version: 8 });
	$("#flashMapa").flash({ src: '/swf/mapa.swf', width: 716, height: 360, wmode: 'transparent', flashvars: { pais: idPaisMapa, xml: ['/MSFNoMundoXML.aspx'].join(' '), xml_siglas: ['/swf/xml/mapa_siglas.xml'].join(' ') } }, { version: 8 });
	
	$("table.oddEven tbody tr:even").addClass("even");
	$("table.oddEven tbody tr:odd").addClass("odd");
	
	$("a.btnFull").click(function(){
		if($(this).parent().prev().is(":visible")){
			$(this).removeClass("hover").html("Veja o conte&uacute;do completo");
		}else{
			$(this).addClass("hover").html("Fechar conte&uacute;do completo");
		}
		$(this).parent().prev().slideToggle();
		return false;
	});

	$("input.tipoFiltro + label, input.tipoFiltro").click(function(){
		if($(this).prev().val() != ''){
			$val = $(this).prev().val();
		}else{
			$val = $(this).val();
		}
		$(this).parent().find("select").hide();
		$(this).parent().find("select").parent().hide();
		$(this).parent().find("input:text").hide();		
		$(this).parent().find("input:text").parent().hide();
		$(this).parent().find("input:image").show();
		
		$("." + $val).show();
		$("." + $val).parent().show();
	});

	$("ul.listFontSize li a.icoMail").click(function(){
		if($(".boxIndique").is(":visible")){
			$(".boxIndique").slideUp(function(){
				$("ul.listFontSize li a.icoMail").removeClass("hover");
			});
		}else{
			$(this).addClass("hover");
			$(".boxIndique").slideDown();
		}
		return false;
	});

    $(".icoPrint").click(function(){
        window.print();
    });
    
	$(".boxFaq h4").click(function(){
		$(".boxFaq .accor").slideUp();
		$(".boxFaq h4").removeClass("hover");
		if($(this).next().is(":visible")){
			$(this).removeClass("hover").next().slideUp();
		}else{
			$(this).addClass("hover").next().slideDown();
		}
		return false;
	});
	$(".boxFaq h4:first").trigger("click");

	$("ul.listFontSize li a.icoMailTB, a.btnIndiqueNoticia").click(function(){
	    tb_indiqueShow('', '/tb/tbIndique.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});

	$("a.btnIndiquePodcast, .popPodcast a.btnIndiquePodcast").click(function(){
		tb_indiqueShow('', '/tb/tbIndiquePodcast.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});
	
	$("a.btnIndiqueTexto").click(function(){
		tb_indiqueShow('', '/tb/tbIndiquePodcast.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});

	$("a.btnIndiqueChat, a.icoMailTBChat").click(function(){
		tb_indiqueShow('', '/tb/tbIndiqueChat.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});

	$("ul.listFontSize li a.icoMailTBDiario, a.btnIndiqueDiario").click(function(){
		tb_indiqueShow('', '/tb/tbIndiqueDiario.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});

	$("a.btnIndiqueGaleria").click(function(){
		$type = $(this).attr("href").split("#")[1];
		switch($type){
			case 'fotos':
				$url = 'tbIndiqueGaleriaFotos.html';
			break;
			case 'videos':
				$url = 'tbIndiqueGaleriaVideos.html';
			break;
			default:
			    $url = 'tbIndique.html';
			    break;
		}
		tb_indiqueShow('', '/tb/' + $url + '?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});
	
	$(".selectFormas input.formaPagamento + label").click(function(){
		$val = $(this).prev().val();
		$(".boxCartao, .boxBoleto, .boxDebito").hide();
		$("."+ $val).show();
	});
	
	$("a.btnIndiqueVideo, a.btnIndiqueVideo2").click(function(){
		tb_indiqueShow('', '/tb/tbIndiqueVideo.html?keepThis=true&TB_iframe=true&width=453&height=245&modal=true', false);
		return false;
	});

	$(".boxDetalhePodcast a.btnAbrirPopup").click(function(){
		popUp('/PopUpPodcast.aspx?p=' + $(".idPodCast").attr("value"),'512','548');
		return false;
	});

	$(".boxIndique a.btnFechar").click(function(){
		$(".boxIndique").slideUp(function(){
			$("ul.listFontSize li a.icoMail").removeClass("hover");
		});
		return false;
	});

	$(".carrosselPodcast ul, .carrosselFotos ul, .carrosselChats ul").jcarousel({ scroll: 5 });
    $(".carrosselDiario ul").jcarousel({ scroll: 2 });

	/* Imprime o flash para o podcast */
	/*
	$(".flashPodcast").each(function(){
		$mp3 = $(this).attr("rel");
		$(this).flash({ src: '/swf/flashPodcast.swf', width: 445, height: 80, wmode: 'transparent', flashvars: { mp3Path: [$mp3].join(" ") } }, { version: 8 });
	});
	*/


	$("input + label").click(function() {
		if ($(this).prev().attr("type") == 'checkbox') {
			if ($(this).prev().is(":checked")) {
				$(this).prev().attr("checked", false);
			} else {
				$(this).prev().attr("checked", true);
			}
		} else {
			$(this).prev().attr("checked", true);
		}
	});


	$(".question input + label, .question input").click(function() {
		$(this).parents(".question").find(".results .alerts, a.btnProximaPergunta").hide();
	});

	$("a.btnResponder").click(function() {
		$question = $(this).parents(".question");
		$number = $question.attr("rel");
		$answer = $question.find("input:checked").val();
		$question.find(".results .alerts").hide();
		$question.find(".results .alerts[rel='"+ $answer +"']").fadeIn();
		if($question.find(".results .alerts[rel='"+ $answer +"']").hasClass("yes")){
			$question.find(".btnProximaPergunta").show();
		}else{
			$question.find(".btnProximaPergunta").hide();
		}
		return false;
    });

	$("a.btnProximaPergunta").click(function() {
		$next = $(this).attr("href").split("#")[1];
		$(".question").hide();
		$(".question[rel='"+ $next +"']").show();
		$(".quizSteps").addClass("q"+ $next);
		return false;
	});

	$("ul.listArtigos li a[href$=ppt]").parent().addClass("ppt");
	$("ul.listArtigos li a[href$=pdf]").parent().addClass("pdf");
	$("ul.listArtigos li a[href$=doc]").parent().addClass("doc");

	$(".boxInfo .item a[href$=ppt]").parent().parent().parent().addClass("ppt");
	$(".boxInfo .item a[href$=pdf]").parent().parent().parent().addClass("pdf");
	$(".boxInfo .item a[href$=doc]").parent().parent().parent().addClass("doc");

	$("#formFaleMSF").validate({ errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                type: 'GET',
				data: $("#formFaleMSF").serialize(),
                dataType: "json",
                url: '/inc/processFaleMSF.html',
                success: function(json) {
                    if (json.msg == "ok") {
						tb_show('', '/tb/sucessoFaleComMSF.html?keepThis=true&TB_iframe=true&width=324&height=135&modal=true', false);
					}else{
						//$(".msgErrorIndique").fadeIn();
					}
                }
            });
        }
    });
	
	$("textarea.postUniverso").tinymce({
		script_url : '/js/tinymce/tiny_mce.js',
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_resizing : false,
		theme_advanced_statusbar_location : "bottom"
	});

	$("ul.idTabs").idTabs();

	//$("#navHeader:not(:'.small') ul.navHeader").superfish({ pathClass: 'current' });
    $("#navHeader").mouseleave(function()
    {
        $("#navHeader > ul > li.current > a").css("background-position", "0px -24px");
    
        $("#navHeader > ul > li > ul").hide();
        $("#navHeader > ul > li.current > ul ").show();      
    });

    $("#navHeader > ul > li").mouseover(function()
    {  
        if( $(this).attr("class") != "current" )
        {       
            $("#navHeader > ul > li.current > a").css("background-position", "0px 0px");
        }
        else
        {
            $("#navHeader > ul > li.current > a").css("background-position", "0px -24px");
        }
                
        $("#navHeader > ul > li > ul").hide();
        $(this).find("ul li").parent().show();
    });

    $("#navHeader > ul > li.current > ul ").show();
    $("#navHeader > ul > li.current > a").css("background-position", "0px -24px");
        
	$("textarea.maxlength").maxlength({
		'feedback' : ".charsLeft span"
	});

	$(".fontsize").each(function(){
		fontResizer('10px','11px','14px');
	});
	$(".fix").ifixpng();
});


/*
  jquery.bgIframe
  @version: 2.1
*/
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&parseInt($.browser.version)<=6){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};if(!$.browser.version)$.browser.version=navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];})(jQuery);

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);


/*
  jquery.maxlength
  @version: 1.2
*/

(function ($) {

$.fn.maxlength = function (settings) {

    if (typeof settings == 'string') {
        settings = { feedback : settings };
    }

    settings = $.extend({}, $.fn.maxlength.defaults, settings);

    function length(el) {
    	var parts = el.value;
    	if ( settings.words )
    		parts = el.value.length ? parts.split(/\s+/) : { length : 0 };
    	return parts.length;
    }
    
    return this.each(function () {
        var field = this,
        	$field = $(field),
        	$form = $(field.form),
        	limit = settings.useInput ? $form.find('input[name=maxlength]').val() : $field.attr('maxlength'),
        	$charsLeft = $form.find(settings.feedback);

    	function limitCheck(event) {
        	var len = length(this),
        	    exceeded = len >= limit,
        		code = event.keyCode;

        	if ( !exceeded )
        		return;

            switch (code) {
                case 8:  // allow delete
                case 9:
                case 17:
                case 36: // and cursor keys
                case 35:
                case 37: 
                case 38:
                case 39:
                case 40:
                case 46:
                case 65:
                    return;

                default:
                    return settings.words && code != 32 && code != 13 && len == limit;
            }
        }

        var updateCount = function () {
            var len = length(field),
            	diff = limit - len;

            $charsLeft.html( diff || "0" );

            // truncation code
            if (settings.hardLimit && diff < 0) {
            	field.value = settings.words ? 
            	    // split by white space, capturing it in the result, then glue them back
            		field.value.split(/(\s+)/, (limit*2)-1).join('') :
            		field.value.substr(0, limit);

                updateCount();
            }
        };

        $field.keyup(updateCount).change(updateCount);
        if (settings.hardLimit) {
            $field.keydown(limitCheck);
        }

        updateCount();
    });
};

$.fn.maxlength.defaults = {
    useInput : false,
    hardLimit : true,
    feedback : '.charsLeft',
    words : false
};

})(jQuery);

function popUp(pagina,largura,altura) {
	w = screen.width;
	h = screen.height;
	meio_w = w/2;
	meio_h = h/2;
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
}

/* FONT SIZER VERSION 1.0
 Developed by fluidByte (http://www.fluidbyte.net) */
function fontResizer(smallFont,medFont,largeFont){
	function clearSelected() {
		$(".smallFont, .medFont, .largeFont").removeClass("curFont");
	}
	function saveState(curSize) {
		var date = new Date();
		date.setTime(date.getTime()+(7*24*60*60*1000));
		var expires = "; expires="+date.toGMTString(); 
		document.cookie = "fontSizer"+"="+curSize+expires+"; path=/";
	}
	$(".smallFont").click(function(){ 
		$('.fontsize').css('font-size', smallFont);
		clearSelected();
		$(".smallFont").addClass("curFont");
		saveState(smallFont);
	});
	$(".medFont").click(function(){
		$('.fontsize').css('font-size', medFont);
		clearSelected();
		$(".medFont").addClass("curFont");
		saveState(medFont);
	});
	$(".largeFont").click(function(){ 
		$('.fontsize').css('font-size', largeFont);
		clearSelected();
		$(".largeFont").addClass("curFont");
		saveState(largeFont);
	});
	function getCookie(c_name) {
		if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end)); } } return ""; 
	}
	var savedSize = getCookie('fontSizer');
	if (savedSize!="") { $('.fontsize').css('font-size', savedSize); switch (savedSize) { case smallFont: $(".smallFont").addClass("curFont"); break; case medFont: $(".medFont").addClass("curFont"); break; case largeFont: $(".largeFont").addClass("curFont"); break; default: $(".medFont").addClass("curFont"); } }
	else { $('.fontsize').css('font-size', medFont); $(".medFont").addClass("curFont"); }
}

function setFlashWidth(divid, newW){
	document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
	document.getElementById(divid).style.height = newH+"px";		
}
function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
}
function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if( document.getElementById ){
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}

function redimensionaLinhaDeTempo( estado ){	
	//var oDiv = document.getElementById("container");
	//window.alert("estado: " + estado);
	//$("#timeLine .flash").removeClass(".estado0, .estado1, .estado2");
	if (estado == 0) {
		$("#timeLine .flash").css({ "position": "absolute", "top": "0px", "height": "95px" });
	}else if (estado == 1) {
		$("#timeLine .flash").css({ "position": "absolute", "top": "-415px", "height": "515px", "z-index":"101", "display":"block" });
	}else{
		$("#timeLine .flash").css({ "width": "950px", "height": "600px", "position": "absolute", "top": "-500px", "height": "660px" });
	}
}

