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