(function($){var index,related,loadingElement,modal,modalOverlay,modalLoading,modalContent,modalLoadedContent,modalClose,borderTopLeft,borderTopCenter,borderTopRight,borderMiddleLeft,borderMiddleRight,borderBottomLeft,borderBottomCenter,borderBottomRight;$(function(){$("body").append($([modalOverlay=$('<div id="modalBackgroundOverlay" />')[0],modal=$('<div id="colorbox" />')[0]]).hide());$(modal).append($([borderTopLeft=$('<div id="borderTopLeft" />')[0],borderTopCenter=$('<div id="borderTopCenter" />')[0],borderTopRight=$('<div id="borderTopRight" />')[0],borderMiddleLeft=$('<div id="borderMiddleLeft" />')[0],borderMiddleRight=$('<div id="borderMiddleRight" />')[0],borderBottomLeft=$('<div id="borderBottomLeft" />')[0],borderBottomCenter=$('<div id="borderBottomCenter" />')[0],borderBottomRight=$('<div id="borderBottomRight" />')[0],modalContent=$('<div id="modalContent" />')[0]]));$(modalContent).append($([modalLoadedContent=$('<div id="modalLoadedContent"><a id="contentPrevious" href="#"></a><a id="contentNext" href="#"></a><span id="contentCurrent"></span><br id="modalInfoBr"/><span id="contentTitle"></span><div id="preloadPrevious"></div><div id="preloadNext"></div><div id="preloadClose"></div></div>')[0],modalLoadingOverlay=$('<div id="modalLoadingOverlay"><a id="inactivePrevious" href="#">previous</a><a id="inactiveNext" href="#">next</a>')[0],modalClose=$('<a id="modalClose" href="#"></a>')[0]]));$(modalClose).click(function(){closeModal();return false;});});function setModalOverlay(){$([modalOverlay,modal]).css({"position":"absolute",width:$(window).width(),height:$(window).height(),top:$(window).scrollTop(),left:$(window).scrollLeft()});}
function keypressEvents(e){if(e.keyCode==27){closeModal();return false;}
else if(e.keyCode==37){$("a#contentPrevious").click();return false;}
else if(e.keyCode==39){$("a#contentNext").click();return false;}}
function keyupEvents(e){var userInput=$('#tUsername').val();if(userInput){if(userInput.charAt(0)=='@')
$('#usernameParagraph').html(userInput);else{userInput='@'+userInput;$('#usernameParagraph').html(userInput);$('#tUsername').val(userInput);}}}
function closeModal(){$([modalOverlay,modal]).fadeOut("fast",function(){$(modalLoadedContent).empty();});if(loadingElement){$(loadingElement).remove()};$(document).unbind('keydown',keypressEvents);$(document).unbind('keyup',keyupEvents);$(window).unbind('resize scroll',setModalOverlay);}
$.fn.colorbox=function(settings){settings=$.extend({},$.fn.colorbox.settings,settings);function modalPosition(modalWidth,modalHeight,transitionSpeed,callback){var posTop=$(window).height()/2-modalHeight/2+$(window).scrollTop();var posLeft=$(window).width()/2-modalWidth/2+$(window).scrollLeft();if(posTop<$(borderTopLeft).height()){posTop=$(borderTopLeft).height();}
if(posLeft<$(borderTopLeft).width()){posLeft=$(borderTopLeft).width();}
$(borderMiddleLeft).animate({left:posLeft-$(borderMiddleLeft).width(),height:modalHeight},transitionSpeed);$(borderMiddleRight).animate({left:posLeft+modalWidth,height:modalHeight},transitionSpeed);$(borderTopLeft).animate({left:posLeft-$(borderTopLeft).width()},transitionSpeed);$(borderTopCenter).animate({left:posLeft,width:modalWidth},transitionSpeed);$(borderTopRight).animate({left:posLeft+modalWidth},transitionSpeed);$(borderBottomLeft).animate({left:posLeft-$(borderBottomLeft).width()},transitionSpeed);$(borderBottomCenter).animate({left:posLeft,width:modalWidth},transitionSpeed);$(borderBottomRight).animate({left:posLeft+modalWidth},transitionSpeed);$(modalContent).animate({height:modalHeight,width:modalWidth,left:posLeft},transitionSpeed,function(){if(callback){callback();}
if($.browser.msie&&$.browser.version<7){setModalOverlay();}});}
var preloads=[];function preload(){if(settings.preloading==true&&related.length>1){var previous,next;index>0?previous=related[index-1].href:previous=related[related.length-1].href;index<related.length-1?next=related[index+1].href:next=related[0].href;return[$(new Image()).attr("src",next),$(new Image()).attr("src",previous)];}}
function centerModal(contentHtml,contentInfo){$(modalLoadedContent).hide().html(contentHtml).append(contentInfo);var className=$(modalContent).attr('class');if(className){$(modalContent).removeClass(className);}
if(settings.extraClassName){$(modalContent).addClass(settings.extraClassName);}
if(settings.contentWidth){$(modalLoadedContent).css({"width":settings.contentWidth})}
if(settings.contentHeight){$(modalLoadedContent).css({"height":settings.contentHeight})}
if(settings.transition=="elastic"){modalPosition($(modalLoadedContent).outerWidth(true),$(modalLoadedContent).outerHeight(true),settings.transitionSpeed,function(){$(modalLoadedContent).show();$(modalLoadingOverlay).hide();if(settings.callBackFunction)eval(settings.callBackFunction+'()');});}
else{$(modal).fadeTo(settings.transitionSpeed,0,function(){modalPosition($(modalLoadedContent).outerWidth(true),$(modalLoadedContent).outerHeight(true),0);$(modalLoadedContent).show();$(modalLoadingOverlay).hide();$(modal).fadeTo(settings.transitionSpeed,1,function(){});});}
var preloads=preload();}
function contentNav(){$(modalLoadingOverlay).show();if($(this).attr("id")=="contentPrevious"){index>0?index--:index=related.length-1;}else{index<related.length-1?index++:index=0;}
buildGallery(related[index]);return false;}
function buildGallery(that){var contentInfo="<br id='modalInfoBr'/><span id='contentTitle'>"+that.title+"</span>";if(related.length>1){contentInfo+="<span id='contentCurrent'> "+settings.contentCurrent+"</span>"
contentInfo=contentInfo.replace(/{current}/,index+1).replace(/{total}/,related.length)
if(settings.showPrevious)
contentInfo+="<a id='contentPrevious' href='#'>"+settings.contentPrevious+"</a> "
if(settings.showNext)
contentInfo+="<a id='contentNext' href='#'>"+settings.contentNext+"</a> "}
if(settings.contentInline){centerModal($(settings.contentInline).html(),contentInfo);}else if(settings.contentIframe){centerModal("<iframe src ="+that.href+"></iframe>",contentInfo);}else if(that.href.match(/.(gif|png|jpg|jpeg|bmp|tif)$/i)&&!settings.contentAjax){loadingElement=$(new Image()).load(function(){centerModal("<img src='"+that.href+"' alt=''/>",contentInfo);}).attr("src",that.href);}else{loadingElement=$('<div></div>').load(((settings.contentAjax)?settings.contentAjax:that.href),function(data,textStatus){if(textStatus=="success"){centerModal($(this).html(),contentInfo)}else{centerModal("<p>Ajax request unsuccessful</p>");}});}};$("#modalBackgroundOverlay").unbind();$("#modalBackgroundOverlay").click(function(){$("#modalClose").click();});$(this).click(function(){$(modalLoadedContent).empty().css({"height":"auto","width":"auto"});$(modalLoadedContent).fadeIn("slow",function(){});$(modalClose).html(settings.modalClose);$(modalOverlay).css({"opacity":settings.bgOpacity});$([modalOverlay,modal,modalLoadingOverlay]).fadeIn('slow');$(modalContent).css({width:settings.initialWidth,height:settings.initialHeight});modalPosition($(modalContent).width(),$(modalContent).height(),0);if(this.rel){related=$("a[rel='"+this.rel+"']");index=$(related).index(this);}else{related=$(this);index=0;}
buildGallery(related[index]);$("a#contentPrevious, a#contentNext").die().live("click",contentNav);$(document).bind('keydown',keypressEvents);$(document).bind('keyup',keyupEvents);if($.browser.msie&&$.browser.version<7){$(window).bind("resize scroll",setModalOverlay);}
return false;});return this.each(function(){});};$.fn.colorbox.settings={transition:"elastic",transitionSpeed:350,initialWidth:300,initialHeight:100,contentWidth:false,contentHeight:false,contentAjax:false,contentInline:false,contentIframe:false,bgOpacity:0.85,preloading:true,contentCurrent:"{current} of {total}",showPrevious:true,contentPrevious:"previous",showNext:true,extraClassName:"",callBackFunction:"",contentNext:"next",modalClose:"close"}})(jQuery);