/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 zondag 2 maart 2008 22:17:25
 HAPedit 3.1.11.111
 - - - - - - - - - - - - - - - - - - - - - - - */

/*
 function setMenuTicker(datafile, target, delayvalue){
     if (!$(target)) exit;
     var req = new Request({
        url: datafile,
        onSuccess: function(txt){
           $(target).set('html', txt);
           menuticker=new Ticker(target,{speed:3000,delay:delayvalue,direction:'vertical'});
        }
    });
    req.send();
 }
 */
 /*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/

  function setMenuTicker(datafile, target, delayvalue){
     if (!$(target)) exit;

    var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", datafile,true);//method, target, async (set always true!)
        xmlhttp.onreadystatechange=function() {
           if (xmlhttp.readyState==4) {
             $(target).set('html',xmlhttp.responseText);
             menuticker=new Ticker(target,{speed:3000,delay:delayvalue,direction:'vertical'});
           }
       }
    xmlhttp.send(null);
 }

 var Ticker = new Class({
          Implements: [Options],
  
          options: {
               speed: 1000,
               delay: 5000,
               direction: 'horizontal',
               onComplete: Class.empty,
               onStart: Class.empty
                },
                /*
                setOptions: function(options) {
                    this.options = Object.extend({
                        speed: 1500,
                        delay: 5000,
                        direction: 'horizontal',
                        onComplete: Class.empty,
                        onStart: Class.empty
                    }, options || {});
                }, */
                initialize: function(el,options){
                    this.setOptions(options);
                    this.container = $(el);
                    this.timer=null;
                    this.items = this.container.getElements('li');
                    var w = 0;
                    var h = 0;
                    if(this.options.direction.toLowerCase()=='horizontal') {
                        h = this.container.getSize().y;
                        this.items.each(function(li,index) {
                            w += li.getSize().x;
                        });
                    } else {
                        w = this.container.getSize().x;
                       this.items.each(function(li,index) {
                            h += li.getSize().y;
                        });
                    }
                       if(this.options.direction.toLowerCase()=='horizontal') {
                         this.container.setStyles({
                           position: 'absolute',
                           top: 0,
                           left: 0,
                           width: w,
                           bottom: 0
                         });
                       } else {
                         this.container.setStyles({
                           position: 'absolute',
                           top: 0,
                           left: 0,
                           right: 0
                         });
                       }
                       this.fx = new Fx.Morph(this.container,{duration:this.options.speed,onComplete:function() {
                           var i = (this.current==0)?this.items.length:this.current;
                           this.items[i-1].injectInside(this.container);
                           this.container.setStyles({
                                 left: 0,
                                 top:0
                          });
                       }.bind(this)});
                      // this.addMouseEvents();
                       this.current = 0;
                       this.next.bind(this).delay(this.options.delay);
                },
                addMouseEvents: function(){
                  this.container.addEvents({
                  'mouseenter': function(me){
                     this.container.setStyle('cursor','not-allowed');
                     this.clearTimer();
                     this.fx.stop(0);
                     }.bind(this),
                  'mouseleave': function(me){
                      this.resume();
                  }.bind(this)
               });
               },
               // stopTicker: function(){
               //   this.clearTimer();
               //   this.container.removeEvents();
               //},
               resume: function(){
                // this.stopTicker();
                // this.addMouseEvents();
                // this.fx.start();
                 //this.next();
                  var pos = this.items[this.current];
                    if ($(pos.parentNode)){
                       this.fx.start({
                           top: -pos.offsetTop,
                           left: -pos.offsetLeft
                       });
                       this.timer=this.next.bind(this).delay(this.options.delay+this.options.speed);
                    } else this.fx.stop(0);
                },
                next: function() {
                    this.current++;
                    if (this.current >= this.items.length) this.current = 0;
                    var pos = this.items[this.current];
                    if ($(pos.parentNode)){
                       this.fx.start({
                           top: -pos.offsetTop,
                           left: -pos.offsetLeft
                       });
                       this.timer=this.next.bind(this).delay(this.options.delay+this.options.speed);
                    } else this.fx.stop(0);
                },
                clearTimer: function(){
                   $clear(this.timer);
                }
            });



