$(document).ready(function(){

	$("#breadcrumb").disableTextSelect();

  // Área restrita
	$("#login_usuario").click(function(){ $(this).val(''); });
	$("#login_senha_fake").focus(function(){
		$("#login_senha_fake").remove();
		$("#login_senha").show();
		$("#login_senha").focus();
	});


// Acesso rápido
	$("#header-container .acesso").click(function() {
		var pos = $(".acesso").position();
		$(".acesso-lista").css({left: $(window).width() / 2 + 241, top: pos.top + 35});
		$(".acesso-lista").slideToggle("fast");
	});

	// Tamanho do texto nas leituras
	/*if($.cookie('MVCTextSize') != '' && $.cookie('MVCTitleSize') != '') {
		$('#main .conteudo1 .texto').css('font-size', parseFloat($.cookie('MVCTextSize')));
		$('#main .conteudo1 .texto h1').css('font-size', parseFloat($.cookie('MVCTitleSize')));
	}*/

	$(".fonte_maior").click(function(){
		var maximo = 16;
		var newTextSize = parseFloat($('#main .conteudo1 .texto').css('font-size'), 10) +1;
		var newTitleSize = parseFloat($('#main .conteudo1 .texto h1').css('font-size'), 10) +1;
		if(newTextSize <= maximo) {
			$('#main .conteudo1 .texto h1').css('font-size', newTitleSize);
			$('#main .conteudo1 .texto').css('font-size', newTextSize);
			$.cookie('MVCTextSize', newTextSize, { expires:10 });
			$.cookie('MVCTitleSize', newTitleSize, { expires:10 });
		} else if(newTextSize > maximo) {
			$('#breadcrumb .toolbar .fonte_maior').html('<img src="_img/pare.gif" />');
			$(this).delay(1000, function() {
				$('#breadcrumb .toolbar .fonte_maior').html('');
			})
		}
		return false;
	});
	$(".fonte_menor").click(function(){
    var minimo = 11;
		var newTextSize = parseFloat($('#main .conteudo1 .texto').css('font-size'), 10) -1;
		var newTitleSize = parseFloat($('#main .conteudo1 .texto h1').css('font-size'), 10) -1;
		if(newTextSize >= minimo) {
			$('#main .conteudo1 .texto h1').css('font-size', newTitleSize);
			$('#main .conteudo1 .texto').css('font-size', newTextSize);
			$.cookie('MVCTextSize', newTextSize, { expires:10 });
			$.cookie('MVCTitleSize', newTitleSize, { expires:10 });
		} else if(newTextSize < minimo) {
			$('#breadcrumb .toolbar .fonte_menor').html('<img src="_img/pare.gif" />');
			$(this).delay(1000, function() {
				$('#breadcrumb .toolbar .fonte_menor').html('');
			})
		}
		return false;
	});

	// Impressão de página
	$(".imprimir").click(function(){
		$("#main .conteudo1 .texto").printArea();
	});

});
// Galeria de imagens em noticias
$.fn.extend({
	galeria: function(idgal, idlist, offset) {
		var n = 1;
		var k = '';
		if($("#"+idgal+" img").size() > 1) {
			$("#"+idgal+" img").each(function() {
				if(n <= 5) {
					$(this).attr('class', 'item' + n);
					if(n > 1) {
						k += '<span>&bull;</span>';
					}
					k += '<a href="javascript:void(0);" class="pagina" id="pagina' + n + '">' + n + '</a>';
					n++;
				}
			});
			$("#"+idlist).html(k);
		}
		n = 1;
		
		$(".pagina").click(function() {
		 $(".pagina").css("text-decoration", "none");
		 $(this).css("text-decoration", "underline");
		 $(this).blur();
		 var n = $(this).attr("id").substr(6, $(this).attr("id").length - 6);
			$("#"+idgal).animate({top: - (n - 1) * offset + "px" });
			$(".legenda ul").animate({top: - (n - 1) * 55 + "px" });
		});

	}
});

$.fn.delay = function(time, func){
	return this.each(function(){
		setTimeout(func,time);
	});
};

$.fn.extend($.fn.disableTextSelect = function() {
	return this.each(function(){
		if($.browser.mozilla){//Firefox
			$(this).css('MozUserSelect','none');
		}else if($.browser.msie){//IE
			$(this).bind('selectstart',function(){return false;});
		}else{//Opera, etc.
			$(this).mousedown(function(){return false;});
		}
	});
});

(function($) {
	var printAreaCount = 0;
	$.fn.printArea = function() {
		var ele = $(this);
		var idPrefix = "printArea_";
		removePrintArea( idPrefix + printAreaCount );
		printAreaCount++;
		var iframeId = idPrefix + printAreaCount;
		var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
		iframe = document.createElement('IFRAME');
		$(iframe).attr({ style : iframeStyle, id : iframeId });
		document.body.appendChild(iframe);
		var doc = iframe.contentWindow.document;
		$(document).find("link")
			.filter(function(){
				return $(this).attr("rel").toLowerCase() == "stylesheet";
			})
			.each(function(){
				doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
			});
			doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
			doc.close();
			var frameWindow = iframe.contentWindow;
			frameWindow.close();
			frameWindow.focus();
			frameWindow.print();
	}
	var removePrintArea = function(id) {
		$( "iframe#" + id ).remove();
	};
})(jQuery);



