j(window).load(function() {
	Solutions.init();
	
	j('.home-tabs-list li').click(function() {
		Solutions.forceTimer = true;
	});
});

Solutions = {
	cur : 1,
	forceTimer : false,
	_timer : null,
	_delay : null,
	_height : 0,

	init : function() {
		this._height = j('.tab-content').height();
		this.initTimer();
	},
	update : function(id) {
		var me = this;

		me.initTimer();
		j('.tab-content').not('#tab-' + me.cur + '-content').stop(true).hide();
		if (me._delay) clearTimeout(me._delay);
		var elm = j('#tab-' + me.cur + '-content')[0];
		j(elm).find('.get-quote').stop(true).fadeOut(200);
		j(elm).animate({opacity:0.1, height:0}, 400, function() {
			me._delay = setTimeout(function() {
				j(elm).hide();
				j('#tab-' + id + '-content').stop(true).show().animate({height:me._height, opacity:1}, 400, function() {
					j(this).find('.get-quote').stop(true).slideDown(350);
				});
			}, 100);
		});
		j('.home-tabs-list li').removeClass('selected');
		j('#htab-' + id).addClass('selected');
		me.cur = id;
	},
	initTimer : function() {
		var me = this;

		if (me._timer) clearTimeout(me._timer);
		var time;
		if (me.forceTimer) {
			time = 60000;
			me.forceTimer = false;
		}
		else {
			time = 15000;
		}
		me._timer = setTimeout(function() {
			var id = (me.cur < 4) ? me.cur + 1 : 1;
			if (me._timer) clearTimeout(me._timer);
			me.update(id);
		}, time);
	}
};