﻿/// <reference path="jquery.intellisense.js" />

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
};

function LineMover(divID)
{
	this._stepSize = 1;
	this._speed = 40;
	this._delay = 3000;
	this._div = null;
	this._timer = null;
	this._isMouseOver = false;
	
	this.OnMouseOver = function()
	{
		this._isMouseOver = true;
		clearTimeout(this._timer);
	}
	
	this.OnMouseOut = function()
	{
		this._isMouseOver = false;
		this.Tick();
	}
	
	this.OnTimerTick = function()
	{
		if (this._isMouseOver) return;
		
		var left = this._div.offsetLeft - this._stepSize;
		
		if (left * -1 > this._div.offsetWidth) left = 800;
		
		this._div.style.left = left + "px";
		
		this.Tick();
	}
	
	this.Tick = function()
	{
		this._timer = setTimeout(function() { this.OnTimerTick() }.bind(this), this._speed);
	}
	
	this.Init = function()
	{
		this._div = document.getElementById(divID);
		this._div.onmouseover = function() { this.OnMouseOver() }.bind(this);
		this._div.onmouseout = function() { this.OnMouseOut() }.bind(this);
		this.Tick();
	}
	
	this.Init();
}

$(document).ready(function(){
	newsLineMover = new	LineMover('divNewsMoveLine');	
});