jQuery.fn.cwh=function(opts){this.each(function(i){var self=$(this);var options={bgid:self.attr("id")+"_bg",bgcolor:"#000",bgimage:null,bgopacity:0.5,bgzindex:1000,bgclickable:true,id:self.attr("id"),width:self.width(),height:self.height(),variableSize:false,useIEpnghack:true,fadespeed:1000,openbtn:null,closebtn:null,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",width:"0px",height:"0px"});if(options.bgimage!=null){bgLayer.css({"background-image":options.bgimage})}else{bgLayer.css({"background-color":options.bgcolor})}self.css({"z-index":options.bgzindex+1,display:"none"});if(self.data("openbtn")!=null){self.data("openbtn").click(function(){self.cwhStart();return false})}if(self.data("closebtn")!=null){self.data("closebtn").click(function(){self.cwhStop();return false})}$.fn.cwhStart=function(useBeforeStart,useAfterStart){if(typeof useBeforeStart=="undefined"){useBeforeStart=true}if(typeof useAfterStart=="undefined"){useAfterStart=true}var self=this;var bg=$(self.data("fullbgid"));if(!self.data("shown")&&bg.size()>0){if(useBeforeStart&&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,function(){if(useAfterStart&&self.data("afterStart")!=null){self.data("afterStart").call()}})}else{self.show();if(useAfterStart&&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(){if(self.data("closebtn")!=null){var cb=self.data("closebtn");var cbevents=cb.data("events");if(cbevents&&typeof cbevents.click!="undefined"){cb.click()}else{self.chwStop()}}})}}}$(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(useBeforeStop,useAfterStop){if(typeof useBeforeStop=="undefined"){useBeforeStop=true}if(typeof useAfterStop=="undefined"){useAfterStop=true}var self=this;var bg=$(self.data("fullbgid"));if(self.data("shown")&&bg.size()>0){if(useBeforeStop&&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(useAfterStop&&self.data("afterStop")!=null){self.data("afterStop").call()}})})}else{self.hide();$(self.data("fullbgid")).stop().fadeTo(self.data("fadespeed"),0,function(){bg.hide();if(useAfterStop&&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};
