// COLORBOX & TIMEAGO
(function($){var open,element,settings,callback,maxWidth,maxHeight,loadedWidth,loadedHeight,interfaceHeight,interfaceWidth,index,$related,ssTimeout,$slideshow,$window,$close,$next,$prev,$current,$title,$modal,$wrap,$loadingOverlay,$loadingGraphic,$overlay,$modalContent,$loaded,$borderTopCenter,$borderMiddleLeft,$borderMiddleRight,$borderBottomCenter;function IE6Overlay(){$overlay.css({"position":"absolute",width:$window.width(),height:$window.height(),top:$window.scrollTop(),left:$window.scrollLeft()});}
function slideshow(){var stop;function start(){$slideshow.text(settings.slideshowStop).bind("cbox_complete",function(){ssTimeout=setTimeout($.fn.colorbox.next,settings.slideshowSpeed);}).bind("cbox_load",function(){clearTimeout(ssTimeout);}).one("click",function(){stop();$(this).removeClass('hover');});$modal.removeClass("cboxSlideshow_off").addClass("cboxSlideshow_on");}
stop=function(){clearTimeout(ssTimeout);$slideshow.text(settings.slideshowStart).unbind('cbox_complete cbox_load').one("click",function(){start();ssTimeout=setTimeout($.fn.colorbox.next,settings.slideshowSpeed);$(this).removeClass('hover');});$modal.removeClass("cboxSlideshow_on").addClass("cboxSlideshow_off");};if(settings.slideshow&&$related.length>1){if(settings.slideshowAuto){start();}else{stop();}}}
function clearInline(){if($("#cboxInlineTemp").length>0){$loaded.children().insertBefore("#cboxInlineTemp");$("#cboxInlineTemp").remove();}}
function cbox_key(e){if(e.keyCode==37){e.preventDefault();$prev.click();}else if(e.keyCode==39){e.preventDefault();$next.click();}}
function setSize(size,dimension){dimension=dimension=='x'?document.documentElement.clientWidth:document.documentElement.clientHeight;return(typeof size=='string')?(size.match(/%/)?(dimension/100)*parseInt(size,10):parseInt(size,10)):size;}
function isImage(url){return settings.photo?true:url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(.*))?$/i);}
$(function(){$.fn.colorbox.init();});$.fn.colorbox=function(options,custom_callback){if(this.length){this.each(function(){var data=$(this).data("colorbox")?$.extend({},$(this).data("colorbox"),options):$.extend({},$.fn.colorbox.settings,options);$(this).data("colorbox",data).addClass("cboxelement");});}else{$(this).data("colorbox",$.extend({},$.fn.colorbox.settings,options));}
$(this).unbind("click.colorbox").bind("click.colorbox",function(event){element=this;settings=$(element).data('colorbox');element.blur();callback=custom_callback?custom_callback:false;var rel=settings.rel?settings.rel:element.rel;if(rel&&rel!='nofollow'){$related=$('.cboxelement').filter(function(){var relRelated=$(this).data("colorbox").rel?$(this).data("colorbox").rel:this.rel;return(relRelated==rel);});index=$related.index(element);if(index<0){$related=$related.add(element);index=$related.length-1;}}else{$related=$(element);index=0;}
if(!open){$.event.trigger('cbox_open');$close.html(settings.close);$overlay.css({"opacity":settings.opacity}).show();open=true;$.fn.colorbox.position(setSize(settings.initialWidth,'x'),setSize(settings.initialHeight,'y'),0);if($.browser.msie&&$.browser.version<7){$window.bind("resize scroll",IE6Overlay);}}
slideshow();$.fn.colorbox.load();if(settings.overlayClose===true){$overlay.css({"cursor":"pointer"}).click($.fn.colorbox.close);}
event.preventDefault();});if(options&&options.open){$(this).triggerHandler('click.colorbox');}
return this;};$.fn.colorbox.element=function(){return element;};$.fn.colorbox.init=function(){$window=$(window);$('body').prepend($overlay=$('<div id="cboxOverlay" />').hide(),$modal=$('<div id="colorbox" />'));$wrap=$('<div id="cboxWrapper" />').appendTo($modal).append($('<div/>').append($('<div id="cboxTopLeft"/>'),$borderTopCenter=$('<div id="cboxTopCenter"/>'),$('<div id="cboxTopRight"/>')),$borderMiddleLeft=$('<div id="cboxMiddleLeft" />'),$modalContent=$('<div id="cboxContent" />'),$borderMiddleRight=$('<div id="cboxMiddleRight" />'),$('<div/>').append($('<div id="cboxBottomLeft"/>'),$borderBottomCenter=$('<div id="cboxBottomCenter"/>'),$('<div id="cboxBottomRight"/>')));$wrap.find("[id]").css({'float':'left'});$modalContent.append($loaded=$('<div id="cboxLoadedContent" style="width:0; height:0;" />'),$loadingOverlay=$('<div id="cboxLoadingOverlay" />'),$loadingGraphic=$('<div id="cboxLoadingGraphic" />'),$title=$('<div id="cboxTitle" />'),$current=$('<div id="cboxCurrent" />'),$slideshow=$('<div id="cboxSlideshow" />'),$next=$('<div id="cboxNext" />').click($.fn.colorbox.next),$prev=$('<div id="cboxPrevious" />').click($.fn.colorbox.prev),$close=$('<div id="cboxClose" />').click($.fn.colorbox.close));$modalContent.children().addClass("hover").mouseover(function(){$(this).addClass("hover");}).mouseout(function(){$(this).removeClass("hover");}).hide();interfaceHeight=$borderTopCenter.height()+$borderBottomCenter.height()+$modalContent.outerHeight(true)-$modalContent.height();interfaceWidth=$borderMiddleLeft.width()+$borderMiddleRight.width()+$modalContent.outerWidth(true)-$modalContent.width();loadedHeight=$loaded.outerHeight(true);loadedWidth=$loaded.outerWidth(true);$modal.css({"padding-bottom":interfaceHeight,"padding-right":interfaceWidth}).hide();$().bind("keydown.cbox_close",function(e){if(e.keyCode==27){e.preventDefault();$close.click();}});$modalContent.children().removeClass("hover");};$.fn.colorbox.next=function(){index=index<$related.length-1?index+1:0;$.fn.colorbox.load();};$.fn.colorbox.prev=function(){index=index>0?index-1:$related.length-1;$.fn.colorbox.load();};$.fn.colorbox.position=function(mWidth,mHeight,speed,loadedCallback){var winHeight=document.documentElement.clientHeight;var posTop=winHeight/2-mHeight/2;var posLeft=document.documentElement.clientWidth/2-mWidth/2;if(mHeight>winHeight){posTop-=(mHeight-winHeight);}
if(posTop<0){posTop=0;}
if(posLeft<0){posLeft=0;}
posTop+=$window.scrollTop();posLeft+=$window.scrollLeft();mWidth=mWidth-interfaceWidth;mHeight=mHeight-interfaceHeight;$wrap[0].style.width=$wrap[0].style.height="9999px";function modalDimensions(that){$borderTopCenter[0].style.width=$borderBottomCenter[0].style.width=$modalContent[0].style.width=that.style.width;$loadingGraphic[0].style.height=$loadingOverlay[0].style.height=$modalContent[0].style.height=$borderMiddleLeft[0].style.height=$borderMiddleRight[0].style.height=that.style.height;}
var animate_speed=($modal.width()===mWidth&&$modal.height()===mHeight)?0:speed;$modal.dequeue().animate({height:mHeight,width:mWidth,top:posTop,left:posLeft},{duration:animate_speed,complete:function(){modalDimensions(this);$wrap[0].style.width=(mWidth+interfaceWidth)+"px";$wrap[0].style.height=(mHeight+interfaceHeight)+"px";if(loadedCallback){loadedCallback();}
if($.browser.msie&&$.browser.version<7){IE6Overlay();}},step:function(){modalDimensions(this);}});};$.fn.colorbox.dimensions=function(object){if(!open){return;}
$window.unbind('resize.cbox_resize');var speed=settings.transition=="none"?0:settings.speed;$loaded.remove();$loaded=$(object);var width;var height;function getWidth(){if(settings.width){width=maxWidth;}else{width=maxWidth&&maxWidth<$loaded.width()?maxWidth:$loaded.width();}
return width;}
function getHeight(){if(settings.height){height=maxHeight;}else{height=maxHeight&&maxHeight<$loaded.height()?maxHeight:$loaded.height();}
return height;}
$loaded.hide().appendTo('body').attr({id:'cboxLoadedContent'}).css({width:getWidth()}).css({height:getHeight()}).prependTo($modalContent);if($.browser.msie&&$.browser.version<7){$('select').not($('#colorbox select')).css({'visibility':'hidden'});}
if($('#cboxPhoto').length>0&&settings.height){var topMargin=(height-parseInt($('#cboxPhoto')[0].style.height,10))/2;$('#cboxPhoto').css({marginTop:(topMargin>0?topMargin:0)});}
function setPosition(s){var mWidth=width+loadedWidth+interfaceWidth;var mHeight=height+loadedHeight+interfaceHeight;$.fn.colorbox.position(mWidth,mHeight,s,function(){if(!open){return;}
if($.browser.msie){if($('#cboxPhoto').length>0){$loaded.fadeIn(100);}
$modal.css('filter','');}
$modalContent.children().show();$('#cboxIframe').after("<iframe name='iframe_"+new Date().getTime()+"' frameborder=0 src='"+(settings.href?settings.href:element.href)+"' />").remove();$loadingOverlay.hide();$loadingGraphic.hide();$slideshow.hide();if($related.length>1){$current.html(settings.current.replace(/\{current\}/,index+1).replace(/\{total\}/,$related.length));$next.html(settings.next);$prev.html(settings.previous);$().unbind('keydown',cbox_key).one('keydown',cbox_key);if(settings.slideshow){$slideshow.show();}}else{$current.add($next).add($prev).hide();}
$title.html(settings.title?settings.title:element.title);$.event.trigger('cbox_complete');if(callback){callback.call(element);}
if(settings.transition==='fade'){$modal.fadeTo(speed,1,function(){if($.browser.msie){$modal.css('filter','');}});}
$window.bind('resize.cbox_resize',function(){$.fn.colorbox.position(mWidth,mHeight,0);});});}
if(settings.transition=='fade'){$modal.fadeTo(speed,0,function(){setPosition(0);});}else{setPosition(speed);}
if(settings.preloading&&$related.length>1){var prev=index>0?$related[index-1]:$related[$related.length-1];var next=index<$related.length-1?$related[index+1]:$related[0];var nextSrc=$(next).data('colorbox').href?$(next).data('colorbox').href:next.href;var prevSrc=$(prev).data('colorbox').href?$(prev).data('colorbox').href:prev.href;if(isImage(nextSrc)){$('<img />').attr('src',nextSrc);}
if(isImage(prevSrc)){$('<img />').attr('src',prevSrc);}}};$.fn.colorbox.load=function(){element=$related[index];settings=$(element).data('colorbox');$.event.trigger('cbox_load');$loadingOverlay.show();$loadingGraphic.show();$close.show();clearInline();var height=settings.height?setSize(settings.height,'y')-loadedHeight-interfaceHeight:false;var width=settings.width?setSize(settings.width,'x')-loadedWidth-interfaceWidth:false;if(settings.maxHeight){maxHeight=settings.maxHeight?setSize(settings.maxHeight,'y')-loadedHeight-interfaceHeight:false;height=height&&height<maxHeight?height:maxHeight;}
if(settings.maxWidth){maxWidth=settings.maxWidth?setSize(settings.maxWidth,'x')-loadedWidth-interfaceWidth:false;width=width&&width<maxWidth?width:maxWidth;}
maxHeight=height;maxWidth=width;var href=settings.href?settings.href:element.href;if(settings.inline){$('<div id="cboxInlineTemp" />').hide().insertBefore($(href)[0]);$.fn.colorbox.dimensions($(href).wrapAll('<div/>').parent());}else if(settings.iframe){$.fn.colorbox.dimensions($("<div><div id='cboxIframe' /></div>"));}else if(isImage(href)){var loadingElement=new Image();loadingElement.onload=function(){loadingElement.onload=null;if((maxHeight||maxWidth)&&settings.resize){var width=this.width;var height=this.height;var percent=0;var that=this;var setResize=function(){height+=height*percent;width+=width*percent;that.height=height;that.width=width;};if(maxWidth&&width>maxWidth){percent=(maxWidth-width)/width;setResize();}
if(maxHeight&&height>maxHeight){percent=(maxHeight-height)/height;setResize();}}
$.fn.colorbox.dimensions($("<div />").css({width:this.width,height:this.height}).append($(this).css({width:this.width,height:this.height,display:"block",margin:"auto",border:0}).attr('id','cboxPhoto')));if($related.length>1){$(this).css({cursor:'pointer'}).click($.fn.colorbox.next);}
if($.browser.msie&&$.browser.version==7){this.style.msInterpolationMode='bicubic';}};loadingElement.src=href;}else{$('<div />').load(href,function(data,textStatus){if(textStatus=="success"){$.fn.colorbox.dimensions($(this));}else{$.fn.colorbox.dimensions($("<p>Request unsuccessful.</p>"));}});}};$.fn.colorbox.close=function(){open=false;clearTimeout(ssTimeout);$window.unbind('resize.cbox_resize');$slideshow.unbind('cbox_complete cbox_load click');clearInline();$overlay.css({cursor:'auto'}).fadeOut('fast').unbind('click',$.fn.colorbox.close);$().unbind('keydown',cbox_key);if($.browser.msie&&$.browser.version<7){$('select').css({'visibility':'inherit'});$window.unbind('resize scroll',IE6Overlay);}
$modalContent.children().hide();$modal.stop(true,false).removeClass().fadeOut('fast',function(){element.focus();$loaded.remove();$modal.css({'opacity':1});$.event.trigger('cbox_closed');});};$.fn.colorbox.settings={transition:"elastic",speed:350,width:false,height:false,initialWidth:"400",initialHeight:"400",maxWidth:false,maxHeight:false,resize:true,inline:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:true,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,overlayClose:true,slideshow:false,slideshowAuto:true,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow"};})(jQuery);(function($){$.timeago=function(timestamp){if(timestamp instanceof Date)return inWords(timestamp);else if(typeof timestamp=="string")return inWords($.timeago.parse(timestamp));else return inWords($.timeago.parse($(timestamp).attr("title")));};var $t=$.timeago;$.extend($.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"ago",suffixFromNow:"from now",ago:null,fromNow:null,seconds:"less than a minute",minute:"about a minute",minutes:"%d minutes",hour:"about an hour",hours:"about %d hours",day:"a day",days:"%d days",month:"about a month",months:"%d months",year:"about a year",years:"%d years"}},inWords:function(distanceMillis){var $l=this.settings.strings;var prefix=$l.prefixAgo;var suffix=$l.suffixAgo||$l.ago;if(this.settings.allowFuture){if(distanceMillis<0){prefix=$l.prefixFromNow;suffix=$l.suffixFromNow||$l.fromNow;}
distanceMillis=Math.abs(distanceMillis);}
var seconds=distanceMillis/1000;var minutes=seconds/60;var hours=minutes/60;var days=hours/24;var years=days/365;var words=seconds<45&&substitute($l.seconds,Math.round(seconds))||seconds<90&&substitute($l.minute,1)||minutes<45&&substitute($l.minutes,Math.round(minutes))||minutes<90&&substitute($l.hour,1)||hours<24&&substitute($l.hours,Math.round(hours))||hours<48&&substitute($l.day,1)||days<30&&substitute($l.days,Math.floor(days))||days<60&&substitute($l.month,1)||days<365&&substitute($l.months,Math.floor(days/30))||years<2&&substitute($l.year,1)||substitute($l.years,Math.floor(years));return $.trim([prefix,words,suffix].join(" "));},parse:function(iso8601){var s=$.trim(iso8601);s=s.replace(/-/,"/").replace(/-/,"/");s=s.replace(/T/," ").replace(/Z/," UTC");s=s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2");return new Date(s);}});$.fn.timeago=function(){var self=this;self.each(refresh);var $s=$t.settings;if($s.refreshMillis>0){setInterval(function(){self.each(refresh);},$s.refreshMillis);}
return self;};function refresh(){var date=$t.parse(this.title);if(!isNaN(date)){$(this).text(inWords(date));}
return this;}
function inWords(date){return $t.inWords(distance(date));}
function distance(date){return(new Date().getTime()-date.getTime());}
function substitute(stringOrFunction,value){var string=$.isFunction(stringOrFunction)?stringOrFunction(value):stringOrFunction;return string.replace(/%d/i,value);}
document.createElement('abbr');})(jQuery);


$(document).ready(function() {
	
	jQuery('abbr[class*=timeago]').timeago();
	$('A[rel*="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
	
	// $('div.big-left-column a').each( function() {
	// 	var url = $(this).attr('href') + '#content';
	// 	$(this).attr('href', url);
	// });
	
	$(".cbox").colorbox({slideshow:true});
	
	var top = 0;
	var newtop = 0;
	
	$('.layout').each( function() {
		
		var csstop = parseInt($(this).css('top'));
		if (csstop == 0) csstop = 12;
		
		newtop = ( parseInt($(this).height()) + csstop );
		
		if (newtop > top){
			top = newtop;
		}
	});
	
	
	$('#footer-bar').css('top',$(document).height() - 4);//top - 1);
	$('#footer-bar').css('display','block');
	$('#bg').css('height',$(document).height());
	
	// var contentheight = top - parseInt($('#content').css('top')) + parseInt($('#footer-bar').height());
	// $('#content').css('height',contentheight);
});

FLIR.init( { path: 'scripts/flir/' } );
FLIR.auto( [ 'h2' , 'div#navigation li a'] );
