(function(a){a.fn.wBox=function(f){var o={opacity:0.5,drag:false,title:"",noTitle:false,html:"",callBack:null,isImage:false,images:[],left:300,top:400,iframeWH:{width:400,height:300},setPos:false,overlay:true,isFrame:false,imageTypes:["png","jpg","jpeg","gif"]};var u=a.extend(o,f);z();var b='				    <div id="wBox" style="display:none;"> 				      <div class="popup"> 				        <table> 				          <tbody> 				            <tr class="imgRemove"> 				              <td class="tl"/><td class="b"/><td class="tr"/> 				            </tr> 				            <tr> 				              <td class="b imgRemove"/> 				              <td class="body">'+(u.noTitle?"":'<table class="title imgRemove"><tr><td class="dragTitle"><div class="itemTitle">'+u.title+'</div></td>                                  <td width="20px" title="Закрыть"><div class="close"></div></td></tr></table> ')+'</div> 				                <div class="content"> 				                </div> 				              </td> 				              <td class="b imgRemove"/> 				            </tr> 				            <tr class="imgRemove"> 				              <td class="bl"/><td class="b"/><td class="br"/> 				            </tr> 				          </tbody> 				        </table> 				      </div> 				    </div>';var k=a("<div class='wBox_loading'><img src='loading.gif'/></div>");var g=[];var c=0;var x=null;var v=null;var q=null;a(this).click(function(){x?x.remove():null;v?v.remove():null;u.overlay?x=a("<div id='wBox_overlay' class='wBox_hide'></div>").hide().addClass("wBox_overlayBG").css("opacity",u.isImage?0.8:u.opacity).dblclick(function(){s()}).appendTo("body").fadeIn(300):null;v=a(b).appendTo("body");m(this.href);return false});function m(G){var C=v.find(".content");if(u.isImage){v.find(".imgRemove").remove();v.find(".content").css({padding:"10px","background-color":"#FFFFFF"});k.appendTo(C);var B=y(370);v.css({left:B[0],top:B[1]});e()}else{if(u.isFrame){ifr=a("<iframe name='wBoxIframe' style='width:"+u.iframeWH.width+"px;height:"+u.iframeWH.height+"px;' scrolling='auto' frameborder='0' src='"+G+"'></iframe>");ifr.appendTo(C);ifr.load(function(){try{$t=a(this).contents();$t.find(".wBoxClose").click(s);fH=$t.height();fW=$t.width();w=a(window);newW=Math.min(w.width()-40,fW);newH=w.height()-25-(u.noTitle?0:30);newH=Math.min(newH,fH);if(!newH){return}var H=y(newW);v.animate({left:H[0],top:H[1]},1000);a(this).animate({height:newH,width:newW},1000)}catch(I){}})}else{if(G!==window.location.href&&G){if(G.match(/#/)){var D=window.location.href.split("#")[0];var F=G.replace(D,"");C.append(a(F).clone(true).show())}else{if(G.match(Exp)){var E=new Image();k.appendTo(C);E.onload=function(){w=E.width<100?100:E.width;h=E.height<100?100:E.height+24;var H=y(w);imgC=a('<div class="image"><img src="'+E.src+'" /></div>');v.css({left:H[0],top:H[1]});k.remove();C.html(imgC.hide().fadeIn())};E.src=G}else{k.appendTo(C);C.load(G,function(){k.remove();a(this).find(".wBoxClose").click(s)})}}}else{C.html(u.html)}}}i()}function e(){for(var B=u.images.length;B--;){g[B]=new Image();B?null:g[0].onload=function(){k.fadeOut(300,n)};g[B].src=u.images[B]}}function n(){var D=g[c],C=v.find(".content").html(k.show());w=D.width<100?100:D.width;h=D.height<100?100:D.height+24;var B=y(w);var F=w*2<900?900:w*2;var E=a("<div id='IMG'><img src='"+D.src+"' id='imgURL'/><div class='imgBTN'><a href='' id='imgPrev' title='Предыдущий'></a><a id='imgNext' href='' title='Следующий'></a></div></div>");E.find("#imgPrev").click(function(){p();return false}).next().click(function(){r();return false});v.animate({left:B[0],top:B[1]},F).find(".body").animate({height:h,width:w},F,function(){C.html(E.hide().fadeIn());k.stop().hide()})}function r(){++c===u.images.length?c=0:null;n()}function p(){--c<0?c=u.images.length-1:null;n()}function z(){var C=u.imageTypes.join("|");Exp=new RegExp("."+C+"$","i");var B=["titleBG.png","wbox.png","close.png","loading.gif","btn-prev.gif","btn-next.gif"];var D=[];for(var E=B.length;E--;){D[E]=new Image();D[E].src=B[E]}}function i(){d();v.find(".close").click(function(){s()}).hover(function(){a(this).addClass("on")},function(){a(this).removeClass("on")});a(document).unbind("keydown.wBox").bind("keydown.wBox",function(B){if(B.keyCode===27){s()}return true});u.drag?A():null;typeof u.callBack==="function"?u.callBack():null}function d(){var B=y(a("#wBox").width());a("#wBox").css({left:B[0],top:B[1]}).show();var C=j();x?x.height(C[1]).width(C[0]):null}function j(){var D,B;if(window.innerHeight&&window.scrollMaxY){D=window.innerWidth+window.scrollMaxX;B=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){D=document.body.scrollWidth;B=document.body.scrollHeight}else{D=document.body.offsetWidth;B=document.body.offsetHeight}}var C,E;if(self.innerHeight){if(document.documentElement.clientWidth){C=document.documentElement.clientWidth}else{C=self.innerWidth}E=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){C=document.documentElement.clientWidth;E=document.documentElement.clientHeight}else{if(document.body){C=document.body.clientWidth;E=document.body.clientHeight}}}if(B<E){pageHeight=E}else{pageHeight=B}if(D<C){pageWidth=D}else{pageWidth=C}pageWidth=Math.max(pageWidth,C);pageHeight=Math.max(pageHeight,E);arrayPageSize=new Array(pageWidth,pageHeight);return arrayPageSize}function y(B){var C=a(window);if(u.setPos){l=u.left;t=u.top}else{l=(C.width()-B)/2;t=C.scrollTop()+C.height()/10}return[l,t]}function A(){var F,D,E;var H=v.find(".dragTitle").css("cursor","move");H.bind("selectstart",function(){return false});H.mousedown(function(I){F=I.clientX-parseInt(v.css("left"));D=I.clientY-parseInt(v.css("top"));v.mousemove(C).mouseout(G).css("opacity",0.8);H.mouseup(B)});function C(I){E=false;win=a(window);if(I.clientX-F<0){l=0}else{if(I.clientX-F>win.width()-v.width()){l=win.width()-v.width()}else{l=I.clientX-F}}v.css({left:l,top:I.clientY-D})}function G(I){E=true;setTimeout(function(){E&&B(I)},10)}function B(I){v.unbind("mousemove",C).unbind("mouseout",G).css("opacity",1);H.unbind("mouseup",B)}}function s(){if(v){x?x.remove():null;v.find(".body").stop();v.stop().fadeOut(300,function(){v.remove()})}}a(".wBoxClose").click(s);a(window).resize(function(){d()})}})(jQuery);

