﻿
(function()
{if(typeof window.top.Cuke.Modal==='undefined')initCukeModal();if(window!=window.top)Cuke.Modal=window.top.Cuke.Modal;function initCukeModal()
{var _currentHost;window.top.Cuke.Modal={};Cuke.apply(window.top.Cuke.Modal,{getCurrentHost:function()
{if(!_currentHost)_currentHost=newWindowHost();return _currentHost;},enter:function(url,options,sharedObject)
{_currentHost=this.getCurrentHost().enterModal(url,options,sharedObject);return this.getCurrentHost();},leave:function()
{_currentHost=this.getCurrentHost().leaveModal();},defaults:{onLeave:Cuke.emptyFunction,title:'',size:null,prefSize:[800,400],skin:"std"}});function newWindowHost(url,options,sharedObject)
{return new _WindowHost();function _WindowHost()
{var _url=url;var _options=Cuke.apply({},options,Cuke.Modal.defaults);var _sharedObject=sharedObject;var _nextHostFactory=newDialogHost;var _prefSize=null;this.enterModal=function(url,options,sharedObject)
{var host;if(_nextHostFactory)host=_nextHostFactory(this,url,options,sharedObject);else host=newDialogHost(this,url,options,sharedObject);return host;};this.leaveModal=function()
{return this;};this.getPrevHost=function()
{return null;};this.getSharedObject=function()
{return _sharedObject;};this.setNextHostFactory=function(nextHostFactory)
{_nextHostFactory=nextHostFactory;};this.getNextHostFactory=function()
{return _nextHostFactory;};this.setTitle=function(title)
{document.title=title;};this.getTitle=function()
{return document.title;};this.setPreferedSize=function(size)
{};this.getPreferedSize=function()
{return[0,0];};}}
function newDialogHost(prevHost,url,options,sharedObject)
{return new _DialogHost(prevHost,url,options,sharedObject);function _DialogHost(prev,url,options,sharedObject)
{var _self=this;var _url=url;var _options=Cuke.apply({},options,Cuke.Modal.defaults);var _sharedObject=sharedObject;var _prevHost=prev;var _nextHostFactory=newDialogHost;var _prefSize=null;var _window;_window=Cuke.Window.loadiframe(url,{modal:true,unloadOnHide:true,onClose:function(t){Cuke.Modal.leave();},skin:_options.skin,title:_options.title,size:_options.size});this.enterModal=function(url,options,sharedObject)
{var host;if(_nextHostFactory)host=_nextHostFactory(_self,url,options,sharedObject);else host=newDialogHost(_self,url,options,sharedObject);return host;};this.leaveModal=function()
{_window.hide();if(_options.onLeave)_options.onLeave(_sharedObject,this);return this.getPrevHost();};this.getPrevHost=function()
{return _prevHost;};this.getSharedObject=function()
{return _sharedObject;};this.setPreferedSize=function(size)
{if(_prefSize==null)
{_window.resize(size[0],size[1]);}
return _prefSize=[size[0],size[1]];};this.getPreferedSize=function()
{return _prefSize;};this.setTitle=function(title)
{if(_window)_window.setTitle(title);};this.getTitle=function()
{if(_window)return _window.getTitle(title);};this.setNextHostFactory=function(nextHostFactory)
{_nextHostFactory=nextHostFactory;};this.getNextHostFactory=function()
{return _nextHostFactory;};};};}
jQuery(function()
{jQuery("a.cuke-modal").click(function()
{Cuke.Modal.enter(jQuery(this).attr('href'),{title:jQuery(this).attr('title')});return false;});});})();