/**
 * Thickbox 4 - One Box To Rule Them All.
 * © 2009 Zetafleet, 2007 Cody Lindley
 * Original by Cody Lindley <http://www.codylindley.com>
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 */(function($){$.fn.thickBox=function(){this.click($.thickBox.show)},$.thickBox=new function(){var self=this;this.widgets={shade:$('<div id="TB_overlay"></div>'),dialogue:$('<div id="TB_window"></div>'),throbber:$('<div id="TB_load"></div>'),titleBar:$('<div id="TB_title"></div>'),title:$('<div id="TB_ajaxWindowTitle"></div>'),closeContainer:$('<div id="TB_closeAjaxWindow"></div>'),closeButton:$('<a id="TB_closeWindowButton">Close</a>'),captionBar:$('<div id="TB_caption"></div>'),caption:$("<div></div>"),previousButton:$('<a id="TB_prev">« Previous</a>'),nextButton:$('<a id="TB_next">Next »</a>'),content:null},this.active=!1,this.modal=!1,this.currentGroup=[],this.currentIndex=-1,this.throbber=new Image,this.throbber.src=window.theme_location+"/images/throbber.gif",this.contentLoader=undefined,this.contentWidth=-1,this.contentHeight=-1,this.activate=function(){this.rel?self.currentGroup=$('*[rel="'+this.rel+'"]'):self.currentGroup=$(this),self.widgets.shade.show(),self.widgets.dialogue.hide(),$(document.body).append(self.widgets.shade).append(self.widgets.dialogue).append(self.widgets.throbber),this.active=!0},this.show=function(a){a.stopPropagation(),a.preventDefault(),this.active||self.activate.call(this),typeof document.body.style.maxHeight=="undefined"&&($("html, body").css({height:"100%",width:"100%"}),$("html").css("overflow","hidden"),$(document.body).append('<iframe id="TB_HideSelect"></iframe>')),$(document).keypress(self.onKeyPressed),self.currentIndex=self.currentGroup.index(this),self.widgets.throbber.show(),self.widgets.previousButton[self.currentIndex>0?"show":"hide"](),self.widgets.nextButton[self.currentIndex<self.currentGroup.length-1?"show":"hide"]();var b=this.href.indexOf("?")!=-1?this.href.substr(0,this.href.indexOf("?")):this.href;self.contentLoader!=undefined&&($(self.contentLoader).unbind("load",self.onContentLoaded),$(self.contentLoader).remove(),self.contentLoader=undefined);var c=[],d,e,f=this.href.split(/[?&]TB_/)[0],g=/\.(jpe?g|jfif?|png|gif|bmp)$/i.test(b),h=/\.(swf|svgz?)$/i.exec(b),i=this.href.indexOf("TB_iframe")!=-1,j=this.href.indexOf("TB_inline")!=-1,k=!g&&!h&&!i&&!j;if(this.href.indexOf("?")!=-1){d=this.href.substr(this.href.indexOf("?")+1).split("&");for(var l=d.length-1;l>=0;--l)e=d[l].split("="),e.length==1?c.push(decodeURIComponent(e[0])):c[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}delete d,delete e,self.contentWidth=c.width?parseInt(c.width,10)+(i?30:0):630,self.contentHeight=c.height?parseInt(c.height,10)+(i?40:0):440,self.modal=c.modal||!1,g&&(self.contentLoader=$("<img />").load(self.onContentLoaded).attr("src",f));if(h){var m=/\.(swf|svgz?)$/i.exec(b)[1],n;switch(m){case"swf":n="application/x-shockwave-flash";break;case"svg":case"svgz":n="image/svg+xml"}self.contentLoader=$('<object type="'+n+'" width="'+self.contentWidth+'" height="'+self.contentHeight+'"></object>').load(self.onContentLoaded),m=="swf"&&self.contentLoader.append('<param name="movie" value="'+f+'" />'),self.contentLoader.attr("data",f)}i&&(self.contentLoader=$('<iframe id="TB_iframeContent" frameborder="no" framespacing="0" scrolling="'+(c.scrolling||"auto")+'"></iframe>').load(self.onContentLoaded).attr("src",f));j?(self.contentLoader=$('<div id="TB_ajaxContent"></div>').append($("#"+c.inlineId).html()).insertAfter(self.widgets.titleBar),self.onContentLoaded.call(self.contentLoader)):(k&&(self.contentLoader=$('<div id="TB_ajaxContent"></div>').load(f,self.onContentLoaded)),self.contentLoader.hide().insertAfter(self.widgets.titleBar))},this.onContentLoaded=function(a){var b=self.currentGroup[self.currentIndex];b.title&&self.widgets.title.html(b.title),self.widgets.content&&self.widgets.content.remove(),self.widgets.content=$(this).unbind("load",arguments.callee),self.contentLoader=undefined,self.widgets.throbber.fadeOut(),self.widgets.dialogue.fadeIn(),self.widgets.content.fadeIn();var c=self.widgets.content.outerWidth(!0)-self.widgets.content.width(),d=self.widgets.content.outerHeight(!0)-self.widgets.content.height()+self.widgets.titleBar.outerHeight(!0)+self.widgets.captionBar.outerHeight(!0);if(/^(img|object)$/i.test(this.nodeName)){var e=$(window).width()-c-80,f=$(window).height()-d-50,g=this.width,h=this.height;g>e?(h=h*(e/g),g=e,h>f&&(g=g*(f/h),h=f)):h>f&&(g=g*(f/h),h=f,g>e&&(h=h*(e/g),g=e)),self.contentWidth=g,self.contentHeight=h,delete g,delete h,delete e,delete f}self.widgets.content.css({width:self.contentWidth+"px",height:self.contentHeight+"px"});var i=c+self.widgets.content.width(),j=d+self.widgets.content.height();self.widgets.dialogue.css({"margin-top":"-"+j*.5+"px","margin-left":"-"+i*.5+"px",width:i+"px",height:j+"px"}),typeof document.body.style.maxHeight=="undefined"&&self.widgets.dialogue.css("margin-top","")},this.next=function(a){self.show.call(self.currentGroup[self.currentIndex+1],a)},this.previous=function(a){self.show.call(self.currentGroup[self.currentIndex-1],a)},this.close=function(a){$(document).unbind("keypress",self.onKeyPressed),self.widgets.throbber.fadeOut(),self.widgets.dialogue.fadeOut("normal",function(){typeof document.body.style.maxHeight=="undefined"&&($("#TB_HideSelect").remove(),$("html, body").css({height:"",width:""}),$("html").css("overflow",""),$("#TB_HideSelect").remove()),self.widgets.content.remove(),self.widgets.content=undefined,self.widgets.shade.hide()})},this.onKeyPressed=function(a){a.keyCode==27?self.close(a):a.keyCode==190&&self.currentIndex<self.currentGroup.length-1?this.next(a):a.keyCode==188&&self.currentIndex>0&&this.previous(a)};with(this.widgets)closeContainer.append(closeButton),titleBar.append(title).append(closeContainer),captionBar.append(previousButton).append(nextButton).append(caption),dialogue.append(titleBar).append(captionBar),throbber.click(this.close),shade.click(this.close),closeButton.click(this.close),previousButton.click(this.previous),nextButton.click(this.next)}})(jQuery),$(function(){$("a.thickbox, area.thickbox, input.thickbox").thickBox()})
