document.observe('dom:loaded', function() {
	new foreignNews;
});
var foreignNews = Class.create({
	currentPosition: 0,
	up: null,
	initialize: function() {
		this.num = 0;
		this.container = $('right').down('.box04 .mask');
		this.target = this.container.down('ul');
		this.defaultPosition = 0;
		this.start.bind(this)();

		this.target.observe('mouseover', this.onMouseOver.bind(this));
		this.target.observe('mouseout', this.onMouseOut.bind(this));
		this.max = -1 * ( this.target.getHeight());
		this.rowHeight = this.target.down('li').getHeight();
	},
	moveUp: function() {
		this.currentPosition -= 1;
		if ( ( this.currentPosition ) % this.rowHeight == 0 ) {
			var temp = this.target.select('li')[0];
			this.target.insert(temp);
			this.currentPosition = 0;
			this.target.setStyle({
				'top': this.currentPosition + 'px'
			});
		++this.num;
		}
		if ( this.num % 5 == 4 ) {
			this.up.stop();
			this.up = null;
			this.start.bind(this).delay(5)
		++this.num;
		}

		this.target.setStyle({
			'top': this.currentPosition + 'px'
		});
	},
	onMouseOver: function() {
		if ( this.up != null) {
		this.up.stop();
		this.up = null;
		}
	},
	onMouseOut: function() {
		this.start.bind(this)();
	},
	start: function() {
		if ( this.up == null ) {
			this.up = new PeriodicalExecuter(this.moveUp.bind(this), 0.05);
		}
	}
});

