/*
 *  La Boite v.1.1.0
 *  Copyright 2009, Gilles Cochez
 *  Released under the MIT, BSD, and GPL Licenses.
 *  More information: http://laboite.codeserenity.com/
 */
;(function($){var scope='laboite',ie=!$.support.opacity,ie6=ie&&!window.XMLHttpRequest,v={},e={},x={},t;x=$.fn.laboite=function(o){o=$.extend({},$.fn.laboite.defaults,o);if(this.nodeName&&'A'===this.nodeName.toUpperCase())var set=$(this);else var set=$(this).find('a');$.extend(o,{set:set,size:set.size(),parent:$(this)});set.each(function(){$(this).data(scope,$(this).data(scope)?$.extend({},$(this).data(scope),o):o);}).click(function(event){event.preventDefault();x.init($(this).blur());});if(o.autostart){setTimeout(function(){x.init(set.eq(0));},o.autostart_delay);};return this;};$.extend(x,{init:function(a){v=a.data(scope);if(!v.cache){v.set=v.parent.find('a').size()?v.parent.find('a'):v.parent;v.size=v.set.size();};$.extend(v,{key:v.set.index(a),controls:(v.size>1&&v.controls)?true:false,slideshow:(v.size>1&&v.slideshow)?true:false});if(v.controls){v.next=true;v.prev=true;}else{v.next=false;v.prev=false;};x.markup();x.pcn(a);x.win();v.on_init(e.viewer);x.load();},load:function(){var url=v.cur.attr('href'),captxt=v.cur.attr('title')||v.cur.find('img').eq(0).attr('alt')||'',ow=e.content.css('overflow','hidden').innerWidth(),oh=e.content.innerHeight();x.fade(x.center(e.loader.show()),1);if(x.isimg(url)){$(new Image()).load(function(){e.content.html($(this).load(function(){}).css('marginBottom',-3)).show();x.onload($(this),captxt,ow,oh);}).attr('src',url);}else if(x.isid(url)){e.content.append($(url).clone());x.onload(e.content.children().show(),captxt,ow,oh);}else if(v.iframe){$('<iframe>').hide().css({width:v.iframe_width,height:v.iframe_height}).load(function(){x.onload($(this).show(),captxt,ow,oh);}).attr('src',url).appendTo(e.content);}else{$('<div>').load(url,function(){e.content.append(this);x.onload(e.content.children(),captxt,ow,oh);});};},onload:function($e,captxt,ow,oh){e.loader.hide();if(v.caption)e.caption.text(captxt).show();if(v.stats)e.stats.text(v.stats_pattern.replace(':current',v.key+1).replace(':total',v.size)).show();var nw=$e.outerWidth(),nh=$e.outerHeight();if((nw!=ow)||(nh!=oh))x.resize(nw,nh,x.postload);else x.fade(e.content,1,x.postload);},postload:function(){e.viewer.find('*[id^="'+v.prefix+'"]').each(function(){var id=$(this).attr('id').replace(v.prefix,'');if(v[id]&&(!e[id].is(':visible')||e[id].css('opacity')<1))x.fade(e[id],1);});x.bindkeys();v.on_load(e.viewer);},bindkeys:function(){if(v.bind_keys){$(document).bind('keyup keypress',function(oe){if(!oe)var oe=window.event;var code=oe.keyCode||oe.which,str=String.fromCharCode(code);if(v.bind_escape&&code==27)x.close();if(v.bind_arrows){if(code==37&&v.prev)x.prev();else if(code==39&&v.next)x.next();};switch(str){case v.close_key:x.close();break;case v.next_key:if(v.next)x.next();break;case v.prev_key:if(v.prev)x.prev();break;case v.slide_key:if(v.slide)x.slide();break;case v.reset_key:if(v.reset)x.reset();break;};});};},unbindkeys:function(){$(document).unbind('keyup keypress');},resize:function(w,h,fn){e.content.animate({width:w,height:h},{easing:(v.easing&&$.easing.def)?v.easing:'linear',step:function(){x.center(e.viewer);},complete:function(){x.fade(e.content,1,fn);x.center(e.viewer);v.on_resize(e.viewer);}},v.resize_speed);},markup:function(){x.$('dim').click(v.bind_dim?x.close:false);x.$('viewer').append(x.$('stats'),x.$('caption'),x.$('next',x.next),x.$('prev',x.prev),x.$('close',x.close),x.$('reset',x.reset),x.$('slide',x.slide),x.$('loader'),x.$('content').show());$('body').append(e.dim,e.viewer);if(ie)e.viewer.addClass(v.prefix+'ie');if(ie6)x.ie6fix();x.center(e.viewer);x.fade(e.dim,v.dim_alpha);x.fade(e.viewer,v.viewer_alpha);},pcn:function($e){v.key=v.set.index($e);$.extend(v,{cur:v.set.eq(v.key),next:v.key+1<v.size?v.set.eq(v.key+1):false,prev:v.key-1>=0?v.set.eq(v.key-1):false});if(!v.continuous&&!v.next&&t)x.stop();if(v.continuous&&!v.next)v.next=v.set.eq(0);if(v.continuous&&!v.prev)v.prev=v.set.eq(v.size-1);},change:function(){x.unbindkeys();if(v.next||e.next.is(':visible'))x.fade(e.next,0,function(){e.next.hide();});if(v.prev||e.prev.is(':visible'))x.fade(e.prev,0,function(){e.prev.hide();});if(v.caption)x.fade(e.caption,0);if(v.close)x.fade(e.close,0);if(v.slide)x.fade(e.slide,0);if(v.reset)x.fade(e.reset,0);if(v.stats)x.fade(e.stats,0);x.fade(e.content,0,function(){e.content.empty();x.load(v.cur);});},next:function(){x.pcn(v.next);x.change();v.on_next(e.viewer);},prev:function(){x.pcn(v.prev);x.change();v.on_prev(e.viewer);},reset:function(){x.pcn(v.set.eq(0));x.change();},slide:function(){if(!t)x.play();else x.stop();},play:function(){t=setInterval(x.next,v.slide_delay);e.slide.text(v.slide_stop).addClass(v.prefix+'stop');},stop:function(){clearInterval(t);e.slide.text(v.slide_html).removeClass(v.prefix+'stop');t=false;},close:function(){x.fade(e.dim,0,function(){$(this).remove();});x.fade(e.viewer,0,function(){$(this).remove();});$(window).unbind('resize scroll');v.on_close();},center:function($e){var opt={position:'absolute'};if(e.viewer===$e){if(v.viewer_x)opt.top=(($(window).height()-$e.outerHeight())/2)+$(document).scrollTop();if(v.viewer_y)opt.left=(($(window).width()-$e.outerWidth())/2)+$(document).scrollLeft();}else{if(v.loader_x)opt.top=(e.viewer.innerHeight()-$e.outerHeight())/2;if(v.loader_y)opt.left=(e.viewer.innerWidth()-$e.outerWidth())/2;};return $e.css(opt);},win:function(){$(window).bind('resize scroll',function(){if(ie6)x.ie6fix();x.center(e.viewer);x.center(e.loader);});},fade:function($e,alpha,fn){if(alpha==0)return $e.fadeTo(v.fade_speed,0,fn);else return $e.show().fadeTo(v.fade_speed,alpha,fn);},ie6fix:function(){e.dim.css({position:'absolute',width:$(window).width(),height:$(window).height(),top:$(window).scrollTop(),left:$(window).scrollLeft()});},isimg:function(str){return v.image||str.match(/([^\s]+(\.(jpg|png|gif|bmp))$)/i);},isid:function(str){return'#'===str.substring(0,1);},$:function(id,clk){if('undefined'===typeof v[id]||v[id])return e[id]=$(document.createElement('div')).attr('id',v.prefix+id).css({opacity:0,display:'none'}).html(v[id+'_html']||'').click('function'==typeof clk?clk:function(){}).hover(!v.hover_class?function(){}:function(){$(this).addClass(v.prefix+'hover');},!v.hover_class?function(){}:function(){$(this).removeClass(v.prefix+'hover');});}});$.fn.laboite.defaults={prefix:'laboite-',cache:true,continuous:false,autostart:false,autostart_delay:0,image:false,slide:false,slide_delay:3500,slide_html:'',slide_stop:'',slide_key:'s',fade_speed:300,resize_speed:600,dim_alpha:0.75,viewer_alpha:1,viewer_html:'',viewer_x:true,viewer_y:true,loader_html:'',loader_x:true,loader_y:true,stats:true,stats_pattern:'Item :current of :total',controls:true,next_html:'',next_key:'n',prev_html:'',prev_key:'p',reset:false,reset_html:'',reset_key:'r',close:true,close_html:'',close_key:'c',caption:true,iframe:false,iframe_width:'700px',iframe_height:'500px',bind_dim:false,bind_keys:true,bind_escape:true,bind_arrows:true,hover_class:false,on_init:function(viewer){},on_load:function(viewer){},on_resize:function(viewer){},on_prev:function(viewer){},on_next:function(viewer){},on_close:function(){},easing:''};})(jQuery);
