jQuery.fn.cwh=function(opts){this.each(function(i){var bg_prefix="centerwindow_mainBg";var self=$(this);var options={bgid:self.attr("id")+"_bg",bgcolor:"#000",bgopacity:0.5,bgzindex:1000,bgclickable:true,id:self.attr("id"),width:self.width(),height:self.height(),variableSize:false,useIEpnghack:true,fadespeed:1000,beforeStart:null,afterStart:null,beforeStop:null,afterStop:null};$.extend(options,opts);for(i in options){self.data(i,options[i])}self.data("shown",false);self.data("fullbgid","#"+options.bgid);$("body").append('<div id="'+options.bgid+'"></div>');var bgLayer=$(self.data("fullbgid"));bgLayer.css({display:"none",position:"absolute","z-index":options.bgzindex,left:"0px",top:"0px","background-color":options.bgcolor,width:"0px",height:"0px"});self.css({"z-index":options.bgzindex+1,display:"none"});$.fn.cwhStart=function(){var self=this;var bg=$(self.data("fullbgid"));if(!self.data("shown")&&bg.size()>0){if(self.data("beforeStart")!=null){self.data("beforeStart").call()}self.data("shown",true);self.cwhPositioning();if(self.data("shown")&&bg.size()>0){bg.stop().fadeTo(self.data("fadespeed"),self.data("bgopacity"),function(){if(($.browser.msie&&!self.data("useIEpnghack"))||!$.browser.msie){self.fadeTo(self.data("fadespeed"),1)}else{self.show()}if(self.data("afterStart")!=null){self.data("afterStart").call()}});if(self.data("bgclickable")){var bgevents=bg.data("events");if(typeof bgevents=="undefined"||(bgevents&&typeof bgevents.click=="undefined")){bg.click(function(){self.cwhStop()})}}}$(window).resize(function(){if(self.data("shown")&&bg.size()>0){self.cwhPositioning()}});$(window).scroll(function(){if(self.data("shown")&&bg.size()>0){self.cwhPositioning()}})}};$.fn.cwhStop=function(){var self=this;var bg=$(self.data("fullbgid"));if(self.data("shown")&&bg.size()>0){if(self.data("beforeStop")!=null){self.data("beforeStop").call()}self.data("shown",false);if(($.browser.msie&&!self.data("useIEpnghack"))||!$.browser.msie){self.stop().fadeTo(self.data("fadespeed"),0,function(){self.hide();$(self.data("fullbgid")).stop().fadeTo(self.data("fadespeed"),0,function(){bg.hide();if(self.data("afterStop")!=null){self.data("afterStop").call()}})})}else{self.hide();$(self.data("fullbgid")).stop().fadeTo(self.data("fadespeed"),0,function(){bg.hide();if(self.data("afterStop")!=null){self.data("afterStop").call()}})}}};$.fn.cwhPositioning=function(){var self=this;var bg=$(self.data("fullbgid"));if(self.data("shown")&&bg.size()>0){var windowWidth=$("body").width();var windowHeight=$(window).height();if($.browser.msie&&parseInt($.browser.version)<7){var windowWidthTmp=document.documentElement.clientWidth;var windowHeightTmp=document.documentElement.clientHeight;if(windowWidthTmp>0){windowWidth=windowWidthTmp}if(windowHeightTmp>0){windowHeight=windowHeightTmp}}bg.css({width:windowWidth,height:windowHeight});var windowFullWidth=Math.max(Math.max(windowWidth,document.documentElement.scrollWidth),document.body.scrollWidth);var windowFullHeight=Math.max(Math.max(windowHeight,document.documentElement.scrollHeight),document.body.scrollHeight);var windowOffsetLeft=Math.max($("body").scrollLeft(),document.documentElement.scrollLeft);var windowOffsetTop=Math.max($("body").scrollTop(),document.documentElement.scrollTop);if(self.data("variableSize")){self.data("width",self.width());self.data("height",self.height())}var width=self.data("width");var height=self.data("height");bg.css({width:windowFullWidth,height:windowFullHeight});if($.browser.msie){self.stop().css({left:(windowWidth<=width?((width+windowOffsetLeft>=windowFullWidth)?self.css("left"):windowOffsetLeft):parseInt((windowWidth-width)/2)+windowOffsetLeft),top:(windowHeight<=height?((height+windowOffsetTop>=windowFullHeight)?self.css("top"):windowOffsetTop):parseInt((windowHeight-height)/2)+windowOffsetTop)})}else{self.stop().animate({left:(windowWidth<=width?((width+windowOffsetLeft>=windowFullWidth)?self.css("left"):windowOffsetLeft):parseInt((windowWidth-width)/2)+windowOffsetLeft),top:(windowHeight<=height?((height+windowOffsetTop>=windowFullHeight)?self.css("top"):windowOffsetTop):parseInt((windowHeight-height)/2)+windowOffsetTop)})}}};return self});return this};
