title: JQuery plugin, Javascript - How create only  for JQuery plugin global variable, or json object and change this (variable, object) in function level
body: <p>I use JQuery : 1.6.4</p>
  
  <p>My target it's create function who, without giving varabiles in (), can start and stop Script.</p>
  
  <p>When i tried reach.. target.. I was found a few problems...</p>
  
  <ol>
  <li><p>Specyfic variable\s only for JQuery plugin, with acces from funcions (change variables)</p></li>
  <li><p>functions move_text</p></li>
  </ol>
  
  <p>Result for div 190px , and distance 2.5px</p>
  
  <p>190, 187.5, 190... We can.. se fault change of global variable</p>
  
  <p>Should be 190, 187.5, 185...</p>
  
  <p>How resolve this problem (JSON ? Window)?</p>
  
  <p>I tried way with JSON, object... but... i waste a lot of time.. And nothing find...</p>
  
  <p>So.. Way with window['distance_iv'] is Good?</p>
  
  <p>Here is my code :</p>
  
  <pre><code>$.fn.emulate_marquee = function( options ) {
  
      var settings = {
        'ob_name': '', // object who we use...
        'direction': 'left', 
        'scroll_amount': 100, 
        'delay': 25 // Animation speed
      };
  
      //call in the default otions
              options = $.extend(settings, options);
  
              return this.each(function(options) {
  
  
  
                  var object = $(settings.ob_name);
                  window['distance_ob'] = width = object.width(); 
  
                  //object.css(settings.direction , width + 'px'); // Set Width
                  //alert(width);
  
                  total_width  = (2 * width) / settings.scroll_amount;
                  // total_width
  
                  settings.distance = settings.scroll_amount / (1000/ settings.delay); // Calculate distance for one frame
  
                  width_s = screen.width; // Get screen width
  
  
  
  
                 next_obj = setTimeout (function(){ 
                              move_text()
                            }, 1);
  
                 /*next_res = setTimeout (function(){ 
                              resolution_ch()
                            }, 1);
  
                  */
  
                  var move_text = function()
                  {
                      //alert((settings.width - (i * settings.scroll_amount)) + 'px');
  
                      alert(window['distance_ob'] + 'px');
                      window['distance_ob'] -= settings.distance;
                      object.css(settings.direction , window['distance_ob'] + 'px');
                      alert(window['distance_ob'] + 'px');
  
  
                      if (window['distance_ob'] &lt; total_width)
                      {
                          next_obj = setTimeout (function(){ 
                              move_text()
                          }, settings.delay); 
                      }
                      else
                      {
                         next_obj = setTimeout (function(){ 
                              move_text()
                          }, settings.delay);
                          window['distance_ob'] = width;
                      }
  
                  }
  
                  var resolution_ch = function()
                  {
                      if (screen.width != width_s)
                      {
                          // change varabiales... for new resolution
  
                          width_s =  screen.width;
                          distance_ob = width = object.width();
                          alert(width_s + ' ' + object.width());
                          total_width  = (2 * width) / settings.scroll_amoun;
  
  
                          alert("Detected Change resolution.... nuke in 5 second... started...");
  
                      }
  
                      next_res = setTimeout (function(){ 
                                  resolution_ch()
                                 }, 1000);
  
  
  
                  }
  
  
              });
    };
  </code></pre>