function addEvent ( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
    obj.attachEvent( "on"+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

function removeEvent ( obj, type, fn ) {
      if ( obj.detachEvent ) {
        obj.detachEvent( "on"+type, obj[type+fn] );
		    obj[type+fn] = null;
      } else
        obj.removeEventListener( type, fn, false );
}

Function.prototype.bind = function(obj) {
    var _method = this;
    return function() {
        return _method.apply(obj, arguments);
    };    
}

function getstyle(elem, prop) {
		if(document.defaultView)
		{
			return document.defaultView.getComputedStyle(elem, null).getPropertyValue(prop);
		}
		else if(elem.currentStyle)
		{
			var prop = prop.replace(/-(\w)/gi, function($0,$1)
			{
				//return $0.charAt($0.length - 1).toUpperCase();
				return $1.toUpperCase();
			});
			return elem.currentStyle[prop];
		}
		else return null;
	}
	
var ttt = [];
function $(id) { 
    var $ =  (typeof id  =="string") ? document.getElementById(id) : id;
    $.start ={};
    
 
    $.start = function() {
        var left = getstyle($,"left");
	    var top =  getstyle($,"top");	 
	    $.start.left = (left=="auto") ? 0 : parseInt(left);
	    $.start.top = (top=="auto") ? 0 : parseInt(top);
    }

    $.stop = function(){
     
     for (i in ttt) {
        clearTimeout(ttt[i]);
     }

    };

    $.move = function(settings,callbk) {
    var _this = $;
    var left = getstyle(_this,"left");
	var top =  getstyle(_this,"top");
	 
	$.start.left = (left=="auto") ? 0 : parseInt(left);
	$.start.top = (top=="auto") ? 0 : parseInt(top);
	
    if (settings.to.top == _this.start.top) { // x 
       
        var descend = (settings.to.left>_this.start.left) ? false : true;     
        var s = Math.min(_this.start.left,settings.to.left); 
        var d = Math.max(_this.start.left,settings.to.left); 
        _this.speed = (d -s)/settings.delay;
      
            for (i = s; i <= d; i++) { 
              (function(j) { 
				    var delay = (descend==true) ? (d-j)*settings.delay/(d - s) : (j-s)*settings.delay/(d - s);
                       ttt[i] = setTimeout(function() { 
                         _this.style.left = j+"px";     
                          if (descend==false&&j==d&&callbk!=undefined) {callbk.call(_this);} 
                          else if (descend==true&&callbk!=undefined&&j==s) {
                          callbk.call(_this);
                         
                          } 
                           
                          },delay); 
                })(i); 
            
            } 
              
    } 
     
}
   
    return $;  
}
		
		function slideshow(id)
		{
		this.ul = document.getElementById(id);
		this.lis = this.ul.getElementsByTagName("LI");
		this.len = this.lis.length;
		this.width = parseInt(getstyle(this.ul.parentNode, "width"));
		this.ul.style.width = this.len*this.width+"px";
		this.left = this.width;
		this.t=0;
		this.k = 0;
		 // the index of active slide
			this.dir = "plus";
		 // moving direction
			this.delay =500;
		}
		
		slideshow.prototype = {
		repeat: function(fn,del){
			var _this = this;
			(function() { 
			_this.t = setInterval(fn,del);
			})();

		},

		attach:function(){
			_this = this;
			this.ul.onmouseover = function(){
				$(this).stop();
				_stop();
			};

			this.ul.onmouseout = function(){
				if (_this.t!=0) return;
				_stop();
				_go();
			}

		},

		go: function(){  
			_this = this;
			_stop = this.stop.bind(this);
			_go = this.go.bind(this);
			this.attach();
			clearInterval(this.t);   
			this.repeat(this.show.bind(this),this.delay+5000); 
		},

		show: function(){
			_this.k = (_this.dir == "plus") ? _this.k+1 : _this.k-1;
			if (_this.k== _this.len) {
				_this.dir = "minus";
				_this.k = _this.len-1;
			}
			else if (_this.k< 0) {
				_this.k = 0;
				_this.dir = "plus";

			} 
			  
			$(_this.ul).move({delay:_this.delay,to:{left:-_this.k*_this.left,top:0}});
				
		},

		stop:function(){
			$(this.ul).stop();
			clearInterval(this.t);
			this.t = 0;
		}

		}

	window.onload=function(){
	var ss1 = new slideshow("nt");
	ss1.go();
	}

