/**
	BrowserCheck
	fun��o coleta informa��es do browser
*/
function BrowserCheck() {
	var uA = new String(navigator.userAgent);
	if(uA.match(/firefox/gi)){
		this.app = "Firefox";
	}
	else if(uA.match(/chrome/gi)){
		this.app = "Chrome";
	}
	else if(uA.match(/safari/gi)){
		this.app = "Safari";
	}
	else if(uA.match(/opera/gi)){
		this.app = "Opera";
	}
	else if(uA.match(/msie/gi)){
		this.app = "Internet Explorer";
	}
	else{
		this.app = navigator.appName;
	}
	
	this.ns = (this.app=="Netscape" && this.v>=4);
	this.firefox = this.app == "Firefox";
	this.chrome = this.app == "Chrome";
	this.safari = this.app == "Safari";
	this.opera = this.app == "Opera";
	this.ie = this.app == "Internet Explorer";
	this.unknown = !(this.ns || this.firefox || this.chrome || this.safari || this.opera || this.ie);
	
	var version = new String(navigator.appVersion);
	if (this.ie){
		var vs = navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE'));
		this.v = parseInt(vs.substring(5,vs.indexOf(';')));
	}
	else if(!this.unknown){
		var toMatch = (this.safari ? "Version" : this.app) + "/";
		var idx = version.indexOf(toMatch) + toMatch.length;
		this.v = parseFloat(version.substring(idx,version.indexOf(' ',idx)));
	}
	else{
		this.v = parseInt(version);
	}
	
	this.toString = function(){
		return this.app + " vers�o " + this.v;
	}
}
/*
	chamada da fun��o BrowserCheck, atrav�s da qual pode-se testar qual navegador est� sendo utilizado.
	browser.ns = para netscape
	browser.firefox= para firefox
	browser.chorme= para chorme
	browser.safari= para safari
	browser.opera= para opera
	browser.ie= para internet explorer
	browser.v= vers�o do navegador
*/
var browser = new BrowserCheck();

(function($) {
	var $this;
	var tamanho=375;
	var altura= 250;
	var novo= 0;
	var limite;
	var run=0;
	var mostrando;
	var imagens= Array();
	$.fn.flash= function(lim){
		$this = $(this);
		limite=lim;
		colocaLinks();
		$.fn.play();
		$.fn.agenda_play();
		//set_control();
	};
	function set_control(){
		$("#imagem_atual, #centro_flash, #div_imagem").mouseover(function(){
			$("#control").fadeIn('slow');
		});
		$("#imagem_atual, #centro_flash, #div_imagem").mouseout(function(){
			$("#control").show();
		});
	};
	$.fn.agenda_play= function(){
		mostrando=window.setInterval('$.fn.play()', 15000);	
		$('#agenda_play').hide();
		//$("#stop").show();
	};
	$.fn.play =function (){
		var e= $this.find('img').eq(novo).parent().parent();
		e.ver();
		novo++;
		if (limite == novo)novo=0;
	};
	function colocaLinks(){
		var elem='';
		var c=0;
		$this.each(function(){
			$(this).css('cursor', 'pointer').click(function(){
				$(this).ver();
			});
			elem= $(this).find('.imagem').html();
			imagens[c]=elem;
			c++;
		});
		$.fn.preload_images();
	};
	$.fn.preload_images= function(){
		var c=0;
		var mx = imagens.length;
		var im;
		while(c < mx){
			im= new Image(tamanho, altura);
			im.src= imagens[c];
			imagens[c]= im;
			c++;
		}
	}
	$.fn.stop= function(){
		clearInterval(mostrando);
		//$("#stop").hide();
		//$('#agenda_play').show();
	}
	function discolore(){
		$this.each(function(){
			$(this).css({
				'color': '#000000'
			});
		});
	}
	$.fn.ver= function(){
		var ide= $(this).attr('id');
		var image = new Image(tamanho, altura);
		var aux= $("#"+ide+" .imagem").html();
		var tit= $("#"+ide+" img").attr('title');
		image.src=aux;
		//discolore();
		$("#"+ide).css({
			'color': '#000000'
		});
		$("#imagem img").toggle('slide', {}, 1000,function(){
			//$("#chamada").slideToggle(1000);
			$("#imagem img").attr({
				'src': aux,
				'width': tamanho,
				'height' : altura,
				'title': tit
			});
			
			aux = $("#"+ide+" .titulo_animacao").html();
			$("#selecionado h1").html(aux);

			$("#selecionado .link a").attr('href','/'+$("#"+ide+" .link_animacao").html());

			aux = $("#"+ide+" .corpo_animacao").html();
			$("#selecionado .corpo").html(aux);
			$("#imagem img").toggle('slide', {}, 1000);
		});
		novo=ide;
		run =1;
	}
})(jQuery);

(function($){
	function Flash($imagem, $titulo, $introducao, $link, $itens) {
		return {
			$imagem : $imagem,
			$titulo : $titulo,
			$introducao : $introducao,
			$link : $link,
			$itens : $itens,
			itens : [],
			running : false,
			timeout : null,
			nextIndex : null,
			
			initialize : function() {
				var This = this;
				This.$itens.each(function(i) {
					$('.flash_switcher', this).click(function(){if (!This.running)This.set(i); else This.nextIndex = i;});
					var $info = $('.flash_info', this);
					$info.css('display', 'none');
					
					//preload
					var img = new Image();
					img.src = $('.imagem', $info).text()
					
					var item = {
						imagem : img.src,
						legenda : $('.legenda', $info).text(),
						titulo : $('.titulo', $info).text(),
						introducao : $('.introducao', $info).text(),
						link : $('.link', $info).text()
					};
					
					This.itens[i] = item;
				});
			},
			
			setViews : function(i) {
				this.$itens.removeClass('selected');
				this.$itens.eq(i).addClass('selected');
				this.$imagem.attr('src', this.itens[i].imagem);
				this.$imagem.attr('title', this.itens[i].legenda);
				this.$titulo.text(this.itens[i].titulo);
				this.$introducao.text(this.itens[i].introducao);
				this.$link.attr('href', this.itens[i].link);
			},
			
			set : function(i, effect) {
				var This = this;
				
				if (This.timeout != null)
				{
					clearTimeout(This.timeout);
					This.timeout = null;
				}
				
				if (!This.itens[i])
					i = 0;
				
				This.running = true;
				if (effect === false)
				{
					This.setViews(i);
					This.running = false;
				}
				else
				{
					var $clone = This.$imagem.clone();
					$clone.css('position', 'absolute');
					$clone.offset(This.$imagem.offset());
					$clone.css('z-index', '1');
					$clone.insertAfter(This.$imagem);
					This.$imagem.css({opacity: 0});
					This.setViews(i);
					This.$imagem.animate({opacity: 1}, 1000);
					$clone.hide('slide', {}, 1000, function() {
						$clone.remove();
						This.running = false;
						
						if (This.nextIndex)
						{
							i = This.nextIndex;
							This.nextIndex = null;
							This.set(i);
						}
					});
				}
				
				This.timeout = setTimeout(function(){This.set(i + 1);}, 15000);
			}
		};
	}
	
	
	$.fn.flash = function() {
		var f = new Flash($('.flash_imagem', this), $('.flash_titulo', this),
				$('.flash_introducao', this), $('.flash_link', this), 
				$('.flash_item', this));
		f.initialize();
		f.set(0, false);
	}
})(jQuery);

(function($) {
	var zoom_atual=0;
	var limite_zoom=7;
	var fonte_minima=12;
	$.fn.zoomFonte= function (tipo){
		var elem=$(".acoes").next();
		if ($("#txt_detalhe_noticia").size() > 0)elem= $("#txt_detalhe_noticia");
		var font= parseInt(elem.css('font-size'));
		if (font ==0)font=fonte_minima;
		if (tipo){
			zoom_atual++;
			font++;
		}
		else{
			zoom_atual--;
			font--;
		}
		if (zoom_atual < 0){
			zoom_atual=0;
			font=fonte_minima;
		}
		if (zoom_atual > limite_zoom){
			zoom_atual= limite_zoom;
			font = fonte_minima+limite_zoom;
		}
		elem.css('font-size',font);
		elem.find('a').css('font-size',font);
	}
})(jQuery);

(function($) {
	var p;
	var $this;
	$.fn.validarFormulario= function(f){
		if (!f.msg) f.msg="<p>Sua mensagem foi enviada com sucesso.</p>";
		if (f)p=f;
		$this= $(this);
		$this.submit(function(){return false;});
		var ide= $this.attr('id');
		$("#"+ide+" input[type='image']").click(function(){
			if ($(this).hasClass('enviar'))validarCampos();
		});
	}
	function validarCampos(){
		$(".erro_form").hide();
		var retorno = true;
		var ide= $this.attr('id');
		var aux = '';
		$("#"+ide+" :text").each(function(){
			aux = $(this).attr('id');
			if ($(this).val().length == 0){
				$("#erro_"+aux).show();
				retorno = false;
			}
		});
		$("#"+ide+" select").each(function(){
			if (($(this).css('display') != 'none') && ($(this).parent().css('display') != 'none') && ($(this).parent().parent().css('display') != 'none')){
				aux = $(this).attr('id');
				if ($(this).find(':selected').val() == 0){
					$("#erro_"+aux).show();
					retorno = false;
				}
			}
		});
		$("#"+ide+" textarea").each(function(){
			aux = $(this).attr('id');
			if ($(this).val().length == 0){
				$("#erro_"+aux).show();
				retorno = false;
			}
		});
		if ($("#"+ide+" input[name='email']").size() > 0){
			aux= $("#"+ide+" input[name='email']").val();
			if (aux.length > 0)aux= trim(aux);
			if (!vemail(aux)){
				aux = $("#"+ide+" input[name='email']").attr('id');
				$("#erro_"+aux).show();
				retorno = false;	
			}
		}
		if (retorno){
			callback();
		}else{
			return false;	
		}
	}
	function callback(){
		if (p.ajax){
			$.ajax({
			  url: p.url,
			  cache: false,
			  dataType: "text",
			  type: "POST",
			  data: $this.serialize(),
			  success: function(){
					$('#retornoAjax').html(p.msg).css('text-align', 'center');
					loadPopup();
					$('html,body').animate({scrollTop: 0}, 1000);
					document.getElementById($this.attr('id')).reset();
			  }
			});			
		}else{
			$this.submit(function(){});
			$this.attr('action', p.url);
			$this.submit();
		}
	}
})(jQuery);
