

var App = {};


App.CenterImages = function(prop) {
	this.p = prop;
	return this.init();
};

App.CenterImages.prototype = {
	
	init: function() {
		var t = this;
		
		t.scrolled = $('#' + t.p.scrolled);
		
		t.from = $('#' + this.p.from);
		t.to = $('#' + this.p.to);
		
		t.body_i0 = $('#body_i0');
		
		var left = Math.round((t.body_i0.width() - t.p.width) / 2);
		t.scrolled.css('left', left + 'px');
		
		if(left == 0) {
			t.from.css('display', 'none');
			t.to.css('display', 'none');
			$('#' + t.p.prompt).css('display', 'none');
			return t;
		}
		
		t.fromNormal = t.from.find('img.' + t.p.normalC);
		t.fromSel = t.from.find('img.' + t.p.selC);
		
		t.from
		.mouseover(function(e) {
			return t.fromOver(e);
		})
		.mouseout(function(e) {
			return t.fromOut(e);
		});
		
		t.toNormal = t.to.find('img.' + t.p.normalC);
		t.toSel = t.to.find('img.' + t.p.selC);
		
		t.to
		.mouseover(function(e) {
			return t.toOver(e);
		})
		.mouseout(function(e) {
			return t.toOut(e);
		});
		
		return t;
	},
	
	fromOver: function(e) {
		var t = this;
		
		t.fromNormal.css('display', 'none');
		t.fromSel.css('display', 'block');
		
		t.minLeft = t.body_i0.width() - t.p.width;
		this.timer = setInterval(function() {
			t.toLeft();
		}, 5);
	},
	
	fromOut: function(e) {
		var t = this;
		
		t.fromNormal.css('display', 'block');
		t.fromSel.css('display', 'none');
		
		if(t.timer) {
			clearInterval(t.timer);
			t.timer = null;
		}
	},
	
	toLeft: function() {
		var l = this.scrolled.css('left').replace(/px$/, '') - 0;
		if (l >= 0) return false;
		this.scrolled.css('left', (l + 5) + 'px');
	},
	
	toRight: function() {
		var t = this;
		
		var l = t.scrolled.css('left').replace(/px$/, '');
		if (l <= t.minLeft) return false;
		t.scrolled.css('left', (l - 5) + 'px');
	},
	
	toOver: function(e) {
		var t = this;
		
		t.toNormal.css('display', 'none');
		t.toSel.css('display', 'block');
		
		t.minLeft = t.body_i0.width() - t.p.width;
		t.timer = setInterval(function() {
			t.toRight();
		}, 3);
	},
	
	toOut: function(e) {
		var t = this;
		
		t.toNormal.css('display', 'block');
		t.toSel.css('display', 'none');
		
		if(t.timer) {
			clearInterval(t.timer);
			t.timer = null;
		}
	}
};




