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