//ceebox
/*
 * CeeBox 2.0.1 jQuery Plugin (minimized version)
 * Requires jQuery 1.3.2 and swfobject.jquery.js plugin to work
 * Code hosted on GitHub (http://github.com/catcubed/ceebox) Please visit there for version history information
 * By Colin Fahrion (http://www.catcubed.com)
 * Inspiration for ceebox comes from Thickbox (http://jquery.com/demo/thickbox/) and Videobox (http://videobox-lb.sourceforge.net/)
 * However, along the upgrade path ceebox has morphed a long way from those roots.
 * Copyright (c) 2009 Colin Fahrion
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

(function(f){f.ceebox={version:"2.0.2"};f.fn.ceebox=function(t){t=f.extend({selector:f(this).selector},f.fn.ceebox.defaults,t);f(this).each(function(u){f.ceebox(this,u,t)});return this};f.fn.ceebox.defaults={html:true,image:true,video:true,modal:false,htmlGallery:true,imageGallery:true,videoGallery:true,videoWidth:false,videoHeight:false,videoRatio:"16:9",htmlWidth:false,htmlHeight:false,htmlRatio:false,imageWidth:false,imageHeight:false,animSpeed:"normal",easing:"swing",fadeOut:400,fadeIn:400,overlayColor:"#000",overlayOpacity:0.8,padding:15,borderWidth:"3px 3px 3px 3px",margin:150,onload:null,};f.fn.ceebox.ratios={"4:3":1.667,"3:2":1.5,"16:9":1.778,"1:1":1,square:1};f.fn.ceebox.relMatch={width:/\bwidth:[0-9]+\b/i,height:/\bheight:[0-9]+\b/i,modal:/\bmodal:true|false\b/i};f.ceebox=function(y,C,z){z=f.meta?f.extend({},z,f(y).data()):z;var v,B=[],u=0;(f(y).is("a[href],area[href],input[href]"))?v=f(y):v=f(y).children().andSelf().find("a[href],area[href],input[href]");var t={image:function(D,E){return(E.image)&&D.match(/\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/i)||false},video:function(D,E){return(E.video)&&D.match(j)||false},html:function(D,E){return(E.html)}};v.each(function(E){var D=this;f.each(t,function(G){if(t[G](f(D).attr("href"),z)){var F=D;z=f.meta?f.extend({},z,f(F).data()):z;if(z.htmlGallery==true&&G=="html"){B[u]=E;u++}if(z.imageGallery==true&&G=="image"){B[u]=E;u++}if(z.videoGallery==true&&G=="video"){B[u]=E;u++}f(F).unbind("click").bind("click",function(I){I.preventDefault();I.stopPropagation();f.fn.ceebox.overlay();if(G=="image"){var H=new Image();H.onload=function(){var J=H.width,K=H.height;z.imageWidth=d(J,f.fn.ceebox.defaults.imageWidth);z.imageHeight=d(K,f.fn.ceebox.defaults.imageHeight);z.imageRatio=J/K;f.fn.ceebox.popup(F,f.extend(z,{type:G}))};H.src=f(F).attr("href")}else{f.fn.ceebox.popup(F,f.extend(z,{type:G}))}});return false}})});var A=B.length;f.each(B,function(F){var E=v[B[F]];if(A>1){var D={parentId:C,cbId:F,cbLen:A};if(F>0){D.prevId=B[F-1]}if(F<A-1){D.nextId=B[F+1]}f.data(E,"ceebox",D)}})};var e={image:function(t,u){return(u.image)&&t.match(/\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/i)||false},video:function(t,u){return(u.video)&&t.match(j)||false},html:function(t,u){return(u.html)}};f.fn.ceebox.overlay=function(y){y=f.extend({width:60,height:30,type:"html"},f.fn.ceebox.defaults,y);var u,t,v=(y.borderWidth.match(/[0-9]+/g));if(v.length=1){t=u=Number(v)}else{if((v.length=4)){t=Number(v[0]);u=Number(v[3])}}var A=parseInt(-1*((y.width)/2+u),10);var z=parseInt(-1*((y.height)/2+t),10);var C="fixed";if(typeof document.body.style.maxHeight==="undefined"){if(f("#cee_HideSelect")===null){f("body").append("<iframe id='cb.HideSelect'></iframe>")}var C="absolute";var B=document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop;z=z+parseInt((B),10)}if(f("#cee_overlay").size()==0){f("<div id='cee_overlay'></div>").css({opacity:y.overlayOpacity,position:"absolute",top:0,left:0,backgroundColor:y.overlayColor,width:"100%",height:f(document).height(),zIndex:100}).appendTo(f("body")).click(function(D){m(y);return false})}if(f("#cee_box").size()==0){f("<div id='cee_box'></div>").addClass("cee_"+y.type).css({position:C,zIndex:102,top:"50%",left:"50%",height:y.height+"px",width:y.width+"px",marginLeft:A+"px",marginTop:z+"px",opacity:0,borderWidth:y.borderWidth}).appendTo("body").animate({height:y.height+"px",width:y.width+"px",opacity:1},y.animSpeed);f("<div id='cee_load'></div>").css({zIndex:105,top:"50%",left:"50%",position:"fixed"}).appendTo("body")}else{f("#cee_box").removeClass().addClass("cee_"+y.type)}f("#cee_load").show("fast").animate({opacity:1},"fast");this.top=z;this.left=A;return this};f.fn.ceebox.popup=function(A,z){z=f.extend({width:k(z.margin).width,height:k(z.margin).height,titleHeight:40,modal:false,type:"html",onload:null},f.fn.ceebox.defaults,z);var u,y;if(f(A).is("a,area,input")&&(z.type=="html"||z.type=="image"||z.type=="video")){u=f.data(A,"ceebox");if(u){y=f(z.selector).eq(u.parentId).contents().andSelf().find("[href]")}i.prototype=new s[z.type](z);g.prototype=new i(A,z);p[z.type].prototype=new g();var t=new p[z.type];A=t.content;z.action=t.action;z.modal=t.modal;z.titleHeight=f(t.titlebox).contents().contents().wrap("<div></div>").parent().attr("id","ceetitletest").css({position:"absolute",top:"-300px",width:t.width+"px"}).appendTo("body").height();f("#ceetitletest").remove();z.titleHeight=(z.titleHeight>=10)?z.titleHeight+20:30;z.width=t.width+2*z.padding;z.height=t.height+z.titleHeight+2*z.padding}var B=f.fn.ceebox.overlay(z);if(f("#cee_load").size()==0){f("<div id='cee_load'></div>").css({zIndex:105,top:"50%",left:"50%",position:"fixed"}).appendTo("body").show("fast")}function v(){f("#cee_load").hide(300).fadeOut(600);if(c(z.action)){z.action()}if(c(z.onload)){z.onload()}}f("#cee_box").animate({marginLeft:B.left,marginTop:B.top,width:z.width+"px",height:z.height+"px"},z.animSpeed,z.easing,function(){var D=f(this).append(A).children().hide();var C=D.length;D.fadeIn(z.fadeIn,function(){if(f(this).is("iframe")){f(this).load(function(){v()});var E=true}if(!E&&this==D[C-1]){v()}});if(z.modal==true){f("#cee_overlay").unbind()}else{f("<a href='#' id='cee_closeBtn' title='Close'>close</a>").prependTo("#cee_box").one("click",function(E){m(z);return false});if(u){n(u,y,z)}l(u,y,z)}});f(".cee_close").live("click",function(C){C.preventDefault();f(".cee_close").die();m(z)})};var s={image:function(t){this.width=t.imageWidth;this.height=t.imageHeight;this.ratio=t.imageRatio;return this},video:function(t){this.width=t.videoWidth;this.height=t.videoHeight;this.ratio=t.videoRatio;return this},html:function(t){this.width=t.htmlWidth;this.height=t.htmlHeight;this.ratio=t.htmlRatio;return this}};var i=function(v,z){this.rel=f(v).attr("rel");this.href=f(v).attr("href");this.title=f(v).attr("title");this.titlebox="<div id='cee_title'><h2>"+this.title+"</h2></div>";this.margin=z.margin;this.modal=z.modal;var u=this.rel;if(u&&u!=""){var t=[String(u.match(f.fn.ceebox.relMatch.modal)),String(u.match(f.fn.ceebox.relMatch.width)),String(u.match(f.fn.ceebox.relMatch.height))];if(t[0]){var y=t[0].match(/true|false/i)}if(y=="true"){this.modal=true}if(y=="false"){this.modal=false}if(t[1]){this.width=Number(t[1].match(/[0-9]+\b/))}if(t[2]){this.height=Number(t[2].match(/[0-9]+\b/))}}return this};var g=function(){var t=k(this.margin);w=d(this.width,t.width);h=d(this.height,t.height);r=this.ratio;if(r){if(!Number(r)){f.each(f.fn.ceebox.ratios,function(u,v){if(r==u){r=v;return false}});r=Number(r)||1}if(w/h>r){w=parseInt(h*r,10)}if(w/h<r){h=parseInt(w/r,10)}}this.width=w;this.height=h;return this};var k=function(t){var u=document.documentElement;t=t||100;this.width=(window.innerWidth||self.innerWidth||(u&&u.clientWidth)||document.body.clientWidth)-t;this.height=(window.innerHeight||self.innerHeight||(u&&u.clientHeight)||document.body.clientHeight)-t;this.ratio=this.width/this.height;return this};var p={image:function(){this.type="image";this.content="<img id='cee_img' src='"+this.href+"' width='"+this.width+"' height='"+this.height+"' alt='"+this.title+"'/>"+this.titlebox;return this},video:function(){var A=o(this.href,this.title,this.rel);var v=A.src;var z=A.params;var y=A.flashvars;var t=this.width;var u=this.height;this.type="video";this.action=function(){f("#cee_vid").flash({swf:v,params:z,flashvars:y,width:t,height:u})};this.content="<div id='cee_vid' style='width:"+this.width+"px;height:"+this.height+"px'></div>"+this.titlebox;return this},html:function(){var v=this.href,y=this.rel;var u=[v.match(/\w+\.com/i),v.match(/^http:+/),(y)?y.match(/^iframe/):false];this.type="html";if((document.domain==u[0]&&u[1]&&!u[2])||(!u[1]&&!u[2])){var t=v;if(v.match(/#[a-z_A-Z1-9]+/)){t=v.split("#")[0];t=String(t+" "+v.match(/#[a-z_A-Z1-9\-]+/))}this.action=function(){f("#cee_ajax").load(t)};this.content=this.titlebox+"<div id='cee_ajax' style='width:"+(this.width-30)+"px;height:"+(this.height-20)+"px'></div>"}else{f("#cee_iframe").remove();this.content=this.titlebox+"<iframe frameborder='0' hspace='0' src='"+v+"' id='cee_iframeContent' name='cee_iframeContent"+Math.round(Math.random()*1000)+"'  style='width:"+(this.width)+"px;height:"+(this.height)+"px;' > </iframe>"}return this}};var j=/youtube\.com\/watch|metacafe\.com\/watch|google\.com\/videoplay|ifilm\.com\/video|vimeo\.com|dailymotion\.com|facebook\.com\/video|\.swf$/i;function o(z,v,A){var u=String(String(z.match(/\w+\.com/i)).match(/\w+/i));var y,C,B;C={wmode:"transparent",allowFullScreen:"true",allowScriptAccess:"always"};B={autoplay:true};y=String(z.match(/http:\/\/[a-zA-Z\.]+\.com/));switch(u){case"facebook":y=y+"/v/"+z.split("v=")[1].split("&")[0];C=f.extend({movie:y},C);break;case"youtube":y=y+"/v/"+z.split("v=")[1].split("&")[0]+"&hl=en&fs=1&autoplay=1";break;case"metacafe":y=y+"/fplayer/"+z.split("id=")[1].split("&")[0]+"/.swf";break;case"google":y=y+"/googleplayer.swf?docId="+z.split("id=")[1].split("&")[0]+"&hl=en";B=f.extend({playerMode:"normal",fs:true},B);break;case"ifilm":y=y+"/efp";B=f.extend({flvbaseclip:z.split("id=")[1].split("&")[0]+"&"});break;case"vimeo":y=y+"/moogaloop.swf?clip_id="+z.split("/")[3]+"&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1";break;case"dailymotion":y=y+"/swf/"+z.split("/")[4]+"&related=0&autoplay=1";break;default:y=z;break}this.src=y;this.params=C;this.flashvars=B;return this}function m(t){f("#cee_closeBtn").unbind();f("#cee_box").fadeOut(t.fadeOut,function(){f("#cee_box,#cee_overlay,#cee_HideSelect").unbind().trigger("unload").remove()});f("#cee_overlay").fadeOut(t.fadeOut*2);f("#cee_load").remove();document.onkeydown=null;document.onkeyup=null;return false}function l(v,t,u){document.onkeydown=function(z){z=z||window.event;var y=z.keyCode||z.which;switch(y){case 27:m(u);document.onkeydown=null;break;case 188:case 37:if(v&&v.prevId!=null){a(z,t,v.prevId,u)}break;case 190:case 39:if(v&&v.nextId!=null){a(z,t,v.nextId,u)}break}}}function n(B,y,A){var u=parseInt(A.width/2);var z=A.height-A.titleHeight-2*A.padding;var v=A.padding;var C=z/2;if(A.type=="video"||A.type=="html"){u=60;z=80;v=parseInt((A.height-A.titleHeight-2*A.padding-10)/2);C=24}if(A.type=="html"){v=parseInt((A.height-A.titleHeight-10)/2)}function t(E,I){var G,H=(C-2000)+"px",D=C+"px";(E=="prev")?G=[{left:0},"left"]:G=[{right:0},x="right"];var F=function(J){return f.extend({width:u+"px",height:z+"px",position:"absolute",top:v},G[0],{backgroundPosition:G[1]+" "+J})};f("<a href='#'></a>").text(E).attr("id","cee_"+E).css(F(H)).hover(function(){f(this).css(F(D))},function(){f(this).css(F(H))}).one("click",function(J){a(J,y,I,A)}).appendTo("#cee_box")}if(B.prevId!=null){t("prev",B.prevId)}if(B.nextId){t("next",B.nextId)}f("#cee_title").append("<div id='cee_count'>Item "+(B.cbId+1)+" of "+B.cbLen+"</div>")}function a(v,u,y,t){v.preventDefault();f("#cee_box").children().fadeOut(t.fadeOut,function(){f(this).remove();if(f(this).is("[id=cee_title]")){u.eq(y).trigger("click")}})}function d(u,t){return((u&&u<t)||!t)?u:t}function q(t){return(typeof t=="object"&&t)||c(t)}function c(t){return typeof t=="function"}function b(u,t,v){if(debugging==true){var z,y="[ceebox]("+(t||"")+")";(f.isArray(u)||q(u))?f.each(u,function(A,B){z=z+A+":"+B+", "}):z=u;if(window.console&&window.console.log){window.console.log(y+z)}else{if(f("#debug").size()==0){f("<ul id='debug'></ul>").appendTo("body").css({border:"1px solid #ccf",position:"fixed",top:"10px",right:"10px",width:"300px",padding:"10px",listStyle:"square"})}f("<li>").css({margin:"0 0 5px"}).appendTo("#debug").append(y).wrapInner("<b></b>").append(" "+z)}}}})(jQuery);
