/*!
 * Pack com:
 * query.hoverIntent.minified.js
 * jquery.ba-resize.min.js
 * all_pages.js
 */
/**
* 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 resize event - v1.1 - 3/14/2010
 * http://benalman.com/projects/jquery-resize-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);
var ie;

$(document).ready(function() {
	//mouse over dos modulos simples
	$(".modulo_over").hoverIntent(menuHover);
	
	//controlador de clicks nos modulos de arquivo do blog
	$("div[type=blog]").click(function(){
		var endereco = $(this).children('input[type=hidden]').attr('value');
		window.location=SITE_URL+"/blog/"+endereco;								  
	});
		
});//document ready

//organizador dos modulos do arquivo do blog
function organizarModulos(cols5, cols4, cols3){
	var janela = $(window).width();
	var conteudo = $("#conteudo");	
	var colunasUtilizadas = 3;
	//debug
	//console.log('janela:' + janela + '| margem:' + margem);
	//console.log($("#teste").offset('left'));
	
	//calcular a margem em relacao ao tamanho da janela
	if (janela > 1556) {
		var margem = (janela - 1208) /2;
		conteudo.css('margin-left', margem);
		$("#conteudo").css('width', '1210px');
		manterGrid(cols4);
		colunasUtilizadas = 4;
	}
	else if (janela > 1264) {
		var margem = (janela - 1208) /2;
		conteudo.css('margin-left', margem);
		$("#conteudo").css('width', '');
		manterGrid(cols4);
		colunasUtilizadas = 4;
	}
	else if (janela > 962) {
		var margem = (janela - 906) /2;
		conteudo.css('margin-left', margem);
		$("#conteudo").css('width', '');
		manterGrid(cols3);
		colunasUtilizadas = 3;
	}

	//acertar as cores em relacao as colunas
	$("#conteudo div.modulo:visible").each(function(){
		var posicao = $(this).offset();
		//if (posicao.left < 197) {
//			$(this).removeClass('verde amarelo azul');
//			$(this).addClass('verde');
//		}
//		else
		if (colunasUtilizadas == 3) {
			if (posicao.left < 197) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
			else if (posicao.left < 499) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('amarelo');
			}
			else if (posicao.left < 801) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('azul');	
			}
			else if (posicao.left < 1103) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
		}
		else if (colunasUtilizadas == 4 && janela <= 1601) {
			if (posicao.left < 197) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
			else if (posicao.left < 499) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('amarelo');
			}
			else if (posicao.left < 801) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('azul');	
			}
			else if (posicao.left < 1103) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
		}
		else if (colunasUtilizadas == 4) {
			if (posicao.left < 499) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
			else if (posicao.left < 801) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('amarelo');
			}
			else if (posicao.left < 1103) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('azul');	
			}
			else if (posicao.left < 1405) {
				$(this).removeClass('verde amarelo azul');
				$(this).addClass('verde');
			}
		}
	});
};

//esconder ou mostrar os posts de acordo com o tamanho da janela
function manterGrid(cols){
	var modulos = $("#conteudo > div.modulo");
	modulos.each(function(i){
			if (i >= cols) {
				$(this).css('display', 'none');
			}
			else {
				$(this).css('display', 'block');	
			}
	});
};

//mouse over dos modulos simples
var menuHover = {    
		 sensitivity: 10,
		 interval: 50,
		 over: menuHoverOver,  
		 timeout: 300,
		 out: menuHoverOut 
	};
	
function menuHoverOver(){
		$(this).parent().children('.modulo_box').children('.modulo_conteudo_2').stop().animate({top: '32px'}, 500, "easeInCubic");
	};
	
	function menuHoverOut(){
		$(this).parent().children('.modulo_box').children('.modulo_conteudo_2').stop().animate({top: '-140px'}, 500, "easeInCubic");
	};
