/* 
*   jQuery Modal Dialog Version 1.0
*   Developed by CJ Amodeo (cjamodeo@gmail.com)
*   Page should be XHTML 1.0 Transitional
*   Requires jQuery 1.4.2 or later
*
*   displaySettings - Default display settings
********************************************************************************
*   All function calls should be made after the page is loaded (jQuery(document).ready)
********************************************************************************
*   show(objSelector, appendToNodeSelector, settings) - Displays the dialog
*       objSelector: selector of obj to display as modal
*       appendToNodeSelector: -will move the object and append it to the sepcified node
*       settings: overrides default display settings
*
*   hide() - Hides the dialog
*
*   refresh() - repositions the dialog
*
*   getCurrentSetting(settingName) - returns the current setting
*   setCurrentSetting(settingName, settingValue) - updates the currently used setting
*
*   settings/jQuery.modalDialog.displaySettings map variables
*       dialogPosition: string, fixed or absolute, default fixed
*       hideOnClick: boolean, true/false, default true
*       backgroundColor: string, hex color, default #000000
*       opacity: float, 0-1, default 0.6
*       left: integer, default -1 (causes centering)
*       top: integer, default -1 (causes centering)
*       width: integer, default -1 (forces use of CSS width)
*       height: integer, default -1 (forces use of CSS height)
*       show: function(dialogSelector), default null, must call showCallback after
*       hide: function(dialogSelector), default null, must call hideCallback after
*       onHide: function, default null, called at the end of hide()
*       fullScreen: boolean, default false, sets the dialog's width and height to the window's width and height
*       padding: integer, default 50, window/dialog padding when using fullScreen=true
*       animation: string, default "fadeIn", values are "fadeIn", "expand", "fadeInGrayoutOnly"
*       callback: function to execute
*       dialogAbove: string, selector of obj which the the dialog should not apear over
*       easing: string, default "swing", jQuery easing algorithm
*/
jQuery.modalDialog=(function(){var shouldAutoScroll=false;var currentSettings=null;var dialogSelector=null;var divWidth=0;var divHeight=0;var grayoutDivID="evokeModalDialogGrayout";var grayoutDivObj=null;var scrollTop=0;var scrollLeft=0;var position={x:-1,y:-1};var browser={ua:window.navigator.userAgent.toLowerCase(),isIE:function(){return/msie/.test(this.ua)},isIE6:function(){return/msie/.test(this.ua)&&(this.ua.match(/.+msie (\d+)/))[1]==6},isIDevice:function(){return/(ipod|ipad|iphone)/.test(this.ua)}};function getType(obj){if(obj instanceof Array){return"array"}else{var t=typeof(obj);if(t=="object"&&!obj){return"null"}else{return t}}}function getSetting(settingName){if(currentSettings!=null&&getType(currentSettings[settingName])!="undefined"){return currentSettings[settingName]}else{return jQuery.modalDialog.displaySettings[settingName]}}function getDialogWidth(){if(getSetting("fullScreen")){return jQuery(window).width()-(getSetting("padding")*2)}else{var width=parseInt(getSetting("width"));if(width<0){width=parseInt(jQuery(dialogSelector).css("width"));if(isNaN(width)||getSetting("usePadding")){width=jQuery(dialogSelector).width()}return width}else{return width}}}function getDialogHeight(){if(getSetting("fullScreen")){return jQuery(window).height()-(getSetting("padding")*2)}else{var height=parseInt(getSetting("height"));if(height<0){height=parseInt(jQuery(dialogSelector).css("height"));if(isNaN(height)||getSetting("usePadding")){height=jQuery(dialogSelector).height()}return height}else{return height}}}function getGrayWidth(){var w=0;w=jQuery(document).width();if(browser.isIE6()){w-=21}return w}function getGrayHeight(){return jQuery(document).height()}function getCenterX(){if(position.x>-1){return position.x+getScrollX()}else{var padLeft=parseInt(jQuery(dialogSelector).css("padding-left"));var padRight=parseInt(jQuery(dialogSelector).css("padding-right"));var pad=0;if(!isNaN(padLeft)){pad+=padLeft}if(!isNaN(padRight)){pad+=padRight}return Math.floor((jQuery(window).width()-getDialogWidth()-pad)/2)+getScrollX()}}function getCenterY(){var y=0;if(position.y>-1){y=position.y+getScrollY()}else{var padTop=parseInt(jQuery(dialogSelector).css("padding-top"));var padBot=parseInt(jQuery(dialogSelector).css("padding-bottom"));var pad=0;if(!isNaN(padTop)){pad+=padTop}if(!isNaN(padBot)){pad+=padBot}y=Math.floor((jQuery(window).height()-getDialogHeight()-pad)/2)+getScrollY()}if(getSetting("dialogAbove")!=null&&jQuery(getSetting("dialogAbove")).offset().top<y+getDialogHeight()){y=jQuery(getSetting("dialogAbove")).offset().top-getDialogHeight();shouldAutoScroll=true}return y}function getScrollX(){var dPos=getSetting("dialogPosition");if(dPos=="absolute"||browser.isIE6()||browser.isIDevice()){return jQuery(document).scrollLeft()}else{return 0}}function getScrollY(){var dPos=getSetting("dialogPosition");if(dPos=="absolute"||browser.isIE6()||browser.isIDevice()){return jQuery(document).scrollTop()}else{return 0}}function getStyle(el,style){return jQuery(el).css(style)}function positionGray(){jQuery(dialogSelector).css({left:getCenterX()+"px",top:getCenterY()+"px",width:getDialogWidth()+"px",height:getDialogHeight()+"px"});jQuery(grayoutDivObj).css({width:getGrayWidth()+"px",height:getGrayHeight()+"px",left:"0px",top:"0px"})}function showDialog(){c.initOpacity();jQuery(grayoutDivObj).css("display","block");jQuery(dialogSelector).css("display","block")}function scrollToCenter(){var b=window.navigator.userAgent.toLowerCase();var jBody=jQuery("html,body");var bodyOffset=0;if(/applewebkit/.test(b)){bodyOffset=document.body.scrollTop}else{if(/opera/.test(b)){bodyOffset=0}else{bodyOffset=document.documentElement.scrollTop}}var elOffset=jBody.find(dialogSelector).offset().top;var winHeight=jQuery(window).height();var centerY=(winHeight-getDialogHeight())/2;var y=elOffset-bodyOffset-centerY;jBody.animate({scrollTop:"+="+y+"px"},"slow",getSetting("easing"))}function c(){}c.exec=function(strFunc){return eval(strFunc)()};c.getGrayoutDivID=function(){return grayoutDivID};c.displaySettings={dialogPosition:"fixed",hideOnClick:true,backgroundColor:"#000000",opacity:0.6,left:-1,top:-1,width:-1,height:-1,show:null,hide:null,onHide:null,fullScreen:false,padding:50,animation:"fadeIn",dialogAbove:null,easing:"swing"};c.refresh=function(){positionGray()};c.setCurrentSetting=function(settingName,settingValue){currentSettings[settingName]=settingValue};c.getCurrentSetting=function(settingName){return getSetting(settingName)};c.showCallback=function(){if(shouldAutoScroll){scrollToCenter()}if(typeof(currentSettings.callback)=="function"){currentSettings.callback()}};c.hideCallback=function(){jQuery(dialogSelector).css("display","none");jQuery(grayoutDivObj).css({display:"none",width:"0px",height:"0px"});if(browser.isIE6()){jQuery("select").each(function(){jQuery(this).css("visibility","visible")})}if(typeof(currentSettings.callback)=="function"){currentSettings.callback()}};c.initOpacity=function(){var opac=getSetting("opacity");jQuery(grayoutDivObj).css("opacity",opac);if(browser.isIE()){grayoutDivObj.filters.alpha.opacity=parseFloat(opac).toFixed(2)*100}};c.show=function(objSelector,appendToNodeSelector,settings){shouldAutoScroll=false;if(dialogSelector!=null&&dialogSelector!=objSelector){jQuery(dialogSelector).css("display","none")}if(settings!=undefined){currentSettings=settings}else{currentSettings=c.displaySettings}position.x=parseInt(getSetting("left"));position.y=parseInt(getSetting("top"));if(appendToNodeSelector!=undefined&&appendToNodeSelector!=null){jQuery(appendToNodeSelector).append(jQuery(objSelector))}if(browser.isIE6()){scrollTop=getScrollY();scrollLeft=getScrollX()}if(grayoutDivObj==null){grayoutDivObj=document.getElementById(grayoutDivID)}jQuery(grayoutDivObj).css({"background-color":getSetting("backgroundColor")});dialogSelector=objSelector;jQuery(dialogSelector).css({"z-index":"99"});if(browser.isIE6()){jQuery(dialogSelector).css("position","absolute");jQuery(grayoutDivObj).css("position","absolute");jQuery("select").each(function(){jQuery(this).css("visibility","hidden")});jQuery(dialogSelector+" > select").each(function(){jQuery(this).css("visibility","visible")})}else{jQuery(dialogSelector).css("position",getSetting("dialogPosition"));jQuery(grayoutDivObj).css("position","fixed")}positionGray();if(getSetting("animation")!=null&&(getType(currentSettings.show)=="undefined"||getType(currentSettings.show)=="null")){switch(getSetting("animation")){case"fadeIn":jQuery.modalDialog.animations.fadeIn(dialogSelector);break;case"expand":jQuery.modalDialog.animations.expand(dialogSelector);break;case"fadeInGrayoutOnly":jQuery.modalDialog.animations.fadeInGrayoutOnly(dialogSelector);break;default:showDialog();break}}else{if(typeof(currentSettings.show)!="undefined"){if(typeof(currentSettings.show)=="function"){currentSettings.show(dialogSelector)}else{showDialog()}}else{if(typeof(this.displaySettings.show)=="function"){this.displaySettings.show(dialogSelector)}else{showDialog()}}}};c.hide=function(settings){if(settings!=undefined){currentSettings=settings}if(getSetting("animation")!=null&&(getType(currentSettings.show)=="undefined"||getType(currentSettings.show)=="null")){switch(getSetting("animation")){case"fadeIn":jQuery.modalDialog.animations.fadeOut(dialogSelector);break;case"expand":jQuery.modalDialog.animations.collapse(dialogSelector);break;case"fadeInGrayoutOnly":jQuery.modalDialog.animations.fadeOutGrayoutOnly(dialogSelector);break;default:this.hideCallback();break}}else{if(typeof(currentSettings.hide)!="undefined"){if(typeof(currentSettings.hide)=="function"){currentSettings.hide(dialogSelector)}else{this.hideCallback()}}else{if(typeof(this.displaySettings.hide)=="function"){this.displaySettings.hide(dialogSelector)}else{this.hideCallback()}}}if(typeof(currentSettings.onHide)=="function"){currentSettings.onHide()}};c.outsideClick=function(){if(currentSettings.hideOnClick!=undefined){if(currentSettings.hideOnClick){this.hide()}}else{if(this.displaySettings.hideOnClick){this.hide()}}};c.attachClickEvent=function(handler){jQuery(grayoutDivObj).bind("click",handler)};c.detachClickEvent=function(handler){jQuery(grayoutDivObj).unbind("click",handler)};jQuery(document).ready(function(){jQuery("body").append('<div id="'+grayoutDivID+'"></div>');jQuery("#"+grayoutDivID).css({position:"fixed",left:"0px",top:"0px",width:"0px",height:"0px",display:"none","z-index":"98","background-color":c.displaySettings.backgroundColor,opacity:c.displaySettings.opacity,filter:"alpha(opacity="+(parseFloat(c.displaySettings.opacity).toFixed(2)*100)+")"});jQuery("#"+grayoutDivID).click(function(){c.outsideClick()});jQuery(window).resize(function(){positionGray()});if(browser.isIE6()){jQuery(window).scroll(function(){if(jQuery("#"+grayoutDivID).css("display")!="none"&&getSetting("dialogPosition")=="fixed"){jQuery(window).scrollLeft(scrollLeft);jQuery(window).scrollTop(scrollTop)}})}});return c})();jQuery.modalDialog.animations={fadeIn:function(a){jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeTo("normal",jQuery.modalDialog.getCurrentSetting("opacity"));jQuery(a).fadeIn("normal",jQuery.modalDialog.showCallback)},fadeOut:function(a){jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeOut("normal");jQuery(a).fadeOut("normal",jQuery.modalDialog.hideCallback)},fadeInGrayoutOnly:function(a){jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeTo("normal",jQuery.modalDialog.getCurrentSetting("opacity"),function(){jQuery(a).css("display","block");jQuery.modalDialog.showCallback()})},fadeOutGrayoutOnly:function(a){jQuery(a).css("display","none");jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeOut("normal",function(){jQuery.modalDialog.hideCallback()})},expand:function(f){jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeTo("normal",jQuery.modalDialog.getCurrentSetting("opacity"));var b=jQuery(f);var c=parseInt(b.css("width"));var a=parseInt(b.css("height"));var e=jQuery.modalDialog.exec("getCenterX");var d=jQuery.modalDialog.exec("getCenterY");b.css({width:"0px",height:"0px",left:(e+Math.floor(c/2))+"px",top:(d+Math.floor(a/2))+"px"});b.animate({width:c,height:a,left:e,top:d},"normal",jQuery.modalDialog.showCallback)},collapse:function(f){jQuery("#"+jQuery.modalDialog.getGrayoutDivID()).fadeOut("normal");var b=jQuery(f);var c=parseInt(b.css("width"));var a=parseInt(b.css("height"));var e=jQuery.modalDialog.exec("getCenterX");var d=jQuery.modalDialog.exec("getCenterY");b.animate({width:0,height:0,left:(e+Math.floor(c/2)),top:(d+Math.floor(a/2))},"normal",function(){b.css({width:c+"px",height:a+"px"});jQuery.modalDialog.hideCallback()})}};
