
/**
 * Deluxe Window
 * @version 1.0
 */
var deluxePopupWindow = {
   
   //Main box
   mainbox        : 'deluxePopupWindow-container', //+Math.random().toString().substr(2),
   
   //Global prefix
   globalprefix   : 'jaw_',
   
   //sidebar postfix
   sidebarpostfix : '_sidebar',
   
   //Active classes
   activeclasses  : {
      handle        : 'jaw_handle',
      header        : 'jaw_header',
      minimize      : 'jaw_minimize',
      fullscreen    : 'jaw_fullscreen',
      close         : 'jaw_close',
      contentarea   : 'jaw_contentarea',
      statusarea    : 'jaw_statusarea',
      resizearea    : 'jaw_resizearea'
   },
   
   //Passiv classes
   passiveclasses : {
      restore       : 'jaw_restore'
   },
   
   //Titles
   titles         : {
      normalization : 'Normalization',
      fullscreen    : 'FullScreen',
      restore       : 'Restore',
      minimize      : 'Minimizar',
      unminimize    : 'Restaurar'
   },
   
   //Errors
   errors         : {
      skinload      : 'Erro! Carregamento da máscara!'
   },
   
   //border for sidebar (px)
   sidebarborder  : 3,
   
   //min Size
   minsize        : {
      'width'       : 150,
      'height'      : 100
   },
   
   //minmized type
   minmizedtype   : 0,
   
   //border for window (correcting)
   offsetborder   : 0,
   
   winminimize    : 0,
   
   //all examples of object
   jaexamples     : [],
   
   //cache control for style files
   connectstyles  : [],
   
   /**
    * Init. Fixing of Load Status
    */
   init:function()
   {
      //add action for page loading
      this.addEvent(window, function(){         

//#ifndef developer
//#ifndef licensed
/*
//#endif
//#ifdef licensed
         //check license
         deluxePopupWindowLicense.check();
//#endif
//#ifndef licensed
*/
//#endif
         
//#ifndef trial
/*
//#endif
//#ifdef trial
         //check license
         //deluxePopupWindowTrialLicense.check();
//#endif
//#ifndef trial
*/
//#endif
//#endif
         
         deluxePopupWindow.isPageloaded = true;
      }, 'load');
      //add action for page scrolling
      this.addEvent(window, function(){deluxePopupWindow.fixed();}, 'scroll');
      //add action for resize window
      this.addEvent(window, function()
      {
         //fullscreen mode adaptation
         for (var i = 0; i < deluxePopupWindow.jaexamples.length; i++){
            var jw = deluxePopupWindow.jaexamples[i];
            if (jw.state == 'fullscreen'){
               jw.nofullscreen = null;
               deluxePopupWindow.fullScreen(jw.fullscreen,jw);
            }
         }
      }, 'resize');
      //set container
      document.write('<div style="left:0px;top:0px;position:absolute;" id="' + deluxePopupWindow.mainbox + '" height="100%" width="100%"><div style="display:none">&nbsp;</div></div>');
   },
   
   /**
    * Open New Window
    * @return obj
    * @param jw object
    * @param contentsource content source
    * @param title title
    * @param attr attributes
    * @param skin skin name
    * @param contype hidden parameter for content type (default - 'auto')
    */
   open:function(jw, contentsource, title, attr, skin, contype)
   {
      // make window
      jw = deluxePopupWindow.make.apply(this,arguments);
      // show window
      jw.show()
      return jw;
   },

  /**
    * Make Window
    * @return obj
    * @param jw object
    * @param contentsource content source
    * @param title title
    * @param attr attributes
    * @param skin skin name
    * @param contype hidden parameter for content type (default - 'auto')
    */
   make:function(jw, contentsource, title, attr, skin, contype)
   {
      //link to deluxePopupWindow
      var d   = deluxePopupWindow;
      
      //content type
      contype = (typeof contype == 'undefined') ? 'auto' : contype;
      
      /**
       * Initialization of Parameters
       * @return object with parameters
       * @param str string
       * @param defaultparams default parameters
       */
      var parametersInit = function(str,defaultparams)
      {
        //array for results
        var result = defaultparams;
        var params = str.split(',');
        for (var i = 0; i < params.length; i++){
          //interpretation value
          if (params[i].indexOf('=') != -1){
            var value = params[i].substr(params[i].indexOf('=')+1);
            if (value == 'yes'){
              value = true;
            }
            else if (value == 'no'){
              value = false;
            }
            result[params[i].substr(0,params[i].indexOf('='))] = value;
          }
          else{
            result[params[i]] = true;
          }
        }
        return result;
      };
      
      //default parameters
      var defaultparams = {
         'resizable'  : true,
         'scrollbars' : true,
         'minimizable': true,
         'closable'   : true,
         'fullscreen' : true,
         'left'       : 0,
         'top'        : 0,
         'floatable'  : true,
         'opacity'    : 1
      };
      
      //get parameters
      var params = parametersInit(attr,defaultparams);
      
      //if doesn't exist
      if (document.getElementById(jw) == null){         
         //create object
         jw = this.create(jw, skin);
      }
      else{
         jw = document.getElementById(jw);
      }
      
      //set default skin
      jw.defaultskin = deluxePopupWindow.globalprefix + 'skin_' + skin;
      
      //unset fullscreen
      if (jw.nofullscreen) deluxePopupWindow.fullScreen(jw.fullscreen,jw);
      
      //setSize
      jw.setSize((params['width'] + 'px'), (params['height'] + 'px'));
      
      //set in px for detail coordinates
      var _shorts = {'left' : ['center','right','left'], 'top' : ['middle','bottom','top']};
      for (var key in _shorts){
        for (var i = 0; i < _shorts[key].length; i++){
            if ( typeof params[ _shorts[key][i] ] != 'undefined' ){
                params[ key ] = ( ( params[ _shorts[key][i] ] === true ) ? _shorts[key][i] : params[ _shorts[key][i] ] + 'px' );
                break;
            }
        }
      }
      //set x, y position
      var xpos = params['left'];
      var ypos = params['top'];
      
      //corrected error
      if (!this.scroll_top) this.scroll_top = 0;
      
      //checking of load status for this page
      if (!deluxePopupWindow.isPageloaded && this.scroll_top == 0){
         
         //if IE (bugfix)
         if (/MSIE /i.test(navigator.userAgent)){
            this.addEvent(window, function(){setTimeout(function(){jw.moveTo(xpos, ypos)}, 400)}, 'load');
         }
         else{
            this.addEvent(window, function(){jw.moveTo(xpos, ypos)}, 'load');
         }
      }
      
      //set resizable
      jw.setResize((params['resizable']?true:false));
      
      //set scrollbars
      jw.setScrolling((params['scrollbars']?true:false));
      
      //set fullscreen
      jw.setFullscreen((params['fullscreen']?true:false));
      
      //set minimizable
      jw.setMinimizable((params['minimizable']?true:false));
      
      //set closable
      jw.setClosable((params['closable']?true:false));
      
      //set floatable
      jw.setFloatable((params['floatable']?true:false));
      
      //set opacity
      jw.defaultopacity = params['opacity'];
      jw.setOpacity(params['opacity']);
      
      //search of effect in parameters
      for (var key in params){
         if (/-effect$/i.test(key)){
            jw.effect = {name : key.substr(0, key.length - '-effect'.length), value : params[key]};
            break;
         }
      }
      
      //visible
      jw.style.visibility          = 'visible';
      jw.contentarea.style.display = 'block';
      
      //displaying
      jw.style.display             = 'block';
      //get parameters
      jw.moveTo(xpos, ypos);
      //hide
      jw.style.display             = 'none';
      //set position
      
      // load
      jw.load(contentsource, title, contype);
      
      //if exists
      if (jw.state == 'minimized'){
         jw.state  = 'fullview';
      }
      
      return jw;
   },

  /**
    * Create Window
    * @return obj
    * @param jw main object
    * @param skin skin name (string)
    */
   create:function(jw,skin)
   {
      //if exists sidebar
      if (!deluxePopupWindow.sidebar){
         
         //create sidebar
         var sidebar = document.createElement('div');
         
         //set name of class
         sidebar.className = deluxePopupWindow.globalprefix + 'skin_' + skin + deluxePopupWindow.sidebarpostfix;
         
         //set border
         sidebar.style.borderWidth = deluxePopupWindow.sidebarborder + 'px';
         
         //add in document
         document.getElementById(deluxePopupWindow.mainbox).appendChild(sidebar);
         
         //save link on global variable
         deluxePopupWindow.sidebar = sidebar;
         
         //create background for sidebar (bug fixed with frames in IE,FF)
         var backsidebar = document.createElement('div');
         
         //set styles for background
         with (backsidebar.style)
         {
            position   = 'absolute';
            width      = '1px';
            height     = '1px';
            top        = '0px';
            left       = '0px';
            display    = 'none';
            background = '#222';
            
            //hide background
            if ((/Firefox/i.test(navigator.userAgent))){
               MozOpacity = '.0';
            }
            else if ((/MSIE /i.test(navigator.userAgent))){
               filter = 'alpha(style=0,opacity=0)';
            }
            else if ((/Safari/i.test(navigator.userAgent))){
               KhtmlOpacity = '0.0';
            }
            else if ((/Opera/i.test(navigator.userAgent))){
               visibility = 'hidden';
            }
         }
         
         //add backsidebar in document
         document.getElementById(deluxePopupWindow.mainbox).appendChild(backsidebar);
         
         //save link on global variable
         deluxePopupWindow.backsidebar = backsidebar;
      }
      
     /**
      * Search Elements (in DOM for Object)
      * @param _obj link to object
      * @param _attribute {String} attribute name
      * @param _sets array with variants
      * @param _results null object; result links on objects
      */
     var searchElements = function(_obj, _attribute, _sets, _results)
     {
       var elms   = _obj.getElementsByTagName('*');
       for (var i = 0; i < elms.length; i++){
         // get all attributes
         for ( var j in _sets ){           
           // check attribute
           if ( elms[ i ][ _attribute ] && elms[ i ][ _attribute ] == _sets[ j ] ){
             _results[ _sets[ j ] ] = elms[ i ];
           }
         }
       }
     };
     
     /**
      * Adding Visual Effects (changing class name)
      * @param obj link to object
      */
     var addVisualEffect = function( obj )
     {
        var events = ['onmouseover','onmouseout','onmousedown','onmouseup'];
        for (var i = 0; i < events.length; i++){
           eval('if (obj[0]) obj[0][events[i]] = function(){deluxePopupWindow.classChanger(this,"' + events[i] + '",obj[1]);};');
        }
     };
      
      //create window
      var domwindow = document.createElement('div');
      //set id
      domwindow.id = jw;
      
      // create design
      domwindow.className = deluxePopupWindow.globalprefix + 'skin_' + skin;
      
      //load skin/styles
      var domwindowdata = deluxePopupWindow.loadSkin(skin);
      //if error in loading skin
      if (domwindowdata == null){
         alert(deluxePopupWindow.errors.skinload);
         return null;
      }
      
      //add skin in window box
      domwindow.innerHTML = domwindowdata;
      
      //adding window
      document.getElementById(deluxePopupWindow.mainbox).appendChild(domwindow);
      
      //z-index control
      this.zIndexvalue = (this.zIndexvalue)? this.zIndexvalue + 1 : 100;
      
      //create link on object
      jw = document.getElementById(jw);
      
      //find active elements
      var _results = {};
      //search elements
      searchElements(jw, 'className', deluxePopupWindow.activeclasses, _results);
      
      //view result
      for (var key in deluxePopupWindow.activeclasses){
         jw[ key ] = ( _results['jaw_' + key] ) ? _results['jaw_' + key] : false;
      }      
      /*
      //view result
      for (var key in _results){
         jw[ key.replace('jaw_', '') ] = _results[key];
      } 
      */     
      //unset result
      _results = null;
      
      //default state
      jw.state = jw.substate = 'fullview';
      
      //store back reference
      jw.handle._parent = jw;
      
      //same
      jw.resizearea._parent = jw;
      
      //special handler for "onclose"
      jw.onclose = function()
      {
         return true;
      };
      
      //increase z-index
      jw.onmousedown = function()
      {
         if (!deluxePopupWindow.currentSelect || deluxePopupWindow.currentSelect != this){
            deluxePopupWindow.zIndexvalue++;
            this.style.zIndex = deluxePopupWindow.zIndexvalue;
            //set active window
            deluxePopupWindow.setActive(this);
         }
      };
      
      if (jw.handle){
      
         //set action for moving
         jw.handle.onmousedown = deluxePopupWindow.startDrag;
         
         //control for select in IE
         if ((/MSIE /i.test(navigator.userAgent))){      
            //disable
            jw.handle.onmouseover = function(){ document.onselectstart = function(){return false;} };
            //enable
            jw.handle.onmouseout  = function(){ document.onselectstart = function(){} };
         }
                     
         //fullscreen mode for double click
         jw.handle.ondblclick = function(e)
         {
            // crossbrowser adapter
            var obj = (typeof event == 'undefined') ? e.target : event.srcElement;

            if ((obj == jw.handle || obj == jw.header) && jw.fullscreenBool){
               deluxePopupWindow.fullScreen(jw.fullscreen, jw);
            }
         };      
      
      }
      
      if (jw.resizearea){

         //set action for resizing
         jw.resizearea.onmousedown = deluxePopupWindow.startDrag;
         
      }
      
      if (jw.minimize){
      
         //add actions for minimize buttons
         addVisualEffect([jw.minimize,deluxePopupWindow.activeclasses['minimize']]);
         
         //add action for buttons
         jw.minimize.onclick = function(){
            if (jw.state != "minimized"){
               deluxePopupWindow.minimize(this, jw);
            }
            else{
               deluxePopupWindow.restore(this, jw);
            }
         };      
      }
      
      if (jw.fullscreen){
         
         //add action of fullscreen
         jw.fullscreen.onclick = function(){         
            deluxePopupWindow.fullScreen(this, jw);
         };
      
      }
      
      if (jw.close){
               
         //add actions for close buttons
         addVisualEffect([jw.close,deluxePopupWindow.activeclasses['close']]);
         
         //add action of close
         jw.close.onclick = function(){
            deluxePopupWindow.close(jw);
         };
      }
      
      //add action for button fullscreen/restore
      var events = ['onmouseover','onmouseout','onmousedown','onmouseup'];
      for (var i = 0; i < events.length; i++){
         eval('jw.fullscreen[events[i]] = function(){deluxePopupWindow.classChanger(this,"' + events[i] + '",((jw.substate == "fullscreen") ? deluxePopupWindow.passiveclasses["restore"] : deluxePopupWindow.activeclasses["fullscreen"]));};');
      };
      
      //show
      jw.show = function()
      {
         deluxePopupWindow.show(this);
      };
      
      //accessibility of fullscreen mode
      jw.setFullscreen = function(bol)
      {
         deluxePopupWindow.setFullscreen(this,bol);
      };
      
      //minimizable
      jw.setMinimizable = function(bol)
      {
         deluxePopupWindow.setMinimizable(this,bol);
      };
      
      //closable
      jw.setClosable = function(bol)
      {
         deluxePopupWindow.setClosable(this,bol);
      };
      
      //floatable
      jw.setFloatable = function(bol)
      {
         deluxePopupWindow.setFloatable(this,bol);
      };
      
      //opacity
      jw.setOpacity = function(opacity)
      {
         deluxePopupWindow.setOpacity(this,opacity);
      };
      
      //hide
      jw.hide = function()
      {
         deluxePopupWindow.close(this);
      };
      
      //set size
      jw.setSize = function(w, h)
      {
         deluxePopupWindow.setSize(this, w, h);
      };
      
      //move
      jw.moveTo = function(x, y)
      {
         deluxePopupWindow.moveTo(this, x, y);
      };
      
      //display resizer
      jw.setResize = function(bol)
      {
         deluxePopupWindow.setResize(this, bol);
      };
      
      //display scrollbar
      jw.setScrolling = function(bol)
      {
         deluxePopupWindow.setScrolling(this, bol);
      };
      
      //load
      jw.load = function(contenttype, contentsource, title)
      {
         deluxePopupWindow.load(this, contenttype, contentsource, title);
      };
      
      //if jaexamples length = 0
      if(!deluxePopupWindow.jaexamples.length){
         window.onunload = deluxePopupWindow.cleaner;
      };
      
      //add this object
      this.jaexamples.push(jw);
      
      return jw;
   },

   /**
    * Load Content
    * @param jw obj
    * @param contentsource content source
    * @param title title
    * @param contype parameter for content type (default - 'auto')
    */
   load:function(jw, contentsource, title, contype)
   {
      //set title
      if (typeof title != 'undefined'){
         jw.header.innerHTML = title;
      }
      
      //prediction of the type content
      if (contype == 'auto'){
         if (contentsource.substr(0,7) == 'http://'){
            var contenttype = 'iframe';
         }
         else if(contentsource.length <= 30 && document.getElementById(contentsource)){
            var contenttype = 'id';
            jw.contentarea.sourceboxid = contentsource;
         }
         else{
            var contenttype = 'text';
         }
      }
      else{
         var contenttype = contype;
      }
            
      //for plain text
      if (contenttype == 'text'){
         jw.contentarea.innerHTML = contentsource;
      }
      //for link on DOM-object
      else if (contenttype == 'id'){
         
         //load content from object
         jw.contentarea.innerHTML = document.getElementById(contentsource).innerHTML;
         
         //hide that object
         document.getElementById(contentsource).style.display = 'none';
      }
      //for iframe
      else if (contenttype == 'iframe')
      {
         //disable scrollbars
         jw.contentarea.style.overflow = 'hidden';
         
         //if iframe doesn't exist
         if (!jw.contentarea.firstChild || jw.contentarea.firstChild.tagName != 'IFRAME'){
            jw.contentarea.innerHTML = '<iframe src="" style="border:0; margin:0; padding:0; width:100%; height: 100%" name="_iframe-' + jw.id + '"></iframe>';}
         
         //set location
         window.frames['_iframe-' + jw.id].location.replace(contentsource);
      }
      
      //store contenttype
      jw.contentarea.datatype = contenttype;
   },

   /**
    * Load Skin
    * @param skin skin name
    * @return windowcode
    */
   loadSkin:function(skin)
   {
      //if not is included
      if (!window[deluxePopupWindow.globalprefix + 'skin_' + skin]){
         return null;
      }
      
      //if style is not added
      if (!deluxePopupWindow.connectstyles[skin]){
         //cache control
         deluxePopupWindow.connectstyles[skin] = true;
         
         //get all SCRIPT-tags
         if (!deluxePopupWindow.scripts_list_cache) deluxePopupWindow.scripts_list_cache = document.documentElement.getElementsByTagName('script');
         var allscripts = deluxePopupWindow.scripts_list_cache;
         
         //path to skin directory
         var path = '';
         
         //restore filename for search
         var file = deluxePopupWindow.globalprefix + 'skin_' + skin + '.js';
         
         //view tags
         for (var i = 0,len = file.length; i < allscripts.length; i++){
            if (allscripts[i].src.substr(allscripts[i].src.length-len,len) == file){
               //restore path
               path = allscripts[i].src.substr(0,allscripts[i].src.length-len);
               break;
            }
         }
         
         //window queue for show() action
         window[deluxePopupWindow.globalprefix + 'skin_' + skin + '_showqueue'] = [];
         
         //run window queue
         var runWindowQueue = function(skin)
         {
            window[skin + '_imgload'] = true;
            while(window[skin + '_showqueue'].length){
               window[skin + '_showqueue'].shift().show();
            }
         };
         
         //load images
         if (window[deluxePopupWindow.globalprefix + 'skin_' + skin + '_images']){
            imagesPreloader.run(
               path,
               window[deluxePopupWindow.globalprefix + 'skin_' + skin + '_images'],
               function(){ runWindowQueue(deluxePopupWindow.globalprefix + 'skin_' + skin); }
            );
         }
         else{
             //using function setTimeout for complete loading of Firefox
             setTimeout(function(){ runWindowQueue(deluxePopupWindow.globalprefix + 'skin_' + skin); }, 300);
         }
      }
      
      //return result
      return window[deluxePopupWindow.globalprefix + 'skin_' + skin];
   },
   
   /**
    * Show
    * @param jw object
    */
   show:function(jw)
   {
      if (window[jw.defaultskin + '_imgload']){
        //show window
        deluxePopupWindow.restore(jw.minimize, jw, 'show');
        jw.onmousedown();
      }
      else{
        window[jw.defaultskin + '_showqueue'].push(jw);
      }
   },

   /**
    * Close
    * @param jw object
    */
   close:function(jw)
   {
      try{
         var closewinbol = jw.onclose();
      }
      catch(err){
         var closewinbol = true;
      }
      finally{
         if (typeof closewinbol == 'undefined'){
            var closewinbol = true;
         }
      }
      
      if (closewinbol){         
         if (jw.state != 'minimized'){
            deluxePopupWindow.saveAttrs(jw);
         }
         if (typeof deluxePopupWindowEffects != 'undefined' && jw.effect && deluxePopupWindowEffects[jw.effect.name]){
            //run hide-effect
            deluxePopupWindowEffects[jw.effect.name].hide(jw, jw.effect.value);
         }
         else{
            jw.style.display = 'none';
         }
      }
      
      //it's focus on nearest window
      for (var i = 0, max = 0, top = -1; i<deluxePopupWindow.jaexamples.length; i++){         
         //all visibles
         if (deluxePopupWindow.jaexamples[i].handle._parent.style.display == 'block'){
            if (max != Math.max(max,parseInt(deluxePopupWindow.jaexamples[i].handle._parent.style.zIndex))){
               top = i;
               max = Math.max(max,parseInt(deluxePopupWindow.jaexamples[i].handle._parent.style.zIndex));
            }        
         }
      }
      
      //restore of hidden div
      if(jw.contentarea.sourceboxid){
         //display
         document.getElementById(jw.contentarea.sourceboxid).style.display = 'block';
      }
      
      //set active window
      if (top >= 0) deluxePopupWindow.setActive(deluxePopupWindow.jaexamples[top].handle._parent);
      return closewinbol;
   },
   
   /**
    * Set Active Window
    * @param jw obj
    */
   setActive:function(jw)
   {
      //unselected window
      if (deluxePopupWindow.currentSelect) deluxePopupWindow.currentSelect.className = deluxePopupWindow.currentSelect.defaultskin;
      
      //selected window header
      jw.className = jw.defaultskin + '-selected';
      
      //save current selected
      deluxePopupWindow.currentSelect = jw;
   },
   
   /**
    * Set Window Size
    * @param jw obj
    * @param w width
    * @param h height
    */
   setSize:function(jw, w, h)
   {
      //set width
      jw.style.width = Math.max(parseInt(w), deluxePopupWindow.minsize.width) + 'px';
      
      //set height
      jw.contentarea.style.height = Math.max(parseInt(h), deluxePopupWindow.minsize.height) + 'px';
      //set width
      jw.contentarea.style.width  = parseInt(jw.style.width) - ((window[jw.defaultskin + '_border_offset']) ? window[jw.defaultskin + '_border_offset'] : 0) + 'px';
   },
   
   /**
    * Move of Window
    * @param jw obj
    * @param x top
    * @param y left
    */
   moveTo:function(jw, x, y)
   {
      //get current parameters
      this.getViewPos();
      
      //set left (center - center)
      switch (x){
        case 'left' :
            jw.style.left = '0px';
            break;
        case 'center' :
            jw.style.left = this.scroll_left + (this.docwidth - jw.offsetWidth)/2 + 'px';
            break;
        case 'right' :
            jw.style.left = this.scroll_left + (this.docwidth - jw.offsetWidth) + 'px';
            break;
        default  :
            jw.style.left = this.scroll_left + parseInt(x) + 'px';
            break;
      }
      
      //set top (middle - center)
      switch (y){
        case 'top' :
            jw.style.top = '0px';
            break;
        case 'middle' :
            jw.style.top = this.scroll_top  + (this.docheight - jw.offsetHeight)/2 + 'px';
            break;
        case 'bottom' :
            jw.style.top = this.scroll_left + (this.docheight - jw.offsetHeight) + 'px';
            break;
        default  :
            jw.style.top = this.scroll_top  + parseInt(y) + 'px';
            break;
      }
      
      if (parseInt(jw.style.top)  < 0) jw.style.top  = '0px';
      if (parseInt(jw.style.left) < 0) jw.style.left = '0px';
      
      //save attrubutes for windows examples
      for (var i = 0; i < deluxePopupWindow.jaexamples.length; i++){
         deluxePopupWindow.saveAttrs(deluxePopupWindow.jaexamples[i]);
      }
   },

   /**
    * Show or Hide Resize Interface
    * @param jw obj
    * @param bol true - show / false - hide
    */
   setResize:function(jw, bol)
   {
      //set visibility
      if (jw.statusarea) jw.statusarea.style.display = (bol)? 'block' : 'none';
      
      //save status visibility
      jw.resizeBool = (bol)? 1 : 0;
   },
   
   /**
    * Show or Hide Scrolling (show - auto mode)
    * @param jw obj
    * @param bol true - show / false - hide
    */   
   setScrolling:function(jw, bol)
   {
      //set style
      jw.contentarea.style.overflow = (bol)? 'auto' : 'hidden';
   },
   
   /**
    * Show or Hide Fullscreen/Restore
    * @param jw obj
    * @param bol true - show / false - hide
    */
   setFullscreen:function(jw, bol)
   {
      //set visibility
      if (jw.fullscreen) jw.fullscreen.style.display = (bol)? 'block' : 'none';
      
      //save status visibility
      jw.fullscreenBool = (bol)? 1 : 0;
   },
   
   /**
    * Minimizable
    * @param jw obj
    * @param bol true - show / false - hide
    */
   setMinimizable:function(jw, bol)
   {
      //set visibility
      if (jw.minimize) jw.minimize.style.display = (bol)? 'block' : 'none';
      
      //save status visibility
      jw.minimizableBool = (bol)? 1 : 0;
   },
   
   /**
    * Closable
    * @param jw obj
    * @param bol true - show / false - hide
    */
   setClosable:function(jw, bol)
   {
      //set visibility
      if (jw.close) jw.close.style.display = (bol)? 'block' : 'none';
      
      //save status visibility
      jw.closableBool = (bol)? 1 : 0;
   },
   
   /**
    * Floatable
    * @param jw obj
    * @param bol true - show / false - hide
    */
   setFloatable:function(jw, bol)
   {
      //save floatable
      jw.floatableBool = (bol)? 1 : 0;
   },
   
   /**
    * Opacity
    * @param opacity opacity [0.0 - 1.0]
    */
   setOpacity:function(jw, opacity)
   {
      //search opacity property
      if (typeof document.body.style.opacity == 'string')
         var property = 'opacity';
      else if (typeof document.body.style.MozOpacity == 'string')
         var property = 'MozOpacity';
      else if (typeof document.body.style.KhtmlOpacity == 'string')
         var property = 'KhtmlOpacity';
      else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+)/)[1]>=5.5)
         var property = 'filter';
      
      //set style
      if (property == "filter"){
        var alpha = jw.filters['DXImageTransform.Microsoft.alpha'] || jw.filters.alpha;
        if (alpha){
           alpha.opacity   = opacity*100;
        }
        else{
           jw.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + (opacity*100) + ")";
        }
      }
      else{
        jw.style[property] = opacity;
      }
      
      //save opacity
      jw.opacity = opacity;
   },
   
   /**
    * StartDrag
    */
   startDrag:function(e)
   {
      //disable select for MS IE
      //if ((/MSIE /i.test(navigator.userAgent))) document.onselectstart = function(){return false;};
      
      //set references
      var d = deluxePopupWindow;
      var jw = this._parent;
      
      // crossbrowser adapter
      var obj = (typeof event == 'undefined') ? e.target : event.srcElement;

      //for fullscreen mode
      if (jw.substate != 'fullscreen' && (obj == jw.handle || obj == jw.header || obj == jw.resizearea) && !(jw.state == 'minimized' && this.className == deluxePopupWindow.activeclasses.resizearea)){
         
         //set cursor
         deluxePopupWindow.sidebar.style.cursor = 'move';
         
         //remember mouse position
         d.etarget = this;
         e = window.event || e;
         
         //store x
         d.initmousex = e.clientX;
         d.initmousey = e.clientY;
         
         //store offsets
         d.initx = parseInt(jw.offsetLeft);
         d.inity = parseInt(jw.offsetTop);
         
         //store width
         d.width = parseInt(jw.offsetWidth);
         
         //store height
         d.contentheight = parseInt(jw.contentarea.offsetHeight);
         
         //get distance
         document.onmousemove = d.getDistance;
         
         //stop
         document.onmouseup = function()
         {
            d.stop(d.etarget);
         };
      }
      
      return false;
   },
   
   /**
    * Get Distance
    */   
   getDistance:function(e)
   {
      var d = deluxePopupWindow;
      
      var etarget = d.etarget;
      
      e = window.event || e;
      
      //display sidebar
      with(deluxePopupWindow.sidebar){
         className = etarget._parent.defaultskin + deluxePopupWindow.sidebarpostfix;
         style.borderWidth = deluxePopupWindow.sidebarborder + 'px';
         style.display = 'block';
      }
      
      //background display
      with (deluxePopupWindow.backsidebar.style){
         width = (window.innerWidth) ? window.innerWidth + 'px' : document.documentElement.clientWidth + 'px';
         height = (window.innerHeight) ? window.innerHeight + 'px' : document.documentElement.clientHeight + 'px';
         display = 'block';
         zIndex = deluxePopupWindow.zIndexvalue + 1;
      }
      
      //horizontal distance
      d.distancex = e.clientX - d.initmousex;
      d.distancey = e.clientY - d.initmousey;
      
      //for "handle"
      if (etarget.className == deluxePopupWindow.activeclasses.handle){
         
         //set parameters for sidebar
         with (deluxePopupWindow.sidebar.style){
            top = etarget._parent.offsetTop + 'px';
            left = etarget._parent.offsetLeft + 'px';
            width = etarget._parent.offsetWidth - deluxePopupWindow.sidebarborder*2 + 'px';
            height = etarget._parent.offsetHeight - deluxePopupWindow.sidebarborder*2 + 'px';
            zIndex = deluxePopupWindow.zIndexvalue + 2;
         }
         d.move(deluxePopupWindow.sidebar, e);
      }
      //for "resize"
      else if (etarget.className == deluxePopupWindow.activeclasses.resizearea){
         
         deluxePopupWindow.sidebar.style.cursor = 'nw-resize';
         
         with (deluxePopupWindow.sidebar.style){
            top = etarget._parent.offsetTop + 'px';
            left = etarget._parent.offsetLeft + 'px';
            width = etarget._parent.offsetWidth - deluxePopupWindow.sidebarborder*2 + 'px';
            height = etarget._parent.offsetHeight - deluxePopupWindow.sidebarborder*2 + 'px';
            zIndex = deluxePopupWindow.zIndexvalue + 2;
         }
         d.resize(etarget._parent,e);
      }
      
      return false;
   },
   
   /**
    * Save Attributes
    * @param jw object
    */
   saveAttrs:function(jw)
   {
      //get current parameters
      this.getViewPos();
      
      //store last coordinations
      jw.lastx = parseInt((jw.style.left || jw.offsetLeft)) - deluxePopupWindow.scroll_left;
      jw.lasty = parseInt((jw.style.top || jw.offsetTop)) - deluxePopupWindow.scroll_top;
      
      //store last width
      jw.lastwidth = parseInt(jw.style.width);
   },
   
   /**
    * Get View Position
    */
   getViewPos:function()
   {
      var ie = (/MSIE /i.test(navigator.userAgent)) ? true : false; //document.all && !window.opera;
      
      var domclientWidth = document.documentElement && parseInt(document.documentElement.clientWidth) || 100000;
      //create reference
      this.standardbody = (document.compatMode == 'CSS1Compat')? document.documentElement : document.body;
      this.scroll_top = (ie)? this.standardbody.scrollTop : window.pageYOffset;
      this.scroll_left = (ie)? this.standardbody.scrollLeft : window.pageXOffset;
      this.docwidth = (ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth - 16);
      this.docheight = (ie)? this.standardbody.clientHeight : window.innerHeight;
   },

   /**
    * Resize
    */
   resize:function(jw, e)
   {
      deluxePopupWindow.sidebar.style.width = Math.max(deluxePopupWindow.width + deluxePopupWindow.distancex, deluxePopupWindow.minsize.width) + 'px';
      deluxePopupWindow.sidebar.style.height = Math.max(deluxePopupWindow.contentheight + deluxePopupWindow.distancey, deluxePopupWindow.minsize.height) + (jw.offsetHeight - parseInt(jw.contentarea.style.height)) + 'px';
   },
   
   /**
    * Move
    */
   move:function(jw, e)
   {
      jw.style.left = deluxePopupWindow.distancex + deluxePopupWindow.initx + 'px';
      jw.style.top = deluxePopupWindow.distancey + deluxePopupWindow.inity + 'px';
   },
   
   /**
    * FullScreen
    * @param button
    * @param jw obj
    */
   fullScreen:function(button, jw)
   {
      //if minimized
      if (jw.state == 'minimized'){
         //restore window
         deluxePopupWindow.restore(jw.minimize, jw);
      }
      
      //for normalization
      if (jw.nofullscreen)
      {
         if (button){
            //restore class name
            button.className = deluxePopupWindow.activeclasses.fullscreen;
            //set attributes
            button.setAttribute('title', deluxePopupWindow.titles.fullscreen);
         }
         //substate - special parameter of fixing state
         //for restore from min.state
         jw.state = jw.substate = 'fullview';
         
         //restire resizer
         if (jw.nofullscreen.resizeBool) jw.setResize(true);
         
         //recovering parameters
         deluxePopupWindow.setSize(jw, jw.nofullscreen.width, jw.nofullscreen.height);
         deluxePopupWindow.moveTo(jw, jw.nofullscreen.x, jw.nofullscreen.y);
         jw.nofullscreen = null;
      } 
      //for fullscreen mode
      else
      {
         if (button){
            //set new class name
            button.className = deluxePopupWindow.passiveclasses.restore;
            //set attributes
            button.setAttribute('title', deluxePopupWindow.titles.normalization);
         }
         jw.state = jw.substate = 'fullscreen';
         //saving old parameters
         jw.nofullscreen = {
            x : parseInt((jw.style.left || jw.offsetLeft)) - deluxePopupWindow.scroll_left,
            y : parseInt((jw.style.top || jw.offsetTop)) - deluxePopupWindow.scroll_top,
            width : parseInt(jw.style.width),
            height : parseInt(jw.contentarea.style.height),
            resizeBool : jw.resizeBool
         };
         
         //hide resizer
         if (jw.resizeBool) jw.setResize(false);         
         
         //get positions
         deluxePopupWindow.getViewPos();

         //set fullscreen
         deluxePopupWindow.setSize(jw, deluxePopupWindow.docwidth - deluxePopupWindow.offsetborder, deluxePopupWindow.docheight - (jw.offsetHeight - parseInt(jw.contentarea.style.height)));
         deluxePopupWindow.moveTo(jw, 0, 0);
      }
   },
   
   /**
    * Minimize
    * @param button
    * @param jw obj
    */
   minimize:function(button, jw)
   {
      deluxePopupWindow.saveAttrs(jw);
      //set title
      button.setAttribute('title', deluxePopupWindow.titles.unminimize);
      
      //hide content
      jw.state = 'minimized';
      jw.contentarea.style.display = 'none';
      //hide statusbar
      //jw.statusarea.style.display = 'none';
      
      //show statusbar
      jw.statusarea.style.display = 'block';
      
      if (typeof jw.winminimize == 'undefined'){
         
         //increment
         deluxePopupWindow.winminimize++;
         jw.winminimize = deluxePopupWindow.winminimize;
      }
      
      //check minmized type 
      if (deluxePopupWindow.minmizedtype){
         
         //set sizes
         jw.style.left = '5px';
         jw.style.width = '220px';
         
         //set position
         var windowspacing = jw.winminimize*10;
         jw.style.top = deluxePopupWindow.scroll_top + deluxePopupWindow.docheight - (jw.handle.offsetHeight*jw.winminimize) - windowspacing + 'px';
      }
   },

   /**
    * Restore
    * @param button
    * @param jw object
    * @param referer referer
    */
   restore:function(button, jw, referer)
   {
      //set referer
      if (typeof referer == 'undefined') referer = '';
      //get positions
      deluxePopupWindow.getViewPos();
      //set title
      if (button) button.setAttribute('title', deluxePopupWindow.titles.minimize);
      
      //displaying
      jw.state = 'fullview';
      //jw.style.display = 'block';
      jw.contentarea.style.display = 'block';
      
      if (jw.statusarea){
         //if resizable
         if (jw.substate == 'fullscreen' || !jw.resizeBool){
            jw.statusarea.style.display = 'none';
         }
         else if (jw.resizeBool){
            jw.statusarea.style.display = 'block';
         }
      }
      
      //check minmized type 
      if (deluxePopupWindow.minmizedtype){         
         //set position
         jw.style.left  = parseInt(jw.lastx) + deluxePopupWindow.scroll_left + 'px';
         jw.style.top   = parseInt(jw.lasty) + deluxePopupWindow.scroll_top + 'px';
         jw.style.width = parseInt(jw.lastwidth) + 'px';      
      }
      
      if (referer == 'show' && typeof deluxePopupWindowEffects != 'undefined' && jw.effect && deluxePopupWindowEffects[jw.effect.name]){
         //run show-effect
         deluxePopupWindowEffects[jw.effect.name].show(jw, jw.effect.value);
      }
      else{
         jw.style.display = 'block';
      }
   },
   
   /**
    * Fixed DeluxeWindow Position for 
    * Browser Scrolling
    */
   fixed:function()
   {
      if (deluxePopupWindow.scroll_delayer) clearTimeout(deluxePopupWindow.scroll_delayer);
      if (deluxePopupWindow.slowlyfixed_delayer) clearTimeout(deluxePopupWindow.slowlyfixed_delayer);
      deluxePopupWindow.scroll_delayer = setTimeout(
         function()
         {
            deluxePopupWindow.getViewPos();
            //access to all windows examples
            for (var i = 0; i < deluxePopupWindow.jaexamples.length; i++){
               //if this window is floatable
               if (deluxePopupWindow.jaexamples[i].floatableBool){
                  //set position               
                  //set left
                  deluxePopupWindow.slowlyfixed(
                     'left',
                     deluxePopupWindow.jaexamples[i],
                     parseInt(deluxePopupWindow.jaexamples[i].style.left),
                     deluxePopupWindow.scroll_left + deluxePopupWindow.jaexamples[i].lastx
                  );
                  //set top
                  deluxePopupWindow.slowlyfixed(
                     'top',
                     deluxePopupWindow.jaexamples[i],
                     parseInt(deluxePopupWindow.jaexamples[i].style.top),
                     deluxePopupWindow.scroll_top + deluxePopupWindow.jaexamples[i].lasty
                  );
               }
            }
         },
         //update frequency
         50
      );
   },
   
   /**
    * Slowly windows fixing
    * @param property property
    * @param jw window example
    * @param start start
    * @param stop stop
    * @param step step
    */
   slowlyfixed:function(property, jw, start, stop, step)
   {
      //step auto calculation
      if (typeof step == 'undefined'){
         var speed = parseInt(Math.abs(start-stop)/30);
         step = (start > stop) ? -speed : speed;
      }
      if ((start > stop && step < 0)||(start < stop && step > 0)){
         start += step;
         if ((start < stop && step < 0)||(start > stop && step > 0)) start = stop;
         //set property
         jw.style[property] = start + 'px';
         deluxePopupWindow.slowlyfixed_delayer = setTimeout(
               function(){ deluxePopupWindow.slowlyfixed(property, jw, start, stop, step) },
               //update frequency
               1
         );
      }
   },
   
   /**
    * Clear Memory
    */
   cleaner:function()
   {
      //unset onload method
      window.onload = null;
      for (var i = 0; i<deluxePopupWindow.jaexamples.length; i++){
         //set null for parent
         deluxePopupWindow.jaexamples[i].handle._parent = deluxePopupWindow.jaexamples[i].resizearea._parent = null;
      }
   },
   
   /**
    * Stop (for Action)
    */
   stop:function()
   {
      if (arguments[0] && deluxePopupWindow.sidebar.style.display == 'block'){
         
         //offset for window border
         var offsetborder = deluxePopupWindow.offsetborder;
         
         //for move
         if (arguments[0].className == deluxePopupWindow.activeclasses.handle){
            
            //set position for moving
            with (arguments[0]._parent.style){
               top = Math.max(deluxePopupWindow.sidebar.offsetTop,0) + 'px';
               left = Math.max(deluxePopupWindow.sidebar.offsetLeft,0) + 'px';
               width = deluxePopupWindow.sidebar.offsetWidth - offsetborder + 'px';
            }
         }
         //for resizing
         else if (arguments[0].className == deluxePopupWindow.activeclasses.resizearea){
            
            //set size for resizing
            deluxePopupWindow.setSize(arguments[0]._parent, deluxePopupWindow.sidebar.offsetWidth - offsetborder, deluxePopupWindow.sidebar.offsetHeight - (arguments[0]._parent.offsetHeight - parseInt(arguments[0]._parent.contentarea.style.height)));
         }
      }
      
      //hide sidebar
      deluxePopupWindow.sidebar.style.display = 'none';
      deluxePopupWindow.backsidebar.style.display = 'none';
      
      //clean up
      deluxePopupWindow.etarget = null;
      document.onmousemove = null;
      document.onmouseup = null;
      
      //save attributes for windows examples
      for (var i = 0; i < deluxePopupWindow.jaexamples.length; i++){
         deluxePopupWindow.saveAttrs(deluxePopupWindow.jaexamples[i]);
      }
   },

   /**
    * Add Event for Object
    * @param target object 
    * @param functionref action
    * @param tasktype type
    */
   addEvent:function(target, functionref, tasktype)
   {
      tasktype = (window.addEventListener)? tasktype : 'on' + tasktype;
      if (target.addEventListener){
         target.addEventListener(tasktype, functionref, false);
      }
      else if (target.attachEvent){
         target.attachEvent(tasktype, functionref);
      }
   },
   
   /**
    * Class Changer (mouseover, mousedown)
    * @param _obj object
    * @param method_name {String} method name
    * @param defaultclass {String} default class name
    */
   classChanger:function( _obj, methodname, defaultclass )
   {
      switch ( methodname ){
         
         case 'onmouseup':
         case 'onmouseover':
           _obj.className = defaultclass + '-' + 'onmouseover';
           break;
         case 'onmouseout':
           _obj.className = defaultclass;
           break;
         case 'onmousedown':
           _obj.className = defaultclass + '-' + methodname;
           break;
      }     
    },

   /**
   *  add skin script function - call it before use one
   */
   addSkin: function(skinFile){
      document.write('<scr'+'ipt src="'+skinFile+'.js"></scr'+'ipt>');
      document.write('<link rel="stylesheet" href="'+skinFile+'.css" type="text/css" />');
   },


   /**
   * Attach function opening and closing window to some event
   */
   attachToEvent:function(win, actionParam){
      var openScript = 'document.getElementById(\''+win.id+'\').show()';

      var onePerSession = /onePerSession/i.test(actionParam);
      var params;
      var regexp_params = /(\w+)(\s*=\s*(\w+))?/g;
      while (params = regexp_params.exec(actionParam)){
         if ((params[1]=='openAfter') && (params.length > 1)) {

            function setCookie(name, value, expires, path, domain, secure){
                  document.cookie = name + "=" + escape(value) +
                    ((expires) ? "; expires=" + expires : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
            };

            function getCookie(name) {
               var cookie = " " + document.cookie;
               var search = " " + name + "=";
               var setStr = null;
               var offset = 0;
               var end = 0;
               if (cookie.length > 0) {
                  offset = cookie.indexOf(search);
                  if (offset != -1) {
                     offset += search.length;
                     end = cookie.indexOf(";", offset);
                     if (end == -1) {
                        end = cookie.length;
                     };
                     setStr = unescape(cookie.substring(offset, end));
                  }
               }
               return(setStr);
            };
            
            if (onePerSession){
               if (getCookie('dpw'+win.id+'run')) return;
               setCookie('dpw'+winID+'run', 1)
            };

            if (!params[3])
               eval(openScript);
            else
               setTimeout(openScript, params[3]*1000);
         }
         else if ((params[1]=='closeAfter') && (params.length > 1)){
            setTimeout('document.getElementById(\''+ win.id +'\').hide()', params[3]*1000);
         }
         else if ((params[1]=='onClick') && (params.length > 1)){
            var e = document.getElementById(params[3]);
            if(e) this.addEvent(e, function (){eval(openScript)}, 'click')
         }
         else if ((params[1]=='onMouseOver') && (params.length > 1)){
            var e = document.getElementById(params[3]);
            if(e) this.addEvent(e, function (){eval(openScript)}, 'mouseover')
         }
         else if ((params[1]=='onMouseOut') && (params.length > 1)){
            var e = document.getElementById(params[3]);
            if(e) this.addEvent(e, function (){eval(openScript)}, 'mouseout')
         }
      }

   }
};

//#ifdef licensed
/**
 * Object. License checker
 * for deluxePopupWindow
 */
var deluxePopupWindowLicense = {
   
   /**
    *  Check license.
    *  Short description: checking of key and
    *  key1, key2 ... key90 for miscellaneous-
    *  es domains and checking copyright
    *  (back link to author site in NOSCRIPT-
    *  tag).
    *
    *                   *
    *         false     |     true
    *         +---<VALID KEY>----+
    *         |                  |
    *   [INCORRECT KEY] +-<VALID COPYRIGHT>-+
    *         |         |                   |
    *         | [INCORRECT COPYRIGHT]       |
    *         |         |                   |
    *         +---------+-------------------+
    *                   |
    *                   O
    *
    *                           simple scheme
    */
   check : function()
   {
       // 'jgx' => 'key'
       var k = k_ = this.decodeString('jgx'), copyOk = 1;
       // var h = location.host;
       eval('var h=' + this.decodeString('mmbcuknl/jnqu') + ';');
       // checking this domain
       // var mainhost = (h == 'deluxepopupwindow.com');
       eval(this.decodeString('wcs"lchlimrv!?!*i"<?!%egmwygqmqwquhlemv,bml%(9'));
       if (!mainhost){
          // checking all 90 keys
          for (var i = 1; i<90 && window[k]; i++){
              // check key
              if (1 || this.checkKey(h, window[k])){
                  // check copyrights in <noscript> tag
                  copyOk = this.checkCopyrights();
                  i      = 0;
                  break;
              }
              k = k_ + i;
          }
       }
       if (i){
           //"Incorrect&nbsp;Key";
           this.writeBox("Koanpsgbv'lcqq9Jgx");
       }
       else if (!copyOk){
           //"Incorrect&nbsp;Copyright";
           this.writeBox("Koanpsgbv'lcqq9Bmq{skfju");
       }
   },

   /**
    *  Write message ( for incorrect key and incorrect copyright )
    *  @param s string for display
    */
   writeBox : function(s)
   {
       document.getElementById(deluxePopupWindow.mainbox).innerHTML += this.decodeString(
           //'<div id="pwgk" style="z-index:2000;visibility:visible;display:block;padding:3px;font:bold 11px Arial;background-color:#F5C4BE;position:absolute;margin:10px;"><a href="http://deluxepopupwindow.com">'
           '=fht!ke?#rvej !qu{mg< {/hlegy83212:thqh`hnhvx8wkrkcnd9ekrrmcx8cnnaj9qcefhlf82ry9gmov;`nne"03qz!Csk`n:``ajesmtle/bmmms8"D4A5@D9qmrkuknl;ccqnntvd9lcsehl;31ry9#<=c!jsgg?#juvq8.-egmwygqmqwquhlemv,bml ?' +
           s +
           //'</a></div>'
           '>.c?>.fht?'
       );
   },

   /**
    *  Decode string
    *  @return decoded string
    *  @param s encoded string
    */
   decodeString : function(s)
   {
     var ds     = '';
     for (var i = 0; i < s.length; i++) ds += String.fromCharCode(s.charCodeAt(i)^(1+i%2));
     return ds;
   },

   /**
    *  Check copyrights.
    *  Short description: scaning all NOSCRIPT-tags and
    *  search of copyright (back-link)
    *  @return search status (boolean)
    */
   checkCopyrights : function()
   {
     // var regex   = /<p>\s*<a href="http:\/\/deluxepopupwindow.com\/*">\s*Javascript\s+Popup\s+Window\s+by\s+DeluxePopupWindow.com\s*<\/a>\s*<\/p>/igm;
     eval(this.decodeString('wcs"sgfgy"!"<".>q<]q+>`"ipdd< ivur;^.^.fdntzdrnrtrvkofnu/ano]-+ ?^r(Kcwcraskqv]q*Rnrtr]q*Uhlemv^r)c{]q*FdntzdRnrtrVkofnu/ano]q+>]-`<]q+>]-q<.kfo:'));
     // check innerHTML attribute ('pwSup')
     var ns = document.getElementById(this.decodeString('quRwq'));
     // not support innerHTML window['_nos']
     if (!ns || !ns.innerHTML || window[this.decodeString('^lnq')]) return 1;
     // 'ns = document.getElementsByTagName("NOSCRIPT")'
     eval(this.decodeString('oq!?!fnatodlu,fguGmglgovr@xV`eOclg) OMRASKQV#+'));
     // scaning all NOSCRIPT-tags
     for (var i = 0; i < ns.length; i++){
       var nsHTML = ns[i].innerHTML.toLowerCase().split('&lt;').join('<').split('&gt;').join('>');
       if ( regex.test(nsHTML) ){
           return 1;
       }
     }
     return 0;
   },

   /**
    *  Check license key
    *  @return result of check (boolean)
    *  @param host host name
    *  @param key product key
    */
   checkKey : function(host, key)
   {
      host   = host.toLowerCase();
      // for '147b754exwp' => 147 => (147 - 111)/2 - 11 => 7
      var num_1 = ( key.substring(0, key.indexOf('b')) - 111 )/2 - 11;
      if ( num_1 < 0 ) return 0;

      // for '147b754exwp' => 754
      var num_2 = key.substring( key.indexOf('b')+1, key.indexOf('e') );
      // if host length >= num_1 and ( key contains 'tg' or 'wp' )
      if ( host.length >= num_1 && (key.indexOf('t'+'g') != -1 || key.indexOf('w'+'p') != -1) ){
          for (var j = 0; j < host.length - num_1 + 1; j++){
              var sum = 0;
              // summing of  the chars code from host
              for (var i = j; i < num_1 + j; i++) sum += host.charCodeAt(i);
              // control checking
              if  (num_2 == sum + 11) return 1;
          }
      }
      return 0
   },
   
   /** init */
   init : function()
   {
      /** add NOSCRIPT tag for checking of noscript.innerHTML support */
      // '<noscript id="pwSup">DeluxePopupWindow.com</noscript>'
      document.write(this.decodeString('=lnqbphru"hf< quRwq ?FdntzdRnrtrVkofnu/ano=-omraskqv?'));
   }
};

//deluxePopupWindowLicense init 
deluxePopupWindowLicense.init();
//#endif

//#ifdef trial
/**
 * Object. Trial License
 * for deluxePopupWindow
 */
var deluxePopupWindowTrialLicense = {
   
   /**
    *   Check license.
    *   Short description: checking this
    *   domain and display 'Trial Version'
    *   for not author domain
    */
   check : function()
   {
      // var h = location.host;
       eval('var h=' + this.decodeString('mmbcuknl/jnqu') + ';');
       // checking this domain
       // var mainhost = (h == 'deluxepopupwindow.com');
       eval(this.decodeString('wcs"lchlimrv!?!*i"<?!%egmwygqmqwquhlemv,bml%(9'));
       if (!mainhost){
          //'Trial&nbsp;version'
          this.writeBox(this.decodeString('Uphcm$o`rr:tdprknl'));
       }
   },
   
   /**
    *  Write message ( for incorrect key and incorrect copyright )
    *  @param s string for display
    */
   writeBox : function(s)
   {
       //'<div id="pwgk" style="z-index:2000;visibility:visible;display:block;padding:3px;font:bold 11px Arial;background-color:#F5C4BE;position:absolute;margin:10px;"><a href="http://deluxepopupwindow.com">'
       document.getElementById(deluxePopupWindow.mainbox).innerHTML += this.decodeString('=fht!ke?#rvej !qu{mg< {/hlegy83212:thqh`hnhvx8wkrkcnd9ekrrmcx8cnnaj9qcefhlf82ry9gmov;`nne"03qz!Csk`n:``ajesmtle/bmmms8"D4A5@D9qmrkuknl;ccqnntvd9lcsehl;31ry9#<=c!jsgg?#juvq8.-egmwygqmqwquhlemv,bml ?') +
           s + this.decodeString('=-`<=-ekw<'); //'</a></div>'
   },
   
   /**
    *  Decode string
    *  @return decoded string
    *  @param s encoded string
    */
   decodeString : function(s)
   {
     var ds     = '';
     for (var i = 0; i < s.length; i++) ds += String.fromCharCode(s.charCodeAt(i)^(1+i%2));
     return ds;
   }
};
//#endif

//deluxePopupWindow init 
deluxePopupWindow.init();

/**
 * Object. Preloading images and
 * run user callback
 */
var imagesPreloader = {
      
   /** images queue */
   queue   : [],
   
   /** defaults values */
   defauls : { timeout : 5000 },
   
   /**
    * Run
    * @param prefix images prefix
    * @param images images array
    * @param callback user callback
    * @param timeout timeout (default = defauls.timeout, 0 - for without limit)
    */
    run    : function(prefix, images, callback, timeout)
    {
      if (typeof timeout == 'undefined') timeout = imagesPreloader.defauls.timeout;
      var index = imagesPreloader.queue.length;
      imagesPreloader.queue[index] = {buffer : [], count : images.length, counter : 0, method : callback};
      if (images.length  == 0){
         imagesPreloader.increment(index, true);
      }
      else{
         for (var i = 0; i < images.length; i++){
            imagesPreloader.queue[index].buffer[i]        = new Image();
            imagesPreloader.queue[index].buffer[i].onload = function(){ imagesPreloader.increment(index) };
            imagesPreloader.queue[index].buffer[i].src    = prefix + images[i];
         }
         if (timeout){
            imagesPreloader.queue[index].timer = setTimeout(
               function(){ imagesPreloader.increment(index, true); },
               timeout
            );
         }
      }
    },
      
    /**
     * Increment
     * @param index index
     * @param stop stop (true/false)
     */
    increment: function(index, stop)
    {
      if (typeof stop == 'undefined') stop = false;
      if (imagesPreloader.queue[index]){
         imagesPreloader.queue[index].counter++;
         if (stop || imagesPreloader.queue[index].counter == imagesPreloader.queue[index].count){
            if (imagesPreloader.queue[index].timer){ clearTimeout(imagesPreloader.queue[index].timer); }
            imagesPreloader.queue[index].method();
            imagesPreloader.queue[index] = false;
         }
      }
    }
};

/**
 *   DeluxePopupWindows Effects Library
 *   for show/hide action.
 *   (using fadeProperty object)
 */
var deluxePopupWindowEffects = {
   
   /**
    * name: Fade
    * description: Slowly changing transparencies for window
    */
   'fade' : {
      'speed' : 0.03,
      'show'  : function(win){
         win.setOpacity(0);
         win.style.display = 'block';
         var ef = fadeProperty.add({
            name   : win.id,
            method : function(opacity){win.setOpacity(opacity);}, 
            start  : 0, 
            stop   : parseFloat(win.defaultopacity),
            step   : deluxePopupWindowEffects['fade']['speed']
         });
         ef.run();
      },
      'hide'  : function(win){
         var ef = fadeProperty.add({
            name      : win.id,
            method    : function(opacity){win.setOpacity(opacity);}, 
            backmethod: function(){win.style.display = 'none';}, 
            start     : parseFloat(win.defaultopacity), 
            stop      : 0,
            step      : -deluxePopupWindowEffects['fade']['speed']
         });
         ef.run();
      }
   },
   
   /**
    * name: Move
    * description: Slowly move window from left|top|bottom|right to final position and back
    * author note: requires to optimization - surplus use deluxePopupWindow['scroll_'+result.position]
    */
   'move' : {
      'divisor'       : 50,
      'interpretation': function(win,position){
         win.style.display = 'block';
         deluxePopupWindow.getViewPos();
         var width  = win.offsetWidth;
         var height = win.offsetHeight;
         win.style.display = 'none';
         var result;
         switch (position){
            case 'left':
               result = {parameter : 'x', position : 'left', start : deluxePopupWindow.scroll_left - width, step : 1 };
               break;
            case 'right':
               result = {parameter : 'x', position : 'left', start : deluxePopupWindow.scroll_left + deluxePopupWindow.docwidth  + width, step  : -1 };
               break;
            case 'bottom':
               result = {parameter : 'y', position : 'top',  start : deluxePopupWindow.scroll_top  + deluxePopupWindow.docheight + height, step : -1 };
               break;
            //case 'top':
            default:
               result = {parameter : 'y', position : 'top',  start : deluxePopupWindow.scroll_top  - height, step : 1 };
               break;
         }
         result.step  = result.step * parseInt(Math.abs(result.start - (deluxePopupWindow['scroll_'+result.position] + win['last'+result.parameter]))/deluxePopupWindowEffects['move']['divisor']);
         return result;
      },
      'show'          : function(win,position){
         var params = deluxePopupWindowEffects['move']['interpretation'](win,position);
         win.style[params.position] = params.start + 'px';
         win.style.display = 'block';
         var ef     = fadeProperty.add({
            name      : win.id,
            method    : function(value){win.style[params.position] = value + 'px';}, 
            start     : params.start, 
            stop      : deluxePopupWindow['scroll_'+params.position] + win['last'+params.parameter],
            step      : params.step
         });
         ef.run();
      },
      'hide'          : function(win,position){
         var params = deluxePopupWindowEffects['move']['interpretation'](win,position);
         win.style[params.position] = deluxePopupWindow['scroll_'+params.position] + win['last' + params.parameter] + 'px';
         win.style.display = 'block';
         var ef     = fadeProperty.add({
            name      : win.id,
            method    : function(value){win.style[params.position] = value + 'px';},
            backmethod: function(){win.style.display = 'none';}, 
            start     : deluxePopupWindow['scroll_'+params.position] + win['last'+params.parameter], 
            stop      : params.start,
            step      : -1 * params.step
         });
         ef.run();
      }
   }
   
};
/**
 * Object. fadeProperty
 * Purpose: slowly changing property from start value to stop
 */
 var fadeProperty = {

   /** all rules */
   rules : [],

   /**
    * Add Rule
    * @param parameters object with parameters
    * attributes: method, backmethod, start, stop, step, delay
    * default values: delay = 1, step = -1/1
    */
    add   : function(parameters)
    {
      if (!parameters.delay)  parameters.delay = 1;
      if (!parameters.step)   parameters.step  = (parameters.start < parameters.stop) ? 1 : -1;
      if (parameters.method instanceof Function){
         parameters.status   = '';
         parameters.defaults = {start : parameters.start, stop : parameters.stop, step : parameters.step};
         parameters.remove   = function(){ fadeProperty.remove(this); };
         parameters.run      = function(){ fadeProperty.run(this); };
         parameters.rever    = function(){ fadeProperty.rever(this); };
         parameters.restore  = function(){ fadeProperty.restore(this); };
         parameters.set      = function(sets){ fadeProperty.set(this,sets); };
         var rule            = false;
         if (parameters.name && ( rule = fadeProperty.rule(parameters.name) )){
            rule = parameters;
         }
         else{
            fadeProperty.rules.push(parameters);
         }
         return parameters;
      }
      else
         return {};
    },

   /**
    * Remove Rule
    * @param rule rule
    */
    remove : function(rule)
    {
      for (var i = 0; i < fadeProperty.rules.length; i++){
         if (fadeProperty.rules[i] == rule){
            fadeProperty.rules.splice(i,1);
            rule = false;
            break;
         }
      }
    },

   /**
    * Run Rule
    * @param rule rule
    */
    run : function(rule)
    {
      rule.method(rule.start);
      rule.start += rule.step;
      if ((rule.step > 0 && rule.start > rule.stop)||
       (rule.step < 0 && rule.start < rule.stop)) rule.start = rule.stop;
      if (rule.start != rule.stop){
         setTimeout( 
            function()
            {
               fadeProperty.run(rule);
            },
            rule.delay
         );
      }
      else{
         setTimeout(function(){rule.method(rule.stop);},rule.delay);
         if ('rever' != rule.status && rule.backmethod){
            if ('rever' == rule.backmethod) rule.backmethod = rule.rever;
            rule.restore();
            rule.backmethod(rule);
         }
         else{
            rule.restore();
         }
      }
    },

   /**
    * Rule Rever
    * @param rule rule
    */
    rever : function(rule)
    {
      rule.start  =  rule.defaults.stop;
      rule.stop   =  rule.defaults.start;
      rule.step   = -rule.defaults.step;
      rule.status = 'rever';
      rule.run();
    },

   /**
    * Rule Restore
    * @param rule rule
    */
    restore : function(rule)
    {
      rule.start  = rule.defaults.start;
      rule.stop   = rule.defaults.stop;
      rule.step   = rule.defaults.step;
      rule.status = '';
    },

   /**
    * Search Rule for Name (public method)
    * @return rule
    * @param name rule name
    */
    rule    : function(name)
    {
      if (name == '') return false;
      for (var i = 0; i < fadeProperty.rules.length; i++){
         if (fadeProperty.rules[i].name && fadeProperty.rules[i].name == name){
            return fadeProperty.rules[i];
         }
      }
      return false;
    },

   /**
    * Set Rule Properties
    * @param rule rule
    * @param properties properties
    */
    set      : function(rule, properties)
    {
      for (var key in properties){
         if ('defaults' == key){
            fadeProperty.set(rule[key], properties[key]);
         }
         else{
            rule[key]  = properties[key];
         }
      }
   }
};
