(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().insertAfter("#cboxInlineTemp");}}
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);data.title=data.title?data.title:this.title;data.href=data.href?data.href:this.href;data.rel=data.rel?data.rel:this.rel;$(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=$(this).data('colorbox');this.blur();callback=custom_callback?custom_callback:false;if(settings.rel&&settings.rel!='nofollow'){$related=$('.cboxelement').filter(function(){return($(this).data("colorbox").rel==settings.rel);});index=$related.index(this);}else{$related=$(this);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 false;}
$window.unbind('resize.cbox_resize');var speed=settings.transition=="none"?0:settings.speed;$loaded.remove();$loaded=$(object);function getWidth(){if(settings.width){return maxWidth;}else{return maxWidth&&maxWidth<$loaded.width()?maxWidth:$loaded.width();}}
function getHeight(){if(settings.height){return maxHeight;}else{return maxHeight&&maxHeight<$loaded.height()?maxHeight:$loaded.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=($loaded.height()-parseInt($('#cboxPhoto')[0].style.height,10))/2;$('#cboxPhoto').css({marginTop:(topMargin>0?topMargin:0)});}
function setPosition(s){var mWidth=$loaded.width()+loadedWidth+interfaceWidth;var mHeight=$loaded.height()+loadedHeight+interfaceHeight;$.fn.colorbox.position(mWidth,mHeight,s,function(){if(!open){return false;}
if($.browser.msie){if($('#cboxPhoto').length>0){$loaded.fadeIn(100);}
$modal.css('filter','');}
$modalContent.children().show();$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);$('#cboxIframe').attr('src',$('#cboxIframe').attr('src'));$.event.trigger('cbox_complete');if(callback){$(element).each(callback);}
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);});return true;});}
if(settings.transition=='fade'){$modal.fadeTo(speed,0,function(){setPosition(0);});}else{setPosition(speed);}
if(settings.preloading&&$related.length>1){var previous=index>0?$related[index-1]:$related[$related.length-1];var next=index<$related.length-1?$related[index+1]:$related[0];if(isImage($(next).data('colorbox').href)){$('<img />').attr('src',next);}
if(isImage($(previous).data('colorbox').href)){$('<img />').attr('src',previous);}}
return true;};$.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;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><iframe id='cboxIframe' name='iframe_"+new Date().getTime()+"' frameborder=0 src='"+href+"' /></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{if(href.match(/#[^#]+$/)){href=href.split("#")[0]+" ##"+href.split("#")[1];}
$('<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(){$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);
