/**
 * jQuery png fix
 * http://jquery.andreaseberhard.de/pngFix/
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([237-9n-zA-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'<y \'+g+h+i+j;b+=\'9="W:X;white-space:pre-line;Y:Z-10;I:transparent;\'+k+d;b+=\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;\';b+=\'J:K:L.t.M(n=\\\'\'+3(2).7(\'n\')+\'\\\', N=\\\'O\\\');\';b+=l+\'"></y>\';p(a!=\'\'){b=\'<y 9="W:X;Y:Z-10;\'+a+d+\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;">\'+b+\'</y>\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);',[],68,'||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'),0,{}))


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;


/**
 * Image Preloader
 * http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
 * http://ajaxian.com/archives/preloading-images-with-jquery
 */
;(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);
//$.preLoadImages("images/tweetSpace.png", "images/followus.png");

/**
 * Link parser
 */
jQuery.fn.autolink = function () {
	return this.each( function(){
		var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
		$(this).html( $(this).html().replace(re, '<a href="$1">$1</a> ') );
	});
}


/**
 * Twitter API
 * 
 */
var user = 'LogicsSoftware';
function posted(t) {
    var now = new Date();
    var diff = parseInt((now.getTime() - Date.parse(t)) / 1000);
    if (diff < 60) { return 'h&aacute; menos de 1 minuto'; }
    else if (diff < 120) { return 'h&aacute; 1 minuto'; }
    else if (diff < (2700)) { return 'h&aacute; ' + (parseInt(diff / 60)).toString() + ' minutos'; }
    else if (diff < (5400)) { return 'h&aacute; mais de 1 hora'; }
    else if (diff < (86400)) { return 'h&aacute; ' + (parseInt(diff / 3600)).toString() + ' horas'; }
    else if (diff < (172800)) { return '1 dia atr&aacute;s'; } 
    else {return (parseInt(diff / 86400)).toString() + ' dias atr&aacute;s'; }
}
function formatUrl(t) {
    var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
    return t.replace(regexp, "<a href=\"$1\" target=\"_blank\">$1</a>");
}
function formatUser(t) {
    var regexp = /[\@]+([A-Za-z0-9-_]+)/gi;
    return t.replace(regexp, "<a href=\"http://twitter.com/$1\" target=\"_blank\">@$1</a>");
}
function formatHash(t) {
    var regexp = / [\#]+([A-Za-z0-9-_]+)/gi;
    return t.replace(regexp, ' <a href="http://search.twitter.com/search?q=&tag=$1&lang=all&from=' + user + '" target=\"_blank\">#$1</a>');
}


/**
 * Adiciona timeout para consultar twitter de minuto em minuto
 * 
 * @author george
 * 
 * @access public
 * 
 * @params string $user usuario do twitter
 * 
 * @return null
 * 
 */
function checkTwitter(user){
	// executa funcao
	_submitTwitter(user);
	
	// coloca timer executando a funcao de 30 em 30 segundos
	var timeout = window.setInterval(function(){_submitTwitter(user);}, 30000);
}


/**
 * Consulta via ajax o ultimo status do Twitter
 * 
 * @param string $user twitter user
 * 
 * @author george
 * @return null
 */
var lastTweetId;
function _submitTwitter(user){

	// efetua consulta
	$.ajax({
		url: "http://search.twitter.com/search.json?rpp=3&callback=?&q=from%3A"+user,
		beforeSend: function() {
			// enquanto processando
			$("#conteudoTwitter").animate({opacity: '0', height: '0'}, 'slow');
		},
		success: function(data) {
			// em caso de sucesso
			var id = data.results[0].id;


			// controle utilizado para verificar se o ultimo tweet e igual ao consultado.
			// se nao for, atualiza.
			if(lastTweetId != id){
				// atribui variavel para controle do tweet
				lastTweetId = id;

				// anima barra
				// recolhe espaco
				$("#conteudoTwitter").slideUp('slow', function(){
                                        // zera conteudo
                                        $("#conteudoTwitter").html('');

                                        // percorre e faz append
                                        for(i=0;i<data.results.length;i++){
                                            $("#conteudoTwitter").append('<div class="twitterPost"><p><a href="http://twitter.com/'+user+'" target="_blank"><img src="'+data.results[i].profile_image_url+'" alt="" /></a></p><p>'+data.results[i].text+'</p><div class="brclear">&nbsp;</div><div>'+posted(data.results[i].created_at)+'</div></div>');

                                        }
					$("#conteudoTwitter").animate({opacity: 'toggle', height: 'toggle'}, 'slow', function(){
                                            // corrige colunas
                                            corrigeColunas();
                                        });



				});




				// parametriza post
				$("div.twitterPost p").autolink();
				

			}
			
			// horario do post
			//$("span.tweetTime").html('<a href="http://twitter.com/'+user+'/statuses/'+id+'" target="_blank">'+posted(created)+'</a>');



		},
		error: function(txt) {
			// em caso de erro
		}
		, dataType: 'json'
	});

	

}





/**
 * Corrige a identacao do texto nas placas
 */
function corrigePaddings(){
    // categorias
    $.each($("ul.#categorias li"), function(index, value) {
        if(index%4==0)
            $(this).css({'padding-left':'36px'});
        if(index%4==2)
            $(this).css({'padding-left':'53px'});
        if(index%4==3)
            $(this).css({'padding-left':'13px'});
    });

    // arquivos
    $.each($("ul.#arquivos li"), function(index, value) {
        if(index%4==0)
            $(this).css({'padding-left':'36px'});
        if(index%4==2)
            $(this).css({'padding-left':'53px'});
        if(index%4==3)
            $(this).css({'padding-left':'13px'});
    });
}


function moveLeft(){
    // incrementa em 20px
    var newPos = parseInt(($(document).width()-1800)/2)+50;
    $("#backgroundTop, #sombraTop, #backgroundMeio, #sombraBottom, #backgroundBottom").stop().animate({backgroundPosition:newPos+'px 0'}, 3000);
}

function moveRight(){
    // incrementa em 20px
    var newPos = parseInt(($(document).width()-1800)/2)-50;
    $("#backgroundTop, #sombraTop, #backgroundMeio, #sombraBottom, #backgroundBottom").stop().animate({backgroundPosition:newPos+'px 0'}, 3000);
}

function moveReset(){
    // incrementa em 20px
    var newPos = parseInt(($(document).width()-1800)/2);
    $("#backgroundTop, #sombraTop, #backgroundMeio, #sombraBottom, #backgroundBottom").stop().animate({backgroundPosition:newPos+'px 0'}, 3000);
}

function initBkgs(){
    // inicializa bkg 1
    var bkg1InitPos = parseInt(($(document).width()-1800)/2);
    $("#backgroundTop").css({backgroundPosition:bkg1InitPos+'px 0'});
    // inicializa bkg 1 sobreposicao transparente
    var bkg1SInitPos =  parseInt(($(document).width()-1800)/2);
    $("#sombraTop").css({backgroundPosition:bkg1SInitPos+'px 0'});

    // inicializa bkg 2
    var bkg2InitPos =  parseInt(($(document).width()-1800)/2);
    $("#backgroundMeio").css({backgroundPosition:bkg2InitPos+'px 0'});

    // inicializa bkg 3 sobreposicao transparente
    var bkg3SInitPos =  parseInt(($(document).width()-1800)/2);
    $("#sombraBottom").css({backgroundPosition:bkg3SInitPos+'px 0'});
    // inicializa bkg 3
    var bkg3InitPos =  parseInt(($(document).width()-1800)/2);
    $("#backgroundBottom").css({backgroundPosition:bkg3InitPos+'px 0'});
    
}


function corrigeColunas(){
    if($("#holder5_1").height()>=$("#holder6RighttMeio").height())
        $("#holder6RighttMeio").height($("#holder5_1").height()-50);
    else{
        $("#holder5LeftMeio").height($("#holder6RighttMeio").height()+50);
    }
}




/**
 * Runtime
 */
$(document).ready(function(){
	// PNGFIX
	$(document).pngFix();
	
	// aciona integracao twitter
	checkTwitter('aomirante');

        // corrige paddings placas de madeira
        corrigePaddings();

        // inicializa bkg para movimento
        initBkgs();

        // corrige altura das colunas de maneira seletiva
        corrigeColunas();
        


});
