﻿egg.extend.imagebox=function(a,b,c){var d=this.get();this.css("cursor","pointer");var e;switch(b){case "acg":case "truth":case "acgPreview":this.click(function(f){egg.imagebox.loadImageList(window.event?window.event.srcElement:f.target,a,b,c)});break;default:this.click(function(f){egg.imagebox.create(window.event?window.event.srcElement:f.target)});egg.imagebox.copyrightText=a||"";for(e=0;e<d.length;e++)egg.imagebox.imageList.push(egg.imagebox.createImage(d[e],e));if(egg.imagebox.imageList.length===
0)return;egg(egg.imagebox.imageList).click(egg.imagebox.listClick).mouseover(egg.imagebox.listMouseover).mouseout(egg.imagebox.listMouseout).css("cursor","pointer")}window.onresize=function(){var f=document.getElementById("bhib_imagebox");if(!(!f||document.getElementById("bhib_ori_image"))){var g=egg.imagebox.currentImage,h=false;if(!g.movieCode){h=egg.imagebox.scaleCurrentImage(g.oriWidth,g.oriHeight,f);g.style.width=h.w+"px";g.style.height=h.h+"px";h=h.scaled}egg.imagebox.setBoxContent(f);egg.lightbox.refresh();
f=egg.imagebox.getCurrentImageMaxHeight();g=document.getElementById("bhib_btn_zoomin");g.style.top=f-45+"px";g.style.display=h?"block":"none"}};egg.browser.opera?egg(document.documentElement).keypress(egg.imagebox.hotkey):egg(document.documentElement).keydown(egg.imagebox.hotkey)};
egg.imagebox=$.imagebox={IMG_SMALL:0,IMG_MIDDLE:1,IMG_BIG:2,SNAP_SIZE:77,SNAP_PER_PAGE:9,imagePattern:/http:\/\/pic\.bahamut\.com\.tw\/[BMS]\/2KU\/[0-9]{2}\/([0-9]{10}\.(:?JPG|GIF|PNG|BMP|JPEG))/,currentImage:null,imageList:[],copyrightText:"",acgPreview:false,imageLoader:function(a){var b=0;if(!a||!a.image||a.image.tagName!="IMG")alert("no image specified");else{var c=function(){if(!(a.criticalSection&&!a.criticalSection(a.image))){b>=100&&a.timeout&&a.timeout(a.args);if(a.image.complete||a.condition){if(a.image.complete){a.image.oriWidth=
a.image.width;a.image.oriHeight=a.image.height}a.loaded(a.args)}else{setTimeout(c,100);b++}}};c()}},loadImageList:function(a,b,c,d){egg.imagebox.imageList=[];egg.imagebox.copyrightText=b||"";egg.imagebox.acgPreview=c=="acgPreview";egg.ajax({method:"GET",param:c=="truth"?null:d,url:{acg:"/ajax/acg_loadpic.php",acgPreview:"/ajax/acg_preview_ajax.php",truth:"/ajax/truthAJAX.php"}[c],success:function(e){e=e.split(/\n/);for(var f=0;f<e.length;f++)if(e[f]!=="")if(c=="truth"){var g=new Image;g.index=f;g.style.width=
egg.imagebox.SNAP_SIZE+"px";g.style.height=egg.imagebox.SNAP_SIZE+"px";g.url="http://truth.bahamut.com.tw"+e[f];egg.imagebox.imageList.push(g)}else egg.imagebox.imageList.push(egg.imagebox.createImage(e[f],f));if(egg.imagebox.imageList.length!==0){egg(egg.imagebox.imageList).click(egg.imagebox.listClick).mouseover(egg.imagebox.listMouseover).mouseout(egg.imagebox.listMouseout).css("cursor","pointer");egg.imagebox.create(a)}},fail:function(){}})},create:function(a){if(!(!a||egg.imagebox.imageList.length===
0)){if(a.className=="acg_preview")a=egg.imagebox.imageList[0];var b=document.createElement("table");b.id="bhib_win";var c=document.createElement("tbody"),d=document.createElement("tr"),e=document.createElement("td"),f=document.createElement("a");f.id="bhib_btn_close2";if(egg.browser.ie){f.style.width="22px";f.style.height="22px"}f.href="javascript:egg.imagebox.close();";f.title="\u95dc\u9589\u8996\u7a97(\u71b1\u9375:Esc)";var g=document.createElement("a");g.id="bhib_btn_help";g.href="javascript:void(0);";
g.title="\u71b1\u9375\u8aaa\u660e";egg(g).click(egg.imagebox.help);var h=document.createElement("span");h.id="bhib_btn_zoomin";h.title="\u6aa2\u8996\u539f\u59cb\u5927\u5c0f(\u71b1\u9375:+)";egg(h).css("cursor","pointer");egg(h).click(egg.imagebox.zoomin);if(egg.browser.ie6)h.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://pic.bahamut.com.tw/plugins/imagebox/in.png', sizingMethod = 'scale')";else h.style.backgroundImage="url(http://pic.bahamut.com.tw/plugins/imagebox/in.png)";
var l=document.createElement("table");l.id="bhib_box_table";l.cellSpacing=0;l.cellPadding=0;var j=document.createElement("tbody"),k=document.createElement("tr"),n=document.createElement("td");n.id="bhib_imagebox";n.title="\u9ede\u9078\u770b\u4e0b\u4e00\u5f35(\u71b1\u9375:C)";egg(n).click(egg.imagebox.next);k.appendChild(n);j.appendChild(k);l.appendChild(j);j=document.createElement("p");j.id="bhib_text";egg.imagebox.setCurrentImage(a,n);a=egg.imagebox.getBoxText(egg.imagebox.currentImage);j.innerHTML=
a;j.style.display=a===""?"none":"block";a=document.createElement("table");a.id="bhib_list_table";a.cellSpacing="0";a.cellPadding="0";k=document.createElement("tbody");var o=document.createElement("tr"),q=document.createElement("td"),m=document.createElement("a");m.id="bhib_btn_left1";m.href="javascript:egg.imagebox.previousPage();";m.title="\u4e0a\u4e5d\u5f35(\u71b1\u9375:PgUp)";var i=document.createElement("a");i.id="bhib_btn_left2";i.href="javascript:egg.imagebox.to(0);";i.title="\u7b2c\u4e00\u5f35(\u71b1\u9375:Z)";
q.appendChild(m);q.appendChild(i);m=document.createElement("td");i=document.createElement("a");i.id="bhib_btn_right1";i.href="javascript:egg.imagebox.nextPage();";i.title="\u4e0b\u4e5d\u5f35(\u71b1\u9375:PgDn)";var p=document.createElement("a");p.id="bhib_btn_right2";p.href="javascript:egg.imagebox.to("+(egg.imagebox.imageList.length-1)+");";p.title="\u6700\u5f8c\u4e00\u5f35(\u71b1\u9375:V)";m.appendChild(i);m.appendChild(p);i=document.createElement("td");i.id="bhib_list_container";i.style.textAlign=
"left";list=egg.imagebox.getImageList(egg.imagebox.currentImage);egg.imagebox.createList(list,i);o.appendChild(q);o.appendChild(i);o.appendChild(m);k.appendChild(o);a.appendChild(k);egg.imagebox.setBoxContent(n);e.appendChild(l);e.appendChild(h);e.appendChild(f);e.appendChild(g);e.appendChild(j);e.appendChild(a);d.appendChild(e);c.appendChild(d);b.appendChild(c);egg.imagebox.imageLoader({image:egg.imagebox.currentImage,condition:egg.imagebox.currentImage.movieCode,loaded:egg.imagebox.show,args:{win:b,
box:n},criticalSection:egg.imagebox.criticalSection})}},setBoxContent:function(a){if(egg.imagebox.currentImage.movieCode)a.innerHTML=egg.imagebox.currentImage.movieCode;else a.firstChild?a.replaceChild(egg.imagebox.currentImage,a.firstChild):a.appendChild(egg.imagebox.currentImage)},createImage:function(a,b){var c=new Image;c.index=b;c.style.width=egg.imagebox.SNAP_SIZE+"px";c.style.height=egg.imagebox.SNAP_SIZE+"px";if(typeof a=="string"){a=a.split(/<>/,2);b=a[0].split(/\|/,2);c.movie=b[1]||undefined;
c.title=a[1]||"";c.url="http://pic.bahamut.com.tw/S/2KU/"+b[0].substring(8,10)+"/"+b[0]}else{c.title=a.title||"";c.url=egg.imagebox.getImageUrl(a.src,egg.imagebox.IMG_SMALL)}return c},show:function(a){var b=egg.imagebox.currentImage,c=false;if(!b.movieCode){c=egg.imagebox.scaleCurrentImage(b.width,b.height,a.box);b.style.width=c.w+"px";b.style.height=c.h+"px";c=c.scaled}if(a.win){egg.lightbox(a.win);$("#egg_mask").removeEvent("click",egg.lightbox.close).click(egg.imagebox.close)}else{egg.imagebox.setBoxContent(a.box);
egg.lightbox.refresh()}a=egg.imagebox.getCurrentImageMaxHeight();var d=document.getElementById("bhib_btn_zoomin");d.style.top=a-45+"px";d.style.display=c?"block":"none";b.title="\u9ede\u9078\u770b\u4e0b\u4e00\u5f35(\u71b1\u9375:C)";if(b=egg.imagebox.imageList[b.index+1])(new Image).src=egg.imagebox.getImageUrl(b.url,egg.imagebox.IMG_BIG)},getImageList:function(a,b){var c,d=egg.imagebox.imageList;if(b){c=a;b=b}else{for(c=0;c<d.length;c++)if(egg.imagebox.compareImage(d[c],a))break;b=d.length}a=Math.ceil((c+
1)/egg.imagebox.SNAP_PER_PAGE)*egg.imagebox.SNAP_PER_PAGE;c=a-egg.imagebox.SNAP_PER_PAGE;if(a>b)a=b;b=[];for(c=c;c<a;c++){if(!d[c].src){d[c].src=d[c].url;!d[c].resized&&!d[c].src.match(egg.imagebox.imagePattern)&&egg.imagebox.resizeTo({image:d[c],size:egg.imagebox.SNAP_SIZE})}b.push(d[c])}return b},resizeTo:function(a){if(a.oldImage){var b=a.image.width,c=a.image.height;if(a.image.width>a.size){b=a.size;c=Math.floor(a.image.height*(a.size/a.image.width))}if(c>a.size){c=a.size;b=Math.floor(a.image.width*
(a.size/a.image.height))}a.oldImage.style.width=b;a.oldImage.style.height=c;a.oldImage.resized=true}else{b=new Image;b.src=a.image.src;egg.imagebox.imageLoader({image:b,loaded:egg.imagebox.resizeTo,args:{image:b,size:a.size,oldImage:a.image}})}},compareImage:function(a,b){a=a.src||a.url;var c=b.src||b.url;if(a==c)return true;else{b=a.match(egg.imagebox.imagePattern);a=c.match(egg.imagebox.imagePattern);if(b&&a)return b[1]==a[1]}return false},getImageIndex:function(a){for(var b=egg.imagebox.imageList,
c=0;c<b.length;c++)if(egg.imagebox.compareImage(b[c],a))break;return c==b.length?-1:c},to:function(a){if(!(a==egg.imagebox.currentImage.index||a<0||a>=egg.imagebox.imageList.length)){var b=document.getElementById("bhib_text"),c=document.getElementById("bhib_list_container"),d=document.getElementById("bhib_imagebox"),e=egg.imagebox.imageList[a];egg.imagebox.setCurrentImage(e,d);a=egg.imagebox.getImageList(a,egg.imagebox.imageList.length);egg.imagebox.createList(a,c);c=egg.imagebox.getBoxText(e);b.innerHTML=
c;b.style.display=c===""?"none":"block";egg.imagebox.imageLoader({image:egg.imagebox.currentImage,condition:egg.imagebox.currentImage.movieCode,loaded:egg.imagebox.show,args:{win:null,box:d},criticalSection:egg.imagebox.criticalSection})}},listClick:function(a){egg.imagebox.to((window.event?window.event.srcElement:a.target).index)},listMouseover:function(a){(window.event?window.event.srcElement:a.target).style.borderColor="#FF9900"},listMouseout:function(a){a=window.event?window.event.srcElement:
a.target;if(a.index!=egg.imagebox.currentImage.index)a.style.borderColor="#999999"},next:function(){var a=egg.imagebox.currentImage.index;a>=egg.imagebox.imageList.length-1?alert("\u6c92\u6709\u4e0b\u4e00\u5f35\u5716\u7247\u4e86!"):egg.imagebox.to(a+1)},previous:function(){var a=egg.imagebox.currentImage.index;a<=0?alert("\u6c92\u6709\u4e0a\u4e00\u5f35\u5716\u7247\u4e86!"):egg.imagebox.to(a-1)},nextPage:function(){var a=egg.imagebox.currentImage.index,b=egg.imagebox.imageList.length,c=Math.ceil((a+
1)/egg.imagebox.SNAP_PER_PAGE),d=Math.ceil(b/egg.imagebox.SNAP_PER_PAGE);if(c>=d)alert("\u6c92\u6709\u4e0b\u4e00\u9801\u4e86!");else{a+=egg.imagebox.SNAP_PER_PAGE;if(a>=b)a=b-1;egg.imagebox.to(a)}},previousPage:function(){var a=egg.imagebox.currentImage.index;a-=egg.imagebox.SNAP_PER_PAGE;a<0?alert("\u6c92\u6709\u4e0a\u4e00\u9801\u4e86!"):egg.imagebox.to(a)},getImageUrl:function(a,b){var c=a.match(egg.imagebox.imagePattern);if(c){var d="";switch(b){case egg.imagebox.IMG_SMALL:a="S";break;case egg.imagebox.IMG_MIDDLE:a=
"M";break;case egg.imagebox.IMG_BIG:a="B";break;default:return a}return d="http://pic.bahamut.com.tw/"+a+"/2KU/"+c[1].substring(8,10)+"/"+c[1]}else return a},createList:function(a,b){var c;for(c=b.getElementsByTagName("img");c.length>0;)b.removeChild(c[0]);for(c=0;c<a.length;c++){a[c].style.borderColor=a[c].index==egg.imagebox.currentImage.index?"#FF9900":"#999999";b.appendChild(a[c])}},setCurrentImage:function(a,b){var c=new Image;c.index=a.index||egg.imagebox.getImageIndex(a);a=egg.imagebox.imageList[c.index];
c.src=egg.imagebox.getImageUrl(a.url,egg.imagebox.IMG_BIG);c.title=a.title||"";egg(c).css("cursor","pointer");egg.imagebox.currentImage=c;if(a.movie)egg.imagebox.currentImage.movieCode=egg.imagebox.getMovieCode(a.movie,b);egg.imagebox.acgPreview&&egg.event.addEvent("contextmenu",function(d){d=window.event||d;egg.event.stop(d)},true,egg.imagebox.currentImage)},getMovieCode:function(a,b){var c=/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/,d="";if(a.match(/^http:\/\/www\.youtube\.com\/v\/[0-9a-zA-Z_-]{11}$/)){b=
egg.imagebox.scaleCurrentImage(425,344,b);d='<object width="'+b.w+'" height="'+b.h+'"><param name="movie" value="'+a+'&hl=zh_TW&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+a+'&hl=zh_TW&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+b.w+'" height="'+b.h+'"></embed></object>'}else if(a.match(c)){b=egg.imagebox.scaleCurrentImage(432,364,b);d='<embed src="http://images.video.msn.com/flash/soapbox1_1.swf" quality="high" width="'+
b.w+'" height="'+b.h+'" base="http://images.video.msn.com" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" pluginspage="http://macromedia.com/go/getflashplayer" flashvars="c=v&v='+a+'&rvp=true&ifs=true&ch=true&fr=IV2_zh-tw_soapbox&msnlink=false&mkt=zh-tw&ap=true&ad=false"></embed>'}return d},getBoxText:function(a){var b="",c=egg.imagebox.copyrightText;b=a.index+1+"/"+egg.imagebox.imageList.length+"\u3000";var d="";if(a&&a.title&&a.title!=="")d=a.title;b=b+d;
if(c!=="")b+='<br /><span style="font-size:8pt;font-family:Arial;">'+c+"</span>";return b},getCurrentImageMaxHeight:function(){var a=egg.imagebox.SNAP_SIZE+46+18;if(egg.imagebox.copyrightText!=="")a+=20;return(document.compatMode&&document.compatMode=="CSS1Compat"?document.documentElement:document.body).clientHeight-a},scaleCurrentImage:function(a,b,c){var d=egg.imagebox.getCurrentImageMaxHeight(),e=false;if(b>d){a=Math.floor(a*(d/b));b=d;c.style.height="";e=true}else if(b<=d)c.style.height=d+10+
"px";if(a>825){b=Math.floor(b*(825/a));a=825;e=true}if(b<=d)c.style.height=d+10+"px";return{w:a,h:b,scaled:e}},zoomin:function(){if(!(!egg.imagebox.currentImage||egg.imagebox.currentImage.movieCode)){var a=new Image,b,c,d=document.compatMode&&document.compatMode=="CSS1Compat"?document.documentElement:document.body;a.src=egg.imagebox.currentImage.src;a.id="bhib_ori_image";a.title="\u9ede\u5716\u95dc\u9589(\u71b1\u9375:-)";a.style.cursor="url(http://pic.bahamut.com.tw/plugins/imagebox/out.cur),default";
egg(a).click(egg.imagebox.closeOriImage);egg.imagebox.imageLoader({image:a,loaded:function(){var e=d.scrollHeight;b=Math.floor(d.clientHeight/2-a.height/2+d.scrollTop);c=Math.floor(d.clientWidth/2-a.width/2);if(b+a.height>e)b=e-a.height;if(b<0)b=0;if(c<0)c=0;a.style.top=b-5+"px";a.style.left=c-5+"px";document.body.appendChild(a);document.getElementById("egg_box").style.display="none";document.getElementById("egg_mask").title="\u9ede\u64ca\u95dc\u9589(\u71b1\u9375:-)";(e=document.getElementById("bhib_help"))&&
document.body.removeChild(e)}})}},closeOriImage:function(){var a=document.getElementById("bhib_ori_image");document.body.removeChild(a);document.getElementById("egg_box").style.display="block";egg.lightbox.refresh();document.getElementById("egg_mask").removeAttribute("title")},close:function(){var a=document.getElementById("bhib_help");a&&document.body.removeChild(a);document.getElementById("bhib_ori_image")?egg.imagebox.closeOriImage():egg.lightbox.close()},criticalSection:function(a){return a==
egg.imagebox.currentImage},hotkey:function(a){a=window.event||a;if(document.getElementById("bhib_imagebox")){var b,c,d,e,f,g;if(egg.browser.opera){b=122;c=120;d=99;e=118;f=43;g=45}else{b=90;c=88;d=67;e=86;f=107;g=109}var h;h=egg.browser.ie?a.keyCode:a.which||a.keyCode;for(var l=[34,33,27,b,c,d,e,f,g],j=[],k=0;k<l.length;k++)j[l[k]]=true;j[h]&&egg.event.preventDefault(a);if(document.getElementById("bhib_ori_image"))if(h==g)h=27;else return;switch(h){case 27:egg.imagebox.close();break;case 34:egg.imagebox.nextPage();
break;case 33:egg.imagebox.previousPage();break;case b:egg.imagebox.to(0);break;case c:egg.imagebox.previous();break;case d:egg.imagebox.next();break;case e:egg.imagebox.to(egg.imagebox.imageList.length-1);break;case f:egg.imagebox.zoomin();break;default:}}},help:function(a){a=a||window.event;var b=document.getElementById("bhib_help");if(b)document.body.removeChild(b);else{var c=document.compatMode&&document.compatMode=="CSS1Compat"?document.documentElement:document.body;b=document.createElement("div");
b.id="bhib_help";b.style.top=a.clientY+c.scrollTop+5+"px";b.style.left=a.clientX+c.scrollLeft+5+"px";b.innerHTML='<table cellspacing="0" cellpadding="0" width="100"><tr><td colspan="2">\u25ce\u71b1\u9375\u8a2d\u5b9a\uff1a</td></tr><tr><td>\u4e0a\u4e00\u5f35</td><td>X</td></tr><tr><td>\u4e0b\u4e00\u5f35</td><td>C</td></tr><tr><td>\u7b2c\u4e00\u5f35</td><td>Z</td></tr><tr><td>\u6700\u5c3e\u5f35</td><td>V</td></tr><tr><td>\u4e0a\u4e5d\u5f35</td><td>PgUp</td></tr><tr><td>\u4e0b\u4e5d\u5f35</td><td>PgDn</td></tr><tr><td>\u95dc\u9589\u8996\u7a97</td><td>Esc</td></tr><tr><td>\u6aa2\u8996\u539f\u5716</td><td>\uff0b</td></tr><tr><td>\u95dc\u9589\u539f\u5716</td><td>\uff0d</td></tr>';
document.body.appendChild(b)}}};