//ceebox
/*
 * CeeBox 2.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(b){function z(c,a,d){m=new (function(){var f="";b.each(b.fn.ceebox.videos,function(e,g){if(g.siteRgx!=null&&typeof g.siteRgx!="string"){e=String(g.siteRgx);f=f+e.slice(1,e.length-2)+"|"}});this.vidRegex=new RegExp(f+"\\.swf$","i")});m.userAgent=navigator.userAgent;b(".cee_close").die().live("click",function(){b.fn.ceebox.closebox();return false});b(c).contents().is("html")||b(c).each(function(f){ceeboxLinkSort(this,f,a,d)});b(c).live("click",function(f){var e=b(f.target).closest("[href]"),
g=e.data("ceebox");if(g){var i=g.opts?b.extend({},a,g.opts):a;b.fn.ceebox.overlay(i);if(g.type=="image"){var j=new Image;j.onload=function(){var k=j.width,l=j.height;i.imageWidth=t(k,b.fn.ceebox.defaults.imageWidth);i.imageHeight=t(l,b.fn.ceebox.defaults.imageHeight);i.imageRatio=k/l;b.fn.ceebox.popup(e,b.extend(i,{type:g.type},{gallery:g.gallery}))};j.src=b(e).attr("href")}else b.fn.ceebox.popup(e,b.extend(i,{type:g.type},{gallery:g.gallery}));return false}})}function A(c,a){c=c.match(a);a=[];var d=
c.length;if(d>1){a[0]=c[0];a[1]=c[1];a[2]=d==2?c[0]:c[2];a[3]=d==4?c[3]:c[1]}else a=[c,c,c,c];return a}function E(c,a,d){document.onkeydown=function(f){f=f||window.event;switch(f.keyCode||f.which){case 13:return false;case 27:b.fn.ceebox.closebox(d);document.onkeydown=null;break;case 188:case 37:c&&c.prevId!=null&&v(a,c.prevId,d);break;case 190:case 39:c&&c.nextId!=null&&v(a,c.nextId,d);break}}}function F(c,a,d){function f(l,n){var o,s=j,p=s-2E3;l=="prev"?(o=[{left:0},"left"]):(o=[{right:0},x="right"]);
var q=function(y){return b.extend({zIndex:105,width:e+k,height:g+k,position:"absolute",top:i,backgroundPosition:o[1]+" "+y+k},o[0])};b("<a href='#'></a>").text(l).attr({id:"cee_"+l}).css(q(p)).hover(function(){b(this).css(q(s))},function(){b(this).css(q(p))}).one("click",function(y){y.preventDefault();v(a,n,d.fadeOut)}).appendTo("#cee_box")}var e=parseInt(d.width/2),g=d.height-d.titleHeight-2*d.padding,i=d.padding,j=g/2,k="px";if(d.type=="video"||d.type=="html"){e=60;g=80;i=parseInt((d.height-d.titleHeight-
10)/2);j=24}if(d.type=="video")i=parseInt((i*2-2*d.padding)/2);c.prevId!=null&&f("prev",c.prevId);c.nextId&&f("next",c.nextId);b("#cee_title").append("<div id='cee_count'>Item "+(c.gNum+1)+" of "+c.gLen+"</div>")}function v(c,a,d){b("#cee_prev,#cee_next").unbind().click(function(){return false});document.onkeydown=null;var f=b("#cee_box").children(),e=f.length;f.fadeOut(d,function(){b(this).remove();this==f[e-1]&&c.eq(a).trigger("click")})}function t(c,a){return c&&c<a||!a?c:a}function u(c){return typeof c==
"function"}function r(c){var a=c.length;return a>1?c[a-1]:c}b.ceebox={version:"2.1"};b.fn.ceebox=function(c){c=b.extend({selector:b(this).selector},b.fn.ceebox.defaults,c);var a=this,d=b(this).selector;c.videoJSON?b.getJSON(c.videoJSON,function(f){b.extend(b.fn.ceebox.videos,f);z(a,c,d)}):z(a,c,d);return this};b.fn.ceebox.defaults={html:true,image:true,video:true,modal:false,titles:true,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:"",textColor:"",borderColor:"",borderWidth:"3px",padding:15,margin:150,onload:null,unload:null,videoJSON:null,iPhoneRedirect:true};b.fn.ceebox.ratios={"4:3":1.333,"3:2":1.5,"16:9":1.778,"1:1":1,square:1};b.fn.ceebox.relMatch={width:/(?:width:)([0-9]+)/i,height:/(?:height:)([0-9]+)/i,ratio:/(?:ratio:)([0-9\.:]+)/i,modal:/modal:true/i,
nonmodal:/modal:false/i,videoSrc:/(?:videoSrc:)(http:[\/\-\._0-9a-zA-Z:]+)/i,videoId:/(?:videoId:)([\-\._0-9a-zA-Z:]+)/i};b.fn.ceebox.loader="<div id='cee_load' style='z-index:105;top:50%;left:50%;position:fixed'></div>";b.fn.ceebox.videos={base:{param:{wmode:"transparent",allowFullScreen:"true",allowScriptAccess:"always"},flashvars:{autoplay:true}},facebook:{siteRgx:/facebook\.com\/video/i,idRgx:/(?:v=)([a-zA-Z0-9_]+)/i,src:"http://www.facebook.com/v/[id]"},youtube:{siteRgx:/youtube\.com\/watch/i,
idRgx:/(?:v=)([a-zA-Z0-9_\-]+)/i,src:"http://www.youtube.com/v/[id]&hl=en&fs=1&autoplay=1"},metacafe:{siteRgx:/metacafe\.com\/watch/i,idRgx:/(?:watch\/)([a-zA-Z0-9_]+)/i,src:"http://www.metacafe.com/fplayer/[id]/.swf"},google:{siteRgx:/google\.com\/videoplay/i,idRgx:/(?:id=)([a-zA-Z0-9_\-]+)/i,src:"http://video.google.com/googleplayer.swf?docId=[id]&hl=en&fs=true",flashvars:{playerMode:"normal",fs:true}},spike:{siteRgx:/spike\.com\/video|ifilm\.com\/video/i,idRgx:/(?:\/)([0-9]+)/i,src:"http://www.spike.com/efp",
flashvars:{flvbaseclip:"[id]"}},vimeo:{siteRgx:/vimeo\.com\/[0-9]+/i,idRgx:/(?:\.com\/)([a-zA-Z0-9_]+)/i,src:"http://www.vimeo.com/moogaloop.swf?clip_id=[id]&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1"},dailymotion:{siteRgx:/dailymotion\.com\/video/i,idRgx:/(?:video\/)([a-zA-Z0-9_]+)/i,src:"http://www.dailymotion.com/swf/[id]&related=0&autoplay=1"},cnn:{siteRgx:/cnn\.com\/video/i,idRgx:/(?:\?\/video\/)([a-zA-Z0-9_\/\.]+)/i,src:"http://i.cdn.turner.com/cnn/.element/apps/cvp/3.0/swf/cnn_416x234_embed.swf?context=embed&videoId=[id]",
width:416,height:374}};b.fn.ceebox.overlay=function(c){c=b.extend({width:60,height:30,type:"html"},b.fn.ceebox.defaults,c);b("#cee_overlay").size()==0&&b("<div id='cee_overlay'></div>").css({opacity:c.overlayOpacity,position:"absolute",top:0,left:0,backgroundColor:c.overlayColor,width:"100%",height:b(document).height(),zIndex:100}).appendTo(b("body"));if(b("#cee_box").size()==0){var a=B(c);a={position:a.position,zIndex:102,top:"50%",left:"50%",height:c.height+"px",width:c.width+"px",marginLeft:a.mleft+
"px",marginTop:a.mtop+"px",opacity:0,borderWidth:c.borderWidth,borderColor:c.borderColor,backgroundColor:c.boxColor,color:c.textColor};b("<div id='cee_box'></div>").css(a).appendTo("body").animate({opacity:1},c.animSpeed,function(){b("#cee_overlay").addClass("cee_close")})}b("#cee_box").removeClass().addClass("cee_"+c.type);b("#cee_load").size()==0&&b(b.fn.ceebox.loader).appendTo("body");b("#cee_load").show("fast").animate({opacity:1},"fast")};b.fn.ceebox.popup=function(c,a){var d=C(a.margin);a=b.extend({width:d.width,
height:d.height,modal:false,type:"html",onload:null},b.fn.ceebox.defaults,a);var f,e;if(b(c).is("a,area,input")&&(a.type=="html"||a.type=="image"||a.type=="video")){if(a.gallery)e=b(a.selector).eq(a.gallery.parentId).find("a[href],area[href],input[href]");D[a.type].prototype=new G(c,a);d=new D[a.type];c=d.content;a.action=d.action;a.modal=d.modal;if(a.titles){a.titleHeight=b(d.titlebox).contents().contents().wrap("<div></div>").parent().attr("id","ceetitletest").css({position:"absolute",top:"-300px",
width:d.width+"px"}).appendTo("body").height();b("#ceetitletest").remove();a.titleHeight=a.titleHeight>=10?a.titleHeight+20:30}else a.titleHeight=0;a.width=d.width+2*a.padding;a.height=d.height+a.titleHeight+2*a.padding}b.fn.ceebox.overlay(a);m.action=a.action;m.onload=a.onload;m.unload=a.unload;d=B(a);d={marginLeft:d.mleft,marginTop:d.mtop,width:a.width+"px",height:a.height+"px",borderWidth:a.borderWidth};if(a.borderColor){var g=A(a.borderColor,/#[1-90a-f]+/gi);d=b.extend(d,{borderTopColor:g[0],
borderRightColor:g[1],borderBottomColor:g[2],borderLeftColor:g[3]})}d=a.textColor?b.extend(d,{color:a.textColor}):d;d=a.boxColor?b.extend(d,{backgroundColor:a.boxColor}):d;b("#cee_box").animate(d,a.animSpeed,a.easing,function(){var i=b(this).append(c).children().hide(),j=i.length,k=true;i.fadeIn(a.fadeIn,function(){if(b(this).is("#cee_iframeContent"))k=false;k&&this==i[j-1]&&b.fn.ceebox.onload()});if(a.modal==true)b("#cee_overlay").removeClass("cee_close");else{b("<a href='#' id='cee_closeBtn' class='cee_close' title='Close'>close</a>").prependTo("#cee_box");
a.gallery&&F(a.gallery,e,a);E(f,e,a.fadeOut)}})};b.fn.ceebox.closebox=function(c,a){c=c||400;b("#cee_box").fadeOut(c);b("#cee_overlay").fadeOut(typeof c=="number"?c*2:"slow",function(){b("#cee_box,#cee_overlay,#cee_HideSelect,#cee_load").unbind().trigger("unload").remove();u(a)?a():u(m.unload)&&m.unload();m.unload=null});document.onkeydown=null};b.fn.ceebox.onload=function(){b("#cee_load").hide(300).fadeOut(600,function(){b(this).remove()});if(u(m.action)){m.action();m.action=null}if(u(m.onload)){m.onload();
m.onload=null}};var m;ceeboxLinkSort=function(c,a,d){var f,e=[],g=[],i=0;b(c).is("[href]")?(f=b(c)):(f=b(c).find("[href]"));var j={image:function(l){return l.match(/\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/i)||false},video:function(l,n){return n&&n.match(/^video$/i)?true:l.match(m.vidRegex)||false},html:function(){return true}};f.each(function(l){var n=this,o=b.metadata?b(n).metadata():false,s=o?b.extend({},d,o):d;b.each(j,function(p){if(j[p](b(n).attr("href"),b(n).attr("rel"))&&s[p]){var q=false;if(d.htmlGallery==
true&&p=="html"||d.imageGallery==true&&p=="image"||d.videoGallery==true&&p=="video"){g[g.length]=l;q=true}e[e.length]={linkObj:n,type:p,gallery:q,linkOpts:s};return false}})});var k=g.length;b.each(e,function(l){if(e[l].gallery){var n={parentId:a,gNum:i,gLen:k};if(i>0)n.prevId=g[i-1];if(i<k-1)n.nextId=g[i+1];i++}!b.support.opacity&&b(c).is("map")&&b(e[l].linkObj).click(function(o){o.preventDefault()});b.data(e[l].linkObj,"ceebox",{type:e[l].type,opts:e[l].linkOpts,gallery:n})})};var G=function(c,
a){var d=a.type,f={image:[a.imageWidth,a.imageHeight,a.imageRatio||a.imageWidth/a.imageHeight],video:[a.videoWidth,a.videoHeight,a.videoRatio],html:[a.htmlWidth,a.htmlHeight,a.htmlRatio]},e=f[d][0],g=f[d][1],i=f[d][2],j=b(c).attr("rel");if(j&&j!=""){var k={};b.each(b.fn.ceebox.relMatch,function(l,n){k[l]=n.exec(j)});if(k.modal)a.modal=true;if(k.nonmodal)a.modal=false;if(k.width)e=Number(r(k.width));if(k.height)g=Number(r(k.height));if(k.ratio){i=r(k.ratio);i=Number(i)?Number(i):String(i)}if(k.videoSrc)this.videoSrc=
String(r(k.videoSrc));if(k.videoId)this.videoId=String(r(k.videoId))}d=C(a.margin);e=t(e,d.width);g=t(g,d.height);if(i){if(!Number(i)){b.each(b.fn.ceebox.ratios,function(l,n){if(i==l){i=n;return false}});i=Number(i)||1}if(e/g>i)e=parseInt(g*i,10);if(e/g<i)g=parseInt(e/i,10)}this.modal=a.modal;this.href=b(c).attr("href");this.title=b(c).attr("title")||c.t||"";this.titlebox=a.titles?"<div id='cee_title'><h2>"+this.title+"</h2></div>":"";this.width=e;this.height=g;this.rel=j;this.iPhoneRedirect=a.iPhoneRedirect},
D={image:function(){this.content="<img id='cee_img' src='"+this.href+"' width='"+this.width+"' height='"+this.height+"' alt='"+this.title+"'/>"+this.titlebox},video:function(){var c="",a=new (function(f){var e=this,g=f.videoId;e.flashvars=e.param={};e.src=f.videoSrc||f.href;e.width=f.width;e.height=f.height;b.each(b.fn.ceebox.videos,function(i,j){if(j.siteRgx!=null&&typeof j.siteRgx!="string"&&j.siteRgx.test(f.href)){if(j.idRgx){j.idRgx=new RegExp(j.idRgx);g=String(r(j.idRgx.exec(f.href)))}e.src=
j.src?j.src.replace("[id]",g):e.src;j.flashvars&&b.each(j.flashvars,function(k,l){if(typeof l=="string")e.flashvars[k]=l.replace("[id]",g)});j.param&&b.each(j.param,function(k,l){if(typeof l=="string")e.param[k]=l.replace("[id]",g)});e.width=j.width||e.width;e.height=j.height||e.height;e.site=i}})})(this);if(b.flash.hasVersion(8)){this.width=a.width;this.height=a.height;this.action=function(){b("#cee_vid").flash({swf:a.src,params:b.extend(b.fn.ceebox.videos.base.param,a.param),flashvars:b.extend(b.fn.ceebox.videos.base.flashvars,
a.flashvars),width:a.width,height:a.height})}}else{this.width=400;this.height=200;if(m.userAgent.match(/iPhone/i)&&this.iPhoneRedirect||m.userAgent.match(/iPod/i)&&this.iPhoneRedirect){var d=this.href;this.action=function(){b.fn.ceebox.closebox(400,function(){window.location=d})}}else{a.site=a.site||"SWF file";c="<p style='margin:20px'>Adobe Flash 8 or higher is required to view this movie. You can either:</p><ul><li>Follow link to <a href='"+this.href+"'>"+a.site+" </a></li><li>or <a href='http://www.adobe.com/products/flashplayer/'>Install Flash</a></li><li> or <a href='#' class='cee_close'>Close This Popup</a></li></ul>"}}this.content=
"<div id='cee_vid' style='width:"+this.width+"px;height:"+this.height+"px;'>"+c+"</div>"+this.titlebox},html:function(){var c=this.href,a=this.rel;a=[c.match(/[a-zA-Z0-9_\.]+\.[a-zA-Z]{2,4}/i),c.match(/^http:+/),a?a.match(/^iframe/):false];if(document.domain==a[0]&&a[1]&&!a[2]||!a[1]&&!a[2]){var d,f=(d=c.match(/#[a-zA-Z0-9_\-]+/))?String(c.split("#")[0]+" "+d):c;this.action=function(){b("#cee_ajax").load(f)};this.content=this.titlebox+"<div id='cee_ajax' style='width:"+(this.width-30)+"px;height:"+
(this.height-20)+"px'></div>"}else{b("#cee_iframe").remove();this.content=this.titlebox+"<iframe frameborder='0' hspace='0' src='"+c+"' id='cee_iframeContent' name='cee_iframeContent"+Math.round(Math.random()*1E3)+"' onload='jQuery.fn.ceebox.onload()' style='width:"+this.width+"px;height:"+this.height+"px;' > </iframe>"}}},C=function(c){var a=document.documentElement;c=c||100;this.width=(window.innerWidth||self.innerWidth||a&&a.clientWidth||document.body.clientWidth)-c;this.height=(window.innerHeight||
self.innerHeight||a&&a.clientHeight||document.body.clientHeight)-c;return this},B=function(c){var a="fixed",d=0,f=A(c.borderWidth,/[0-9]+/g);if(!window.XMLHttpRequest){b("#cee_HideSelect")===null&&b("body").append("<iframe id='cee_HideSelect'></iframe>");a="absolute";d=parseInt(document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop,10)}this.mleft=parseInt(-1*(c.width/2+Number(f[3])),10);this.mtop=parseInt(-1*(c.height/2+Number(f[0])),10)+d;this.position=a;return this}})(jQuery);