(function(a){a.fn.closeDOMWindow=function(b){if(!b)b={};var c=function(){if(b.anchoredClassName){var c=a("."+b.anchoredClassName);c.fadeOut("fast",function(){if(a.fn.draggable)c.draggable("destory").trigger("unload").remove();else c.trigger("unload").remove()});b.functionCallOnClose&&b.functionCallAfterClose()}else{var e=a("#DOMWindowOverlay"),d=a("#DOMWindow");e.fadeOut("fast",function(){e.trigger("unload").unbind().remove()});d.fadeOut("fast",function(){if(a.fn.draggable)d.draggable("destroy").trigger("unload").remove();else d.trigger("unload").remove()});a(window).unbind("scroll.DOMWindow");a(window).unbind("resize.DOMWindow");a.fn.openDOMWindow.isIE6&&a("#DOMWindowIE6FixIframe").remove();b.functionCallOnClose&&b.functionCallAfterClose()}};if(b.eventType)return this.each(function(){a(this).bind(b.eventType,function(){c(this);return false})});else c()};a.closeDOMWindow=function(b){a.fn.closeDOMWindow(b)};a.fn.openDOMWindow=function(k){var c=a.fn.openDOMWindow;c.defaultsSettings={anchoredClassName:"",anchoredSelector:"",borderColor:"#ccc",borderSize:"4",draggable:0,eventType:null,fixedWindowY:100,functionCallOnOpen:null,functionCallOnClose:null,height:500,loader:0,loaderHeight:0,loaderImagePath:"",loaderWidth:0,modal:0,overlay:1,overlayColor:"#000",overlayOpacity:"85",positionLeft:0,positionTop:0,positionType:"centered",width:500,windowBGColor:"#fff",windowBGImage:null,windowHTTPType:"get",windowPadding:10,windowSource:"inline",windowSourceID:"",windowSourceURL:"",windowSourceAttrURL:"href"};var b=a.extend({},a.fn.openDOMWindow.defaultsSettings,k||{});c.viewPortHeight=function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight};c.viewPortWidth=function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};c.scrollOffsetHeight=function(){return self.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop};c.scrollOffsetWidth=function(){return self.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft};c.isIE6=typeof document.body.style.maxHeight==="undefined";var g=function(){var b=a("#DOMWindowOverlay");if(c.isIE6){var d=document.documentElement.offsetHeight+document.documentElement.scrollTop-4,e=document.documentElement.offsetWidth-21;b.css({height:d+"px",width:e+"px"})}else b.css({height:"100%",width:"100%",position:"fixed"})},f=function(){var b=document.documentElement.offsetHeight+document.documentElement.scrollTop-4,c=document.documentElement.offsetWidth-21;a("#DOMWindowIE6FixIframe").css({height:b+"px",width:c+"px"})},e=function(){var d=a("#DOMWindow");if(b.height+50>c.viewPortHeight())d.css("left",Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(d.outerWidth()/2));else{d.css("left",Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(d.outerWidth()/2));d.css("top",Math.round(c.viewPortHeight()/2)+c.scrollOffsetHeight()-Math.round(d.outerHeight()/2))}},l=function(){var b=a("#DOMWindowLoader");if(c.isIE6){b.css({left:Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(b.innerWidth()/2),position:"absolute"});b.css({top:Math.round(c.viewPortHeight()/2)+c.scrollOffsetHeight()-Math.round(b.innerHeight()/2),position:"absolute"})}else b.css({left:"50%",top:"50%",position:"fixed"})},i=function(){var d=a("#DOMWindow");d.css("left",b.positionLeft+c.scrollOffsetWidth());d.css("top",+b.positionTop+c.scrollOffsetHeight())},d=function(c){if(arguments[0]){a("."+c+" #DOMWindowLoader").remove();a("."+c+" #DOMWindowContent").fadeIn("fast",function(){b.functionCallOnOpen&&b.functionCallOnOpen()});a("."+c+".closeDOMWindow").click(function(){a.closeDOMWindow();return false})}else{a("#DOMWindowLoader").remove();a("#DOMWindow").fadeIn("fast",function(){b.functionCallOnOpen&&b.functionCallOnOpen()});a("#DOMWindow .closeDOMWindow").click(function(){a.closeDOMWindow();return false})}},h=function(b){var a={};b.replace(/b([^&=]*)=([^&=]*)b/g,function(d,b,c){if(typeof a[b]!="undefined")a[b]+=","+c;else a[b]=c});return a},j=function(r){b.windowSourceID=a(r).attr("href")||b.windowSourceID;b.windowSourceURL=a(r).attr(b.windowSourceAttrURL)||b.windowSourceURL;b.windowBGImage=b.windowBGImage?"background-image:url("+b.windowBGImage+")":"";var m,k;if(b.positionType=="anchored"){var n=a(b.anchoredSelector).position(),p=n.left+b.positionLeft,q=n.top+b.positionTop;a("body").append('<div class="'+b.anchoredClassName+'" style="'+b.windowBGImage+";background-repeat:no-repeat;padding:"+b.windowPadding+"px;overflow:auto;position:absolute;top:"+q+"px;left:"+p+"px;height:"+b.height+"px;width:"+b.width+"px;background-color:"+b.windowBGColor+";border:"+b.borderSize+"px solid "+b.borderColor+';z-index:10001"><div id="DOMWindowContent" style="display:none"></div></div>');b.loader&&b.loaderImagePath!==""&&a("."+b.anchoredClassName).append('<div id="DOMWindowLoader" style="width:'+b.loaderWidth+"px;height:"+b.loaderHeight+'px;"><img src="'+b.loaderImagePath+'" /></div>');if(a.fn.draggable)b.draggable&&a("."+b.anchoredClassName).draggable({cursor:"move"});switch(b.windowSource){case "inline":a("."+b.anchoredClassName+" #DOMWindowContent").append(a(b.windowSourceID).children());a("."+b.anchoredClassName).unload(function(){a("."+b.windowSourceID).append(a("."+b.anchoredClassName+" #DOMWindowContent").children())});d(b.anchoredClassName);break;case "iframe":a("."+b.anchoredClassName+" #DOMWindowContent").append('<iframe frameborder="0" hspace="0" wspace="0" src="'+b.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1e3)+'" style="width:100%;height:100%;border:none;background-color:#fff;" class="'+b.anchoredClassName+'Iframe" ></iframe>');a("."+b.anchoredClassName+"Iframe").load(d(b.anchoredClassName));break;case "ajax":if(b.windowHTTPType=="post"){if(b.windowSourceURL.indexOf("?")!==-1){m=b.windowSourceURL.substr(0,b.windowSourceURL.indexOf("?"));k=h(b.windowSourceURL)}else{m=b.windowSourceURL;k={}}a("."+b.anchoredClassName+" #DOMWindowContent").load(m,k,function(){d(b.anchoredClassName)})}else{if(b.windowSourceURL.indexOf("?")==-1)b.windowSourceURL+="?";a("."+b.anchoredClassName+" #DOMWindowContent").load(b.windowSourceURL+"&random="+(new Date).getTime(),function(){d(b.anchoredClassName)})}}}else{if(b.overlay){a("body").append('<div id="DOMWindowOverlay" style="z-index:10000;display:none;position:absolute;top:0;left:0;background-color:'+b.overlayColor+";filter:alpha(opacity="+b.overlayOpacity+");-moz-opacity: 0."+b.overlayOpacity+";opacity: 0."+b.overlayOpacity+';"></div>');if(c.isIE6){a("body").append('<iframe id="DOMWindowIE6FixIframe"  src="blank.html"  style="width:100%;height:100%;z-index:9999;position:absolute;top:0;left:0;filter:alpha(opacity=0);"></iframe>');f()}g();var o=a("#DOMWindowOverlay");o.fadeIn("fast");!b.modal&&o.click(function(){a.closeDOMWindow()})}if(b.loader&&b.loaderImagePath!==""){a("body").append('<div id="DOMWindowLoader" style="z-index:10002;width:'+b.loaderWidth+"px;height:"+b.loaderHeight+'px;"><img src="'+b.loaderImagePath+'" /></div>');l()}a("body").append('<div id="DOMWindow" style="background-repeat:no-repeat;'+b.windowBGImage+";overflow:auto;padding:"+b.windowPadding+"px;display:none;height:"+b.height+"px;width:"+b.width+"px;background-color:"+b.windowBGColor+";border:"+b.borderSize+"px solid "+b.borderColor+'; position:absolute;z-index:10001"></div>');var j=a("#DOMWindow");switch(b.positionType){case "centered":e();b.height+50>c.viewPortHeight()&&j.css("top",b.fixedWindowY+c.scrollOffsetHeight()+"px");break;case "absolute":j.css({top:b.positionTop+c.scrollOffsetHeight()+"px",left:b.positionLeft+c.scrollOffsetWidth()+"px"});if(a.fn.draggable)b.draggable&&j.draggable({cursor:"move"});break;case "fixed":i();break;case "anchoredSingleWindow":var n=a(b.anchoredSelector).position(),p=n.left+b.positionLeft,q=n.top+b.positionTop;j.css({top:q+"px",left:p+"px"})}a(window).bind("scroll.DOMWindow",function(){b.overlay&&g();c.isIE6&&f();b.positionType=="centered"&&e();b.positionType=="fixed"&&i()});a(window).bind("resize.DOMWindow",function(){c.isIE6&&f();b.overlay&&g();b.positionType=="centered"&&e()});switch(b.windowSource){case "inline":j.append(a(b.windowSourceID).children());j.unload(function(){a(b.windowSourceID).append(j.children())});d();break;case "iframe":j.append('<iframe frameborder="0" hspace="0" wspace="0" src="'+b.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1e3)+'" style="width:100%;height:100%;border:none;background-color:#fff;" id="DOMWindowIframe" ></iframe>');a("#DOMWindowIframe").load(d());break;case "ajax":if(b.windowHTTPType=="post"){if(b.windowSourceURL.indexOf("?")!==-1){m=b.windowSourceURL.substr(0,b.windowSourceURL.indexOf("?"));k=h(b.windowSourceURL)}else{m=b.windowSourceURL;k={}}j.load(m,k,function(){d()})}else{if(b.windowSourceURL.indexOf("?")==-1)b.windowSourceURL+="?";j.load(b.windowSourceURL+"&random="+(new Date).getTime(),function(){d()})}}}};if(b.eventType)return this.each(function(){a(this).bind(b.eventType,function(){j(this);return false})});else j()};a.openDOMWindow=function(b){a.fn.openDOMWindow(b)}})(jQuery)
