(function($){window._=window._||function(s){return s;};$.browser.msie6=$.browser.msie&&$.browser.version<7;$.extend({thickbox:new function(){TB_TYPE={AJAX:'ajax',CONFIRM:'confirm',EXTERNAL:'external',IMAGE:'image',INLINE:'inline'};TB_ID={DIM:'tb-dim',LOADING:'tb-loading',MODAL:'tb-modal',TITLE:'tb-title',CLOSE:'tb-close',CONTENT:'tb-content',BROWSE:'tb-browse',NEXT:'tb-next',PREV:'tb-prev'};var dim,loading,modal,content,close;var request;var defaultValues={top:'',left:'',width:300,minWidth:250,height:340,animate:null,i18n:{close:{text:'Close',title:'Close this window'},count:{text:'Image %{image} / %{count}'},next:{text:'Next',title:'Show next image'},prev:{text:'Previous',title:'Show previous image'},confirm:{what:'Are you sure?',confirm:'Yes',cancel:'No'}}};function setup(type,builder){dim=$('#'+TB_ID.DIM);dim=dim.size()&&dim||$('<div id="'+TB_ID.DIM+'">'+($.browser.msie6?'<iframe src="about:blank" frameborder="0"></iframe>':'')+'</div>').appendTo(document.body).hide();$('iframe',dim).bind('focus',hide);loading=$('#'+TB_ID.LOADING);loading=loading.size()&&loading||$('<div id="'+TB_ID.LOADING+'"></div>').appendTo(document.body);modal=$('#'+TB_ID.MODAL);modal=modal.size()&&modal||$('<div id="'+TB_ID.MODAL+'"></div>').append('<b class="tb-tl"></b><b class="tb-tr"></b><b class="tb-br"></b><b class="tb-bl"></b>').appendTo(document.body);modal.attr('class','tb-'+type);content=$('#'+TB_ID.CONTENT);content=content.size()&&content||$('<div id="'+TB_ID.CONTENT+'"></div>').appendTo(modal);close=$('#'+TB_ID.CLOSE);close=close.size()&&close||$('<div id="'+TB_ID.CLOSE+'"><a href="#" title="'+defaultValues.i18n.close.title+'">'+defaultValues.i18n.close.text+'</a></div>').appendTo(modal);$('a',close).bind('click',hide);dim.unbind('click').one('click',hide);if(!dim.is(':visible')){dim.show();}
loading.show();builder();$(document).bind('keydown',keydown).bind('keypress',blockKeys);$(window).bind('scroll',blockScroll);}
function show(width,height,top,left,animate,callback){loading.hide();var css={width:width+'px',height:height+'px'},noUnit=/^\d+$/;if(!top){css['top']='';if(!$.browser.msie6){css['margin-top']=-parseInt(height/2)+'px';}else{dim[0].style.setExpression('height','document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + "px"');loading[0].style.setExpression('marginTop','0 - parseInt(this.offsetHeight / 2) + (document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + "px"');modal[0].style.setExpression('marginTop','0 - parseInt(this.offsetHeight / 2) + (document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + "px"');}}else{css['top']=top+((top+'').match(noUnit)?'px':'');css['margin-top']='';}
if(!left){css['left']='';css['margin-left']=-parseInt(width/2)+'px';}else{css['left']=left+((left+'').match(noUnit)?'px':'');css['margin-left']='';}
animate?modal.css(css).animate(animate.animation,animate.speed):modal.css(css).show();typeof callback=='function'&&callback(modal[0]);}
function hide(callback){if(request){request.abort();request=null;}
loading.hide();modal.hide();dim.hide();content.empty();typeof callback=='function'&&callback();$(document).unbind('keydown',keydown).unbind('keypress',blockKeys);$(window).unbind('scroll',blockScroll);next=previous=function(){};return false;}
function blockKeys(e){var allowed=$('a, button, input, select, textarea',modal);for(var i=0,k=allowed.length;i<k;i++){if(allowed[i]==e.target){return true;}}
return false;}
function blockScroll(){return false;}
var next=function(){},previous=next;function keydown(e){var key=e.which||e.keyCode||-1;switch(key){case 27:hide();break;case 37:previous();break;case 39:next();break;default:blockKeys(e);}}
function buildTitle(title){if(title){content.prepend('<h2 id="'+TB_ID.TITLE+'">'+title+'</h2>');}}
this.defaults=function(override){defaultValues=$.extend(defaultValues,override);};this.render=function(settings,callback){settings=$.extend({top:defaultValues.top,left:defaultValues.left,width:defaultValues.width,height:defaultValues.height,slideshow:false},settings);return this.each(function(){var $$=$(this),hostname=this.hostname&&this.hostname.replace(/:\d*$/,''),port=parseInt(this.port)||80,hash=this.hash&&this.hash.replace('#','')||'';var isLink=$$.is('a')&&this.href;var isImage=isLink&&this.href.match(/\.(bmp|gif|jpe?g|png)/gi);var isInline=!!hash;var isAjax=hostname==location.hostname&&port==(location.port||80)&&!isInline;var isExternal=isLink&&(hostname!=location.hostname||port!=(location.port||80));var isForm=$$.is('form');var type=isImage&&TB_TYPE.IMAGE||isInline&&TB_TYPE.INLINE||isAjax&&TB_TYPE.AJAX||isExternal&&TB_TYPE.EXTERNAL||isForm&&TB_TYPE.CONFIRM;var builder;switch(type){case TB_TYPE.IMAGE:builder=function(){var title=$$.attr('title')||'',rel=$$.attr('rel');if(rel){var group=$('a[rel="'+rel+'"]'),size=group.size(),i=group.index($$[0]);var count='<em>'+defaultValues.i18n.count.text.replace(/%\{image\}/,i+1).replace(/%\{count\}/,size)+'</em>';if(size>1){var buildShowFunc=function(el){return function(){modal.hide();content.empty();$(el).trigger('click');return false;};};var nextHtml='<strong id="'+TB_ID.NEXT+'"><a href="#" title="'+defaultValues.i18n.next.title+'">'+defaultValues.i18n.next.text+'</a></strong>';next=buildShowFunc(group[i+1]||group[0]);var previousHtml='<strong id="'+TB_ID.PREV+'"><a href="#" title="'+defaultValues.i18n.prev.title+'">'+defaultValues.i18n.prev.text+'</a></strong>';previous=buildShowFunc(group[i-1]||group[size-1]);}}
var img=new Image();img.onload=function(){img.onload=null;var subtraction=150;var viewportWidth=(self.innerWidth||$.boxModel&&document.documentElement.clientWidth||document.body.clientWidth)-subtraction;var viewportHeight=(self.innerHeight||$.boxModel&&document.documentElement.clientHeight||document.body.clientHeight)-subtraction;var imgWidth=img.width;var imgHeight=img.height;if(imgWidth>viewportWidth){imgHeight=imgHeight*viewportWidth/imgWidth;imgWidth=viewportWidth;if(imgHeight>viewportHeight){imgWidth=imgWidth*viewportHeight/imgHeight;imgHeight=viewportHeight;}}else if(imgHeight>viewportHeight){imgWidth=imgWidth*viewportHeight/imgHeight;imgHeight=viewportHeight;if(imgWidth>viewportWidth){imgHeight=imgHeight*viewportWidth/imgWidth;imgWidth=viewportWidth;}}
imgWidth=parseInt(imgWidth);imgHeight=parseInt(imgHeight);$('<img src="'+$$.attr('href')+'" alt="Image" width="'+imgWidth+'" height="'+imgHeight+'" title="'+title+'" />').appendTo(content);if(rel){$(['<p id="'+TB_ID.BROWSE+'">',(previousHtml||''),(nextHtml||''),count,'</p>'].join('')).appendTo(content);if(size>1){$('#'+TB_ID.NEXT+' a').bind('click',next);$('#'+TB_ID.PREV+' a').bind('click',previous);}}
show(Math.max(imgWidth,defaultValues.minWidth)+20,imgHeight+(rel?65:50),settings.top,settings.left,settings.animate,callback);};img.src=$$.attr('href');};break;case TB_TYPE.INLINE:var inlineContent=$($$[0].hash);builder=function(){buildTitle($$.attr('title'));inlineContent.css('display','block').appendTo(content);show(settings.width,settings.height,settings.top,settings.left,settings.animate,callback);};break;case TB_TYPE.AJAX:builder=function(){buildTitle($$.attr('title'));request=$.ajax({url:$$.attr('href'),dataType:'html',global:false,success:function(r){content.append(r);show(settings.width,settings.height,settings.top,settings.left,settings.animate,callback);}});};break;case TB_TYPE.EXTERNAL:builder=function(){buildTitle($$.attr('title'));$('<iframe id="'+TB_ID.CONTENT+'" src="'+$$.attr('href')+'" frameborder="0"></iframe>').appendTo(content);show(settings.width,settings.height,settings.top,settings.left,settings.animate,callback);};break;case TB_TYPE.CONFIRM:builder=function(){buildTitle($('*[type="submit"][title]',$$).attr('title')||defaultValues.i18n.confirm.what);$('<a id="tb-confirm" href="#">'+defaultValues.i18n.confirm.confirm+'</a>').appendTo(content).click(function(){hide(settings.onConfirm||function(){$$[0].submit();});return false;});$('<a id="tb-cancel" href="#">'+defaultValues.i18n.confirm.cancel+'</a> ').appendTo(content).click(function(){hide();return false;});show(settings.width,(settings.height==defaultValues.height?90:settings.height),settings.top,settings.left,settings.animate,callback);};break;default:alert('You can apply a Thickbox to links and forms only.');}
if(builder){$$.bind((type==TB_TYPE.CONFIRM?'submit':'click'),function(){setup(type,builder);this.blur();return false;});}});};}});$.fn.extend({thickbox:$.thickbox.render});})(jQuery);jQuery.thickbox.defaults({i18n:{close:{text:_('Close'),title:_('Close this window')},count:{text:_('Image %{image} / %{count}')},next:{text:_('Next'),title:_('Show next image')},prev:{text:_('Previous'),title:_('Show previous image')},confirm:{what:_('Are you sure?'),confirm:_('Yes'),cancel:_('No')}}});(function(){$('#comments').delegate('submit',{'.manage':function(e){if($.plazes.confirm(e.target)){var $form=$(e.target);$form.ajaxSubmit({success:function(){var $li=$form.parents('li:first').fadeOut(500,function(){$li.remove();});},error:function(){}});}
return false;}});var check;function enable(){if(this.value&&this.value!=this.defaultValue){$button.removeClass('disabled');clearInterval(check);}
else
$button.addClass('disabled');}
function disable(){if(!this.value||this.value==this.defaultValue)
$button.addClass('disabled');clearInterval(check);}
var $form=$('#add-comment');var $button=$('button',$form).addClass('disabled');var $textarea=$('textarea',$form).each(function(){this.value=this.defaultValue=this.title;$(this).removeAttr('title').searchField().bind('keyup',enable).bind('blur',disable).bind('focus',function(){var that=this;check=setInterval(function(){enable.apply(that);},100);});});$form.ajaxForm({beforeSubmit:function(){var submit=!!$button.not('.disabled').length;if(submit)
$button.wait();return submit;},success:function(html){$($('#comments ol')[0]||$('<ol></ol>').insertAfter('#comments div.caption')[0]).append(html).find('li:last').css('display','none').animate({opacity:'show',height:'show'},300);},complete:function(){$textarea.val($textarea.attr('defaultValue'));$button.wait(true);}});$('#comments div.caption a').bind('click',function(){$textarea.focus();return false;});})();(function(){$('#add-plaze a').thickbox({width:480,height:450},function(){$('#tb-content form').each(function(){var $form=$(this).ajaxForm({beforeSubmit:function(){$form.hide().parents('li:first').processing();},success:function(){$form.parents('li:first').remove(500);}});});});$('#plazes form.manage').confirm();if(!$('#content ul.preview li').length)
$('#leave-group form').confirm();})();
