(function($){$.jquery=$.jquery||{};$.jquery.ux=$.jquery.ux||{};$.jquery.ux.ui=$.jquery.ux.ui||{};$.jquery.ux.ui.BPHelper=function(){return{AUTO_ID:1001,galleries:{},isBoxRendered:function(){return $('#bp').size()>0?true:false},isBoxVisible:function(){return $('#bp > .bp-wrap').is(':visible')},renderBox:function(){if($.jquery.ux.ui.BPHelper.isBoxRendered()){return}var sbox=document.createElement('div');var mask=document.createElement('div');var wrap=document.createElement('div');var main=document.createElement('div');var view=document.createElement('div');var bbar=document.createElement('div');$(bbar).addClass('bp-bbar').append('<div class="bp-hide-link"><a href="#"><span>Close</span></a></div>').append('<div class="bp-info-link"><a href="#"><span>Image info</span></a></div>').append('<div class="bp-clear"></div>');$(view).addClass('bp-view').css({'margin':0}).append('<div class="bp-nav bp-prev-link"><a href="#"><span>Prev</span></a></div>').append('<div class="bp-nav bp-next-link"><a href="#"><span>Next</span></a></div>').append('<div class="bp-info-wrap"><div class="bp-info"></div></div>');$(main).addClass('bp-main').css({'margin-left':'auto','margin-right':'auto'}).append(view).append(bbar);$(wrap).addClass('bp-wrap').append(main);$(mask).addClass('bp-mask');$(sbox).attr('id','bp').append(mask).append(wrap).appendTo('form');$(window).resize(function(e){if($.jquery.ux.ui.BPHelper.isBoxVisible()){$.jquery.ux.ui.BPHelper.onWindowResize()}});$(mask).click(function(e){$.jquery.ux.ui.BPHelper.hideBox()});$(wrap).click(function(e){$.jquery.ux.ui.BPHelper.hideBox()});$(main).click(function(e){e.preventDefault();return false});$('.bp-hide-link',bbar).click(function(e){e.preventDefault();$.jquery.ux.ui.BPHelper.hideBox()})},showBox:function(){$.jquery.ux.ui.BPHelper.onWindowResize();$('#bp .bp-mask').show();$('#bp .bp-wrap').show()},hideBox:function(){$.jquery.ux.ui.BPHelper.resetBox();$('#bp .bp-wrap').fadeOut('fast',function(){$('#bp .bp-mask').hide()})},resetBox:function(){$('#bp .bp-bbar').stop().hide();$('#bp .bp-info-wrap').stop().hide().css({'marginTop':0});$('#bp .bp-info-link > a').removeClass('active');$('#bp .bp-view > img').remove()},onWindowResize:function(){var ds=$.jquery.ux.ui.BPHelper.getDimensions();var ps=$.jquery.ux.ui.BPHelper.getPageScroll();$('#bp .bp-mask').width(ds.pageWidth).height(ds.pageHeight);$('#bp .bp-wrap').css({'left':0,'top':ps.y+(ds.windowHeight*0.08)})},getDimensions:function(){var dims={};var dbw,dbh;if(window.innerHeight&&window.scrollMaxY){dbw=window.innerWidth+window.scrollMaxX;dbh=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){dbw=document.body.scrollWidth;dbh=document.body.scrollHeight}else{dbw=document.body.offsetWidth;dbh=document.body.offsetHeight}if(self.innerHeight){if(document.documentElement.clientWidth){dims.windowWidth=document.documentElement.clientWidth}else{dims.windowWidth=self.innerWidth}dims.windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){dims.windowWidth=document.documentElement.clientWidth;dims.windowHeight=document.documentElement.clientHeight}else if(document.body){dims.windowWidth=document.body.clientWidth;dims.windowHeight=document.body.clientHeight}dims.pageHeight=Math.max(dbh,dims.windowHeight);dims.pageWidth=Math.max(dbw,dims.windowWidth);return dims},getPageScroll:function(){var scroll={};if(self.pageYOffset){scroll.y=self.pageYOffset;scroll.x=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){scroll.y=document.documentElement.scrollTop;scroll.x=document.documentElement.scrollLeft}else if(document.body){scroll.y=document.body.scrollTop;scroll.x=document.body.scrollLeft}return scroll}}}();$.jquery.ux.ui.BigPicture=function(el,conf){this.images=[];this.index=0;this.gallery='';this.offset=false;conf=$.extend({'cls':'','prevLabel':'Prev','nextLabel':'Next','infoLabel':'Image info','hideLabel':'Close','boxEaseFn':'','boxEaseSpeed':750,'enableInfo':false,'infoPosition':'bottom','infoEaseFn':'','infoEaseSpeed':500},conf);if(!$(el).attr('id')){$(el).attr('id','bigPicture-'+$.jquery.ux.ui.BPHelper.AUTO_ID++)}this.gallery=$(el).attr('rel');if(this.gallery&&!$.jquery.ux.ui.BPHelper.galleries[this.gallery]){$.jquery.ux.ui.BPHelper.galleries[this.gallery]=$("a[rel='"+this.gallery+"']").get()}this.launchBox=function(){if(this.images.length==0){if(this.gallery){this.images=$.jquery.ux.ui.BPHelper.galleries[this.gallery]}else{this.images.push(el)}}this.index=0;for(var i=0;i<this.images.length;i++){if(this.images[i].id==el.id){this.index=i;break}}this.show()};this.show=function(){$.jquery.ux.ui.BPHelper.renderBox();$('#bp').removeClass().addClass(conf.cls);$('#bp .bp-prev-link > a > span').html(conf.prevLabel);$('#bp .bp-next-link > a > span').html(conf.nextLabel);$('#bp .bp-info-link > a > span').html(conf.infoLabel);$('#bp .bp-hide-link > a > span').html(conf.hideLabel);var sbox=this;$('#bp .bp-view').unbind('mouseenter.bp').unbind('mouseleave.bp').bind('mouseenter.bp',function(){sbox.toggleNavigation(true)}).bind('mouseleave.bp',function(){sbox.toggleNavigation(false)});$('#bp .bp-prev-link > a').unbind('click.bp').bind('click.bp',function(e){e.preventDefault();sbox.back()});$('#bp .bp-next-link > a').unbind('click.bp').bind('click.bp',function(e){e.preventDefault();sbox.next()});if(conf.enableInfo){$('#bp .bp-info-link').show();$('#bp .bp-info-link > a').unbind('click.bp').bind('click.bp',function(e){e.preventDefault();sbox.toggleInfo(this)})}else{$('#bp .bp-info-link').hide()}$('#bp .bp-main').width(64).height(64);if(!$.jquery.ux.ui.BPHelper.isBoxVisible()){$.jquery.ux.ui.BPHelper.showBox()}this.load()};this.hide=function(){$.jquery.ux.ui.BPHelper.hideBox()};this.reset=function(){$.jquery.ux.ui.BPHelper.resetBox()};this.load=function(){this.reset();$('#bp .bp-main').addClass('loading');this.calculateOffset();var box=this;var img=new Image();$(img).load(function(){$('#bp .bp-main').animate({'width':img.width+box.offset.x,'height':img.height+box.offset.y},conf.boxEaseSpeed,conf.boxEaseFn,function(){box.onLoad(img)})}).error(function(){box.hide();alert('There was an error loading the image')}).attr('src',$(this.images[this.index]).attr('href'))};this.onLoad=function(img){if(conf.enableInfo){var title=$(this.images[this.index]).attr('title');var divId=$(this.images[this.index]).attr('name');var count=this.images.length;var $wrap=$('#bp .bp-info-wrap');var txt='';if(count>1){txt+='<div class="bp-count">Image '+(this.index+1)+' of '+count+'</div>'}txt+=title?'<h2>'+title+'</h2>':'';$('#bp .bp-info').html(txt).append($('#'+divId).contents().clone(true));$('#bp .bp-info a').click(function(e){var href=$(this).attr('href');if(href&&href.charAt(0)!='#'){document.location=href}});var y=conf.infoPosition=='top'?(-1*$wrap.outerHeight()):img.height;$wrap.css({'top':y})}$('#bp .bp-main').removeClass('loading');$('#bp .bp-info-wrap').before(img);$('#bp .bp-view').width(img.width).height(img.height).fadeIn('normal');$('#bp .bp-nav > a').width(Math.floor(img.width/2)).height(img.height);var bh=img.height+this.offset.y+$('#bp .bp-bbar').outerHeight();$('#bp .bp-bbar').show();$('#bp .bp-main').animate({'height':bh},350);$(img).click().focus()};this.toggleInfo=function(link){if(!conf.enableInfo){return}var h=$('#bp .bp-info-wrap').outerHeight();var b=conf.infoPosition=='top'?0:$('#bp .bp-view > img').height();var hide=false;if($(link).hasClass('active')){$(link).removeClass('active');h=conf.infoPosition=='top'?h:0;hide=true}else{$(link).addClass('active');h=conf.infoPosition=='top'?0:h}$('#bp .bp-info-wrap').show().animate({'top':b-h},conf.infoEaseSpeed,conf.infoEaseFn,function(){if(hide){$('#bp .bp-info-wrap').hide()}})};this.toggleNavigation=function(show){if(show==true&&this.images.length>1){$('#bp .bp-nav').fadeIn(250)}else{$('#bp .bp-nav').hide()}return false};this.back=function(){this.index--;if(this.index<0){this.index=this.images.length-1}this.load()};this.next=function(){this.index++;if(this.index==this.images.length){this.index=0}this.load()};this.calculateOffset=function(){if(this.offset){return}var $view=$('#bp .bp-view');this.offset={x:0,y:0};this.offset.x=$view.outerWidth()-$view.width();this.offset.y=$view.outerHeight()-$view.height()}};$.fn.bigPicture=function(p){return this.each(function(){if(this.bigPicture instanceof $.jquery.ux.ui.BigPicture){return this}var box=new $.jquery.ux.ui.BigPicture(this,p);$(this).click(function(e){e.preventDefault();box.launchBox()});this.bigPicture=box;return this})}})(jQuery);