/**
 * jQuery lightpop plugin
 * This jQuery plugin was inspired on jQuery lightBox plugin by Leandro Vieira Pinho (http://leandrovieira.com/projects/jquery/lightbox/)
 * @name jquery.lightpop-0.4.6.min.js
 * @author wokamoto - http://dogmap.jp
 * @version 0.4.6
 * @date May 22, 2008
 * @category jQuery plugin
 * @copyright (c) 2007-2008 wokamoto (dogmap.jp)
 * @license  Released under the GPL license (http://www.gnu.org/copyleft/gpl.html)
 * @example http://dogmap.jp/lightpop_sample/sample.html
 */
(function(A){A.fn.lightpop=function(S){S=A.extend({overlayBgColor:"#000",overlayOpacity:0.7,contentFrameType:"border",contentBorder:"none",boxBorderSize:6,containerBorderSize:10,containerResizeSpeed:"normal",contentBgColor:"#FFF",imageBox:"images/lightpop-box.gif",imageBorderL:"images/lightpop-border-l.gif",imageBorderR:"images/lightpop-border-r.gif",imageLoading:"images/lightpop-ico-loading.gif",imageBtnPrev:"images/lightpop-btn-prev.gif",imageBtnNext:"images/lightpop-btn-next.gif",imageBtnClose:"images/lightpop-btn-close.gif",imageBlank:"images/lightpop-blank.gif",imageBtnPrevWidth:63,imageBtnNextWidth:63,imageBtnCloseWidth:66,txtImage:null,txtOf:"of",setLinkToTitle:false,keyToClose:"c",keyToPrev:"p",keyToNext:"n",flvplayer:"mediaplayer.swf",iconAdd:true,imageMaxWidth:0,imageMaxHeight:0},S);var L=((/^border$/i).test(S.contentFrameType));var G=new Array();var D=new Array({type:"Image",match:function(W){return((/\.(jpe?g|gif|png|bmp)$/i).test(W))},set:function(W){M(G[W].href,(function(X){return function(){var Y=K(this.src,new Array(this.width,this.height),new Array(S.imageMaxWidth,S.imageMaxHeight));G[X]=A.extend(G[X],{content:'<img src="'+this.src.replace(/\?.*$/,"")+'" width="'+Y[0]+'" height="'+Y[1]+'" />',width:Y[0],height:Y[1],later:(A.browser.msie?250:100)});U(X)}})(W))},preload:function(W){M(G[W].href,(function(X){return function(){var Y=K(this.src,new Array(this.width,this.height),new Array(S.imageMaxWidth,S.imageMaxHeight));G[X]=A.extend(G[X],{content:'<img src="'+this.src.replace(/\?.*$/,"")+'" width="'+Y[0]+'" height="'+Y[1]+'" />',width:Y[0],height:Y[1],later:(A.browser.msie?250:100)})}})(W))}},{type:"Video",match:function(W){return((/\.(flv|swf|rm|mov|3gp|mp4|asf|avi|mpg|wmv)$/i).test(W))}},{type:"YouTube",match:function(W){return((/\.youtube\.com\/watch/i).test(W))}},{type:"metacafe",match:function(W){return((/\.metacafe\.com\/watch/i).test(W))}},{type:"LiveLeak",match:function(W){return((/\.liveleak\.com\/view/i).test(W))}},{type:"GoogleVideo",match:function(W){return((/video\.google\.com\/videoplay/i).test(W))}},{type:"IFILM",match:function(W){return((/\.ifilm\.com\/video/i).test(W))}},{type:"Dailymotion",match:function(W){return((/\.dailymotion\.com\/video/i).test(W))}},{type:"superdeluxe",match:function(W){return((/\.superdeluxe\.com\/sd/i).test(W))}},{type:"nicovideo",match:function(W){return((/\.nicovideo\.jp\/watch/i).test(W))}},{type:"Contents",match:function(W){return(RegExp(window.location.host,"i").test(W))},set:function(W){A.get(G[W].href,function(Z,X){var a=K(G[W].href);var Y='<div width="'+a[0]+'" height="'+a[1]+'">'+Z.replace(/[\r\n]/g,"").replace(/.*<body.*?>(.*?)<\/body>.*$/,"$1").replace(/<script.*?>.*<\/script>/g,"")+"</div>";G[W]=A.extend(G[W],{content:Y,width:a[0],height:a[1],later:500});U(W)})},preload:function(W){},content_css:{textAlign:"left",lineHeight:"1.2em"}});var C=function(X){M(S.imageBtnPrev,function(){S.imageBtnPrevWidth=(this.width>0?this.width:63);this.onload=function(){}});M(S.imageBtnNext,function(){S.imageBtnNextWidth=(this.width>0?this.width:63);this.onload=function(){}});M(S.imageBtnClose,function(){S.imageBtnCloseWidth=(this.width>0?this.width:66);this.onload=function(){}});if(!L){A.each(new Array(S.imageBox,S.imageBorderL,S.imageBorderR),function(){M(this)});S.contentBorder="none"}var Z=new Array();var Y=0;var W=window.location;G.length=0;X.filter("a").each(function(){var c=A(this);if(!(/^https?:/i).test(c.attr("href"))&&(/^https?:/i).test(W.protocol)){c.attr("href",((/^\//i).test(c.attr("href"))?W.protocol+"//"+W.hostname+"/"+c.attr("href"):W.href.replace(/^(.*\/).*$/i,"$1")+c.attr("href").replace(/^\/?(.*)$/i,"$1")))}for(var a=D[0],b=0;b<D.length;b++,a=D[b]){if(a.match(c.attr("href").replace(/\?.*$/,""))){if(S.iconAdd&&c.children("img").length==0){c.css({background:"transparent url("+(S["icon"+a.type]?S["icon"+a.type]:"images/icon-"+a.type.toLowerCase()+".png")+") no-repeat scroll 1px 0pt",paddingLeft:"20px"})}G.push({index:b,type:a.type,href:c.attr("href"),title:(c.attr("title")?c.attr("title"):c.html().replace(/<[^>]*>/ig,""))});c.unbind("click").click((function(d){return function(){N(d);return false}})(Y));Z.push(this);Y++;break}}});return new A(Z)};var N=function(Y){E(A("embed, object, select"),false);A("body").append(A('<div id="overlay" /><div id="lightpop"><div id="lightpop-box"><div id="lightpop-box-content">'+(L?'<div id="lightpop-content-box"><div id="lightpop-content" /></div></div><div id="lightpop-data-box"><div id="lightpop-data"><div id="lightpop-details"><div id="lightpop-details-caption" /><div id="lightpop-details-number" /></div><div id="lightpop-data-nav"><a href="#" id="lightpop-data-nav-close"><img src="'+S.imageBtnClose+'" /></a></div></div></div>':'<div id="lightpop-box-hd"><div id="lightpop-box-hdc" /></div><div id="lightpop-box-bd"><div id="lightpop-box-bdc"><div id="lightpop-content-box"><div id="lightpop-content" /></div><div id="lightpop-data-box"><div id="lightpop-data"><div id="lightpop-details"><div id="lightpop-details-caption" /><div id="lightpop-details-number" /></div><div id="lightpop-data-nav"><a href="#" id="lightpop-data-nav-close"><img src="'+S.imageBtnClose+'" /></a></div></div></div></div></div><div id="lightpop-box-ft"><div id="lightpop-box-ftc" /></div></div>')+'<div id="lightpop-nav"><a href="#" id="lightpop-nav-prev" /><a href="#" id="lightpop-nav-next" /></div><div id="lightpop-loading"><a href="#" id="lightpop-loading-link"><img src="'+S.imageLoading+'" /></a></div></div></div>').hide());var W=I();var X=Q();var Z=250;A("#overlay").css({position:"absolute",top:0,left:0,backgroundColor:S.overlayBgColor,opacity:S.overlayOpacity,width:W[0],height:W[1],zIndex:90});A("#lightpop").css({position:"absolute",top:X[1]+Math.round(W[3]/10),left:X[0],width:"100%",textAlign:"center",lineHeight:0,border:"none",zIndex:100});A("#lightpop a img").css({border:"none"});A("#lightpop-box").css({position:"relative",width:Z,height:Z,top:0,margin:"0 auto",padding:0,backgroundColor:S.contentBgColor,border:S.contentBorder,overflow:(L?"hidden":"visible")});A("#lightpop-content-box").css({backgroundColor:"transparent"});A("#lightpop-content").css({margin:(L?0:"0 auto"),padding:(L?0:S.containerBorderSize+"px 0")});A("#lightpop-box-content").css({position:"relative",width:Z,height:Z,backgroundColor:"transparent",margin:"0 auto",padding:(L?S.containerBorderSize:0),overflow:(L?"hidden":"visible")});if(!L){V(false).css({position:"relative"}).hide();A("#lightpop-box-hd").css({height:S.boxBorderSize,top:0,margin:"0 "+S.boxBorderSize+"px 0 0"});A("#lightpop-box-hdc").css({height:S.boxBorderSize,top:0,margin:"0 "+S.boxBorderSize*-1+"px 0 "+S.boxBorderSize+"px"});A("#lightpop-box-ft").css({height:S.boxBorderSize,bottom:0,margin:"0 "+S.boxBorderSize+"px 0 0"});A("#lightpop-box-ftc").css({height:S.boxBorderSize,bottom:0,margin:"0 "+S.boxBorderSize*-1+"px 0 "+S.boxBorderSize+"px"})}A("#lightpop-nav").css({position:"absolute",top:0,left:0,height:"10px",width:"100%",padding:0,margin:(L?"0":S.boxBorderSize+"px")+" auto",zIndex:10});A("#lightpop-nav a").css({display:"block",height:"100%",zoom:1,margin:(L?0:"0 "+S.boxBorderSize+"px"),outline:"none"});A("#lightpop-nav-prev").css({width:S.imageBtnPrevWidth,left:0,styleFloat:"left"});A("#lightpop-nav-next").css({width:S.imageBtnNextWidth,right:0,styleFloat:"right"});A("#lightpop-loading").css({position:"absolute",top:"40%",left:0,height:"20%",width:"100%",margin:"0 auto",textAlign:"center",lineHeight:0});A("#lightpop-data-box").css({font:"10px Verdana, Helvetica, sans-serif",backgroundColor:S.contentBgColor,lineHeight:"1.4em",width:"100%",margin:"0 auto",padding:"0 "+S.containerBorderSize+"px 0",overflow:"hidden"}).hide();A("#lightpop-data").css({position:"relative",padding:"0 "+S.containerBorderSize+"px",color:"#666",left:0,bottom:0});A("#lightpop-details").css({width:"70%",styleFloat:"left",textAlign:"left"});A("#lightpop-details-caption").css({styleFloat:"left","font-weight":"bold",width:"100%"});A("#lightpop-details-number").css({styleFloat:"left",clear:"left",width:"100%","padding-bottom":"1.0em"});A("#lightpop-data-nav-close").css({styleFloat:"right",width:S.imageBtnCloseWidth,"padding":"0.35em 0"});A("#overlay").click(B).fadeIn(S.containerResizeSpeed,function(){A("#lightpop").show()});A("#lightpop-loading-link, #lightpop-data-nav-close").click(function(){B();return false});R(true);H(Y)};var H=function(W){E(A("#lightpop-data, #lightpop-details, #lightpop-details-caption, #lightpop-details-number, #lightpop-data-nav-close"),false);A("#lightpop-nav, #lightpop-nav-prev, #lightpop-nav-next").hide();A("#lightpop-content").hide().children().remove();A("#lightpop-loading, #lightpop-box, #lightpop-box-content").show();V(false);if(!L&&A.browser.safari){A("#lightpop-data-box").height("auto")}U(W)};var U=function(W){(G[W].content?function(X){A("#lightpop-content").append(A(G[X].content));setTimeout(function(){T(X)},G[X].later)}:(D[G[W].index].set?D[G[W].index].set:(function(X){O(X);U(X)})))(W)};var T=function(Y){var X=G[Y].width+(S.containerBorderSize+(L?0:S.boxBorderSize))*2;var W=G[Y].height+S.containerBorderSize*2;A("#lightpop-box").animate({width:X,height:W},S.containerResizeSpeed,function(){var Z=G[Y];A("#lightpop-box-content").css({width:(L?Z.width:X),height:Z.height});A("#lightpop-content").css({width:Z.width,height:Z.height});A("#lightpop-data-box").css({width:Z.width});if(D[Z.index].content_css){A("#lightpop-content").children().css(D[Z.index].content_css)}A("#lightpop-loading").hide();if((/<object.*>/i).test(Z.content)){A("#lightpop-content").show()}else{A("#lightpop-content").fadeIn()}V(true);A("#lightpop-details-caption").html((S.setLinkToTitle?'<a href="'+Z.href+'" title="'+Z.title+'">'+Z.title+"</a>":Z.title));A("#lightpop-details-number").html((S.txtImage?S.txtImage:Z.type)+(G.length>1?" "+(Y+1)+" "+S.txtOf+" "+G.length:""));var a=E(A("#lightpop-data, #lightpop-details, #lightpop-details-caption, #lightpop-details-number, #lightpop-data-nav-close"),false).show();A("#lightpop-data-box").slideDown("fast",function(){var b=(!A.browser.safari?A(this).height():this.scrollHeight);b=(b<28?28:b);W+=b;(L?(function(c){A("#lightpop-box").animate({width:X,height:W},"fast",function(){E(c,true)})}):(function(c){if(A.browser.safari){A("#lightpop-data-box").height(b)}E(c,true)}))(a)});A("#lightpop-nav").css({width:X}).show(function(){A("#lightpop-nav-prev, #lightpop-nav-next").css({height:Math.round(W/3),background:"transparent url("+S.imageBlank+") no-repeat"}).unbind();if(Y!=0){A("#lightpop-nav-prev").hover(function(){A(this).css({background:"url("+S.imageBtnPrev+") left 30% no-repeat"})},function(){A(this).css({background:"transparent url("+S.imageBlank+") no-repeat"})}).show().click((function(b){return function(){H(b);return false}})(Y-1))}if(Y!=(G.length-1)){A("#lightpop-nav-next").hover(function(){A(this).css({background:"url("+S.imageBtnNext+") right 30% no-repeat"})},function(){A(this).css({background:"transparent url("+S.imageBlank+") no-repeat"})}).show().click((function(b){return function(){H(b);return false}})(Y+1))}F(true,Y)});if((G.length-1)>Y){J(Y+1)}if(Y>0){J(Y-1)}})};var J=function(W){if(!G[W].content){(D[G[W].index].preload?D[G[W].index].preload:(function(X){O(X)}))(W)}};var K=function(Y,X,c){var b=0,W=0;var Z=Y.toLowerCase().replace(/[\r\n]/g,"").replace(/["']/g,"").match(/(width|height)=(\d+)/ig);if(Z){A.each(Z,function(){if((/^width=\d+$/i).test(this)){b=Number(this.replace(/^width=(\d+)$/,"$1"))}if((/^height=\d+$/i).test(this)){W=Number(this.replace(/^height=(\d+)$/,"$1"))}})}if(b==0||W==0){if(X){b=X[0];W=X[1]}else{var a=I();b=a[0]/4;W=a[1]/4}}if(c){if(c[0]!=0&&b>c[0]){W=W*(c[0]/b);b=c[0]}if(c[1]!=0&&W>c[1]){b=b*(c[1]/W);W=c[1]}}return new Array(Math.round(b),Math.round(W))};var O=function(e){var X=G[e];var a=X.href.replace(/&.*$/i,"");var W,Y,d,Z=null,c=1500;var b=X.href.replace(/^.*\?/,"").split("&");Y={};switch(X.type){case"YouTube":W=K(X.href,new Array(425,355));d=a.replace(/^.*\.youtube.*watch.*?v=(.*)$/i,"$1");a="http://www.youtube.com/v/"+d;Z=P(a,W[0],W[1],Y);break;case"metacafe":W=K(X.href,new Array(400,345));d=a.replace(/\?.*$/,"").replace(/\/$/i,"").replace(/^.*\.metacafe.*watch\/(.*)$/i,"$1");a="http://www.metacafe.com/fplayer/"+d+".swf";Z=P(a,W[0],W[1],Y);break;case"LiveLeak":W=K(X.href,new Array(450,370));d=a.replace(/^.*\.liveleak.*view.*?i=(.*)$/i,"$1");a="http://www.liveleak.com/player.swf?autostart=false&token="+d;Y={quality:"high"};Z=P(a,W[0],W[1],Y);break;case"GoogleVideo":W=K(X.href,new Array(400,326));d=a.replace(/^.*video\.google\.com\/videoplay.*docid=(.*)$/i,"$1");a="http://video.google.com/googleplayer.swf?docId="+d+"&#038;hl=en";Y={flashvars:""};Z=P(a,W[0],W[1],Y);break;case"IFILM":W=K(X.href,new Array(448,365));d=a.replace(/\?.*$/,"").replace(/\/$/i,"").replace(/^.*\.ifilm\.com.*video\/(.*)$/i,"$1");a="http://www.ifilm.com/efp";Y={flashvars:"flvbaseclip="+d+"&",quality:"high",bgcolor:"000000"};Z=P(a,W[0],W[1],Y);break;case"Dailymotion":W=K(X.href,new Array(420,330));d=a.replace(/^.*\.dailymotion\.com\/video\/([^_]*).*$/i,"$1");a="http://www.dailymotion.com/swf/"+d;Y={allowFullScreen:"true",allowScriptAccess:"always"};Z=P(a,W[0],W[1],Y);break;case"superdeluxe":W=K(X.href,new Array(400,350));d=a.replace(/^.*\.superdeluxe\.com\/sd\/contentDetail\.do\?id=(.*)$/i,"$1");a="http://www.superdeluxe.com/static/swf/share_vidplayer.swf";Y={allowFullScreen:"true",quality:"high",FlashVars:"id="+d};Z=P(a,W[0],W[1],Y);break;case"nicovideo":W=K(X.href,new Array(312,176));d=a.replace(/^.*\.nicovideo\.jp\/watch\/(.*)$/i,"$1");Z='<iframe width="'+W[0]+'" height="'+W[1]+'" src="http://www.nicovideo.jp/thumb/'+d+'" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"><a href="http://www.nicovideo.jp/watch/'+d+'">'+X.tytle+"</iframe>";c=500;break;case"Video":W=K(X.href,new Array(320,240));a=a.replace(/\?.*$/,"");switch(a.toLowerCase().match(/\.(flv|swf|rm|mov|3gp|mp4|asf|avi|mpg|wmv)$/i)[1]){case"flv":W[1]+=22;a=S.flvplayer+"?file="+a;A.each(b,function(){if(!(/^(width|height)=/i).test(this)){a+="&amp;"+this}});case"swf":Y=A.extend({quality:"high",bgcolor:"#000"},Y);Z=P(a,W[0],W[1],Y);break;case"rm":Z='<object classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" width="'+W[0]+'" height="'+W[1]+'"><param name="src" value="'+a+'" /><param name="autostart" value="true" /><param name="controls" value="imagewindow,controlpanel" /><embed src="'+a+'" width="'+W[0]+'" height="'+W[1]+'" autostart="true" controls="imagewindow,controlpanel" type="audio/x-pn-realaudio-plugin"></embed></object>';break;case"mov":case"mp4":case"3gp":W[1]+=20;Z='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+W[0]+'" height="'+W[1]+'"><param name="src" value="'+a+'" /><param name="href" value="'+a+'" /><param name="controller" value="true" /><param name="pluginspage" value="http://www.apple.com/quicktime/download/" /><param name="autoplay" value="true" /><param name="bgcolor" value="000000" /><embed src="'+a+'" width="'+W[0]+'" height="'+W[1]+'" bgcolor="000000" autoplay="true" controller="true" src="'+a+'" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';break;default:W[1]+=20;Z='<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'+W[0]+'" height="'+W[1]+'" type="application/x-oleobject"><param name="url" value="'+a+'" /><param name="autostart" value="true" /><param name="uiMode" value="full" /><embed src="'+a+'" width="'+W[0]+'" height="'+W[1]+'" autostart="true" uiMode="full" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/"></embed></object>';break}c=1000;break}if(Z){G[e]=A.extend(X,{content:Z,width:W[0],height:W[1],later:c})}};var P=function(X,Z,W,a){a=A.extend({movie:X,wmode:"transparent"},a);var Y='<object data="'+X+'" type="application/x-shockwave-flash" width="'+Z+'" height="'+W+'" wmode="'+a.wmode+'">';A.each(a,function(b){Y+='<param name="'+b+'" value="'+this+'" />'});Y+="</object>";return Y};var V=function(Z){if(!L){var Y=A("#lightpop-box-hd, #lightpop-box-hdc, #lightpop-box-bd, #lightpop-box-bdc, #lightpop-box-ft, #lightpop-box-ftc");var X="transparent",W=S.contentBgColor;if(Z){A("#lightpop-box").css({backgroundColor:X});A("#lightpop-box-hd").css({background:X+" url("+S.imageBox+") left top no-repeat"});A("#lightpop-box-hdc").css({background:X+" url("+S.imageBox+") right top no-repeat"});A("#lightpop-box-bd").css({background:W+" url("+S.imageBorderL+") left top repeat-y"});A("#lightpop-box-bdc").css({background:X+" url("+S.imageBorderR+") right top repeat-y"});A("#lightpop-box-ft").css({background:X+" url("+S.imageBox+") left bottom no-repeat"});A("#lightpop-box-ftc").css({background:X+" url("+S.imageBox+") right bottom no-repeat"});Y.show()}else{A("#lightpop-box").css({backgroundColor:W});Y.css({background:X})}return Y}};var M=function(X,Y){var W=new Image();if(Y){W.onload=Y}W.src=X;return W};var E=function(X,W){return X.css({visibility:(W?"visible":"hidden")})};var F=function(W,X){A(document).unbind("keydown");if(W){A(document).keydown(function(a){var b,Y,Z;if(!a){Y=event.keyCode;Z=27}else{Y=a.keyCode;Z=a.DOM_VK_ESCAPE}b=String.fromCharCode(Y).toLowerCase();if((b==S.keyToClose)||(b=="x")||(Y==Z)){B()}else{if(((b==S.keyToPrev)||(Y==37))&&X!=0){H(X-1)}else{if(((b==S.keyToNext)||(Y==39))&&X!=(G.length-1)){H(X+1)}}}})}};var R=function(W){A(window).unbind("resize");if(W){A(window).resize(function(){var X=I();var Y=Q();A("#overlay").css({width:X[0],height:X[1]});A("#lightpop").css({top:Y[1]+Math.round(X[3]/10),left:Y[0]})})}};var I=function(){var a,W,Y,b,Z,X;if(window.innerHeight&&window.scrollMaxY){a=window.innerWidth+window.scrollMaxX;W=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){a=document.body.scrollWidth;W=document.body.scrollHeight}else{a=document.body.offsetWidth;W=document.body.offsetHeight}}if(self.innerHeight){if(document.documentElement.clientWidth){Y=document.documentElement.clientWidth}else{Y=self.innerWidth}b=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){Y=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else{if(document.body){Y=document.body.clientWidth;b=document.body.clientHeight}}}X=(a<Y?a:Y);Z=(W<b?b:W);return new Array(X,Z,Y,b)};var Q=function(){var X,W;if(self.pageYOffset){W=self.pageYOffset;X=self.pageXOffset}else{if(document.documentElement&&document.documentElement.scrollTop){W=document.documentElement.scrollTop;X=document.documentElement.scrollLeft}else{if(document.body){W=document.body.scrollTop;X=document.body.scrollLeft}}}return new Array(X,W)};var B=function(){E(A("object",A("#lightpop")),false).remove();A("#lightpop").slideUp(function(){A(this).remove();A("#overlay").fadeOut(function(){A(this).remove();E(A("embed, object, select"),true)})});F(false);R(false)};return C(this)}})(jQuery)
