/**
 * zudolab jqPopWin
 *
 * @version    1
 * @copyright    (c)2008 Takeshi Takatsudo (http://zudolab.net/)
 * @license    MIT (http://www.opensource.org/licenses/mit-license.php)
 */
(function(a){jqPopWin=function(c){this.selector=c.selector?c.selector:null;this.focusWin=(c.focusWin===false)?false:true;this.resizeWin=c.resizeWin?c.resizeWin:false;this.name=c.name?c.name:"_blank";this.style=c.style?c.style:null;this.$anchors=[];this.styleStr=null;var b=this;a(function(){b.setup()})};jqPopWin.prototype.setup=function(){this.$anchors=a(this.selector);if(this.$anchors.length==0){return}this.generateStyleStr();this.setEvents()};jqPopWin.prototype.setEvents=function(){var b=this;this.$anchors.click(c);function c(){var h=a(this);var d=this.href;var i=(this.target&&this.target!="_blank")?this.target:(b.name?b.name:"_blank");var g=b.styleStr?b.styleStr:null;var f=b.getDirectWH(h);if(f){g=b.replaceOrAddWH(g,f)}var e=g?window.open(d,i,g):window.open(d,i);b.tryToResize(e,f);b.tryToFocus(e);return false}};jqPopWin.prototype.tryToFocus=function(b){if(!this.focusWin){return}try{b.focus()}catch(c){}};jqPopWin.prototype.tryToResize=function(g,h){if(!this.resizeWin){return}var c=this.getSpecifiedStyleValue("width");var f=this.getSpecifiedStyleValue("height");if(!(c&&f)&&!h){return}var d=h?h.w:c;var b=h?h.h:f;try{g.resizeTo(d,b)}catch(i){}};jqPopWin.prototype.generateStyleStr=function(){if(!this.style){return}var f="";for(var d=0,e;e=this.style[d];d++){if(d!=0){f=f+","}var c=e[0];var b=e[1];f=f+c+"="+b}this.styleStr=f};jqPopWin.prototype.replaceOrAddWH=function(c,b){if(b.w){if(!c){c="width="+b.w}else{if(c.indexOf("width=")>-1&&b.w){c=c.replace(/width=[0-9]+/,"width="+b.w)}else{c=c+"width="+b.w}}}if(b.h){if(!c){c="height="+b.h}else{if(c.indexOf("height=")>-1&&b.h){c=c.replace(/height=[0-9]+/,"height="+b.h)}else{c=c+"height="+b.h}}}return c};jqPopWin.prototype.getSpecifiedStyleValue=function(d){for(var c=0,b;b=this.style[c];c++){if(b[0]==d){return b[1]}}return null};jqPopWin.prototype.getDirectWH=function(g){if(!g.is("[class*= w_]")){return false}var f=g.attr("class").split(" ");for(var e=0,h;h=f[e];e++){if(h.indexOf("w_")==0){var d=h.split("_");var b=d[1]?d[1]:null;var c=d[3]?d[3]:null;break}}return{w:b,h:c}}})(jQuery);
