var $ = function (d){
    typeof d == "string" &&(d = document.getElementById(d)); 
     return $.fn.call(d);
};
var chk = function(obj){
		return !!(obj || obj === 0);
};
$.fn = function (){
	this.addEvent = function (sEventType,fnHandler){
		if (this.addEventListener) {this.addEventListener(sEventType, fnHandler, false);} 
	    else if (this.attachEvent) {this.attachEvent("on" + sEventType, fnHandler);} 
	    else {this["on" + sEventType] = fnHandler;}
	}
	this.removeEvent = function (sEventType,fnHandler){
		if (this.removeEventListener) {this.removeEventListener(sEventType, fnHandler, false);} 
	    else if (this.detachEvent) {this.detachEvent("on" + sEventType, fnHandler);} 
	    else { this["on" + sEventType] = null;}
	}
	return this;
};
var Class = {create: function() {return function() { this.initialize.apply(this, arguments); }}};
var Bind = function (obj,fun,arr){
	return function() {
		return fun.apply(obj,arr);
	}
}
var Marquee = Class.create();
Marquee.prototype = {
	initialize : function(speed,name,width){
		this.box = $("J_banner_img");
		this.speed = speed;
		this.name = name;
		this.width = width;
		this.lastOpr = 0;
		this.chkNum = this.lastOpr +1;
		this.scrollL = 0;
		this.Flag = 0;
		this.JPanel = $("J_banner_action_panel").getElementsByTagName("li");
		this.box.style.width = this.JPanel.length*this.width+"px";
		for(var i=0,j=(this.JPanel).length;i<j;i++){
			var currur = this.JPanel[i];
			var dataIndex = currur.getAttribute("data-index");
			if(dataIndex == i){
				$(currur).addEvent("mouseover",Bind(this,this.Start,[i]));
				this.Len = i;
			}
		}
		this.Go();
	},
	Go : function(){
		this.ainterval = setInterval(this.name+".Start()",this.speed);
	},
	Start : function(){
		if(this.Flag == 1 ) return;
		var incurrur = this.JPanel;
		if(chk(arguments[0])){
			var no =  arguments[0];
		}else{
			var no = this.chkNum;
		}
		
		if(this.lastOpr==no) return;
		incurrur[no].className = "current";
		incurrur[this.lastOpr].className = "";
		this.Flag = 1;
		this.Fun(no);
	},
	Fun : function(n){
		var num = this.lastOpr - n;
		this.scrollW = num / -num;
		this.interval = setInterval(this.name+".Scroll("+num+","+n+")",10);
		this.lastOpr = n;
	},
	Scroll : function(o,n){
		n = this.scrollW *n;
		this.scrollL += o*(this.width/10);
		this.box.style.left = this.scrollL+"px"; 
		if(this.scrollL == n*this.width) {
			clearInterval(this.interval);
			clearInterval(this.ainterval);
			this.Flag = 0;
			if(this.lastOpr == this.Len){
				this.chkNum = 0;
			}else{
				this.chkNum += 1;
			}
			this.Go();
		}
	}
}
$(window).addEvent("load",function (){
  marquee = new Marquee(5000,"marquee",980);
});﻿
