
var gFirenzeTouch=false;jQuery(function($){var $selected=$("body > *[selected='true'], body > *[selected='selected']");if($selected.length){$selected=$selected.eq(0);}
else{$selected=$("body>*:first").attr("selected","true");}
$.ajaxSetup({cache:false});$(".timeline .more.loader a").live("click",function(e){e.preventDefault();var $p=$(this).parent();$.get(this.href+"&paging=1&id="+$p.attr("id"),function(data){$p.replaceWith(data);filterRows($("#timeline").data("filter"));});$(this).replaceWith("<span class='spinner'></span>");removeDuplicates();});function filterRows(filter){if(!filter.length){filter="all";}
$("#timeline li").not(".filters, .scrolltotop, .powered-by").hide();var $rows=$("#timeline li."+filter);$rows.show();}
function highlightNewItems(){$("#NewsFeed li.new").each(function(i,x){setTimeout(function(){var $bgcolor=$("#timeline").css("background-color");var hlcolor=$(x).css("background-color");$(x).removeClass("new");$(x).css("background-color",$bgcolor);$(x).effect("highlight",{color:hlcolor},1500);},$("#timeline").attr("data-highlighttimer"));});}
function loadRecent(){var $latest=$("#timeline").attr("data-latest");var $first=$("#NewsFeed li:first");$.get('recent.cfm?latest='+$latest,function(data){$first.before(data);filterRows($("#timeline").data("filter"));$("#timeline").attr("data-latest",$("#timeline li:first").attr("data-timestamp"));highlightNewItems();setTimeout(loadRecent,$("#timeline").attr("data-refreshtimer"));});}
function removeDuplicates(){$("#NewsFeed li").each(function(){if($(this).attr("id").length){var thisid=$(this).attr("id");$("#"+thisid).not(":first").remove();}});}
$("#filters").live("click",function(e){if(!$(e.target).is("a"))return true;e.preventDefault();filterRows(e.target.rel);$("#filters a").parent().removeClass("selected");$(e.target).parent().addClass("selected");$("#timeline").data("filter",e.target.rel);});$(document).ready(function(){if($("#NewsFeed").length){$("#timeline").data("filter","all");$(".selected li").click();setTimeout(loadRecent,$("#timeline").attr("data-refreshtimer"));}});$(document).bind("counter",function(e){if(console)console.log("Counter fired");var interval=10;function updateCounters(){var found=0;$(".counter").each(function(){if(typeof(this.innerHTML)!=="undefined"){var $f=$(this).closest("form");var left=maxLength($f)-$f.find("textarea[name='Comment']").eq(0).val().length;this.innerHTML=left;found++;}});if(found)setTimeout(updateCounters,interval);}
setTimeout(updateCounters,interval);});$(document).submit(function(e){if("contribute"!==e.target.id||"form"!==e.target.localName.toLowerCase()||!gFirenzeTouch)return true;var form=e.target;e.preventDefault();var options={url:form.action,type:"POST",dataType:"json",data:$(form).serialize(),success:function(data,textStatus){if(data.status==="SUCCESS"){$.jQTouch.showPageByHref(data.display);}
else{$(".error",form).text(data.errMsg||"Contributions appear to be unavailable at the moment. Please try again in a little while.").show();}},error:function(XMLHttpRequest,textStatus,errorThrown){console.log("ERROR!",textStatus||errorThrown);$(".error",form).text("Contributions appear to be unavailable at the moment. Please try again in a little while.").show();}}
$(".error",form).hide();$.ajax(options);});installPageHandlers();if($("body").css("outline-width")==="1px"&&!window.opera){$(document).bind("pageTransitionEnd",installPageHandlers);$.jQTouch({slideInSelector:"ul:not(.tabs) li:not(.noslide) a, .slide",icon:"/assets/img/apple-touch-icon.png",iconIsGlossy:true});gFirenzeTouch=true;}
function maxLength($form){return parseInt($form.attr("max"))||140;}
function arrayLast(arr){return $.isArray(arr)?arr[arr.length-1]:null;}
function installPageHandlers(){var $p=gFirenzeTouch?$.jQTouch.getSelectedPage():$selected;if($p.data("firenze:handlers")===true)return;$p.find("input.toggler[name]:checkbox").each(function(){var $target=$p.find(".toggler-"+this.name);if($target.length===0)return;$(this).change(function(){$target.toggle($(this).attr("checked"));}).change();});installTabs($p);$p.data("firenze:handlers",true);}
function installTabs($context){$context.find(".tabset").filter(function(){return $(this).css("outline-width")==="1px";}).find(".tab-pane").hide().end().find(".tabs").not(":has(.selected)").children(":first-child").addClass("selected").end().end().find("a").each(function(){var href=$(this).attr("href");var hash=arrayLast(href.split(/(?=#)/));if(!hash||hash.charAt(0)!=="#")return;var $el=$context.find(hash);if($el.length==0)return;$(this).attr("href",hash);$el.filter(":empty").each(function(){$(this).addClass("loading").load(href,{format:"bare"},function(){$(this).removeClass("loading")});});}).end().click(function(e){var hash=$(e.target).attr("href");if(hash.charAt(0)==="#"){e.preventDefault();$(e.target).parent().addClass("selected").siblings().removeClass("selected");$(this).closest(".tabset").find(".tab-pane:visible").hide().end().find(hash).show();}}).find(".selected:first a").click().end();}});
