/**
* Homepage new products rotation
*
* @author Tomas Rasek <tomas@rasek.biz>
* @copyright Castus
* @version 20100924
*/
var newProducts = {
	interval: 3000,
	fadeInInterval: 300,
	ID: 1,
	currentID: 1,

	/**
	 * Inicialization
	 */
	init: function() {
		this.setEvents();
		this.setNewProducts();
		this.startRotate();
	},

	/**
	 * Set events
	 */
	setEvents: function() {
		var reference = this;
		jqf('.boxnew .box-inner').mouseout(function() {
			reference.startRotate();
		});
		jqf('.boxnew .box-inner').mouseover(function() {
			reference.stopRotate();
		});
	},

	/**
	 * Set ID
	 */
	setID: function(givenID) {
		if (givenID > jqf('.boxnew .box-inner').length) {
			givenID = 1;
		}
		this.ID = givenID;
	},

	/**
	 * Set current ID
	 */
	setCurrentID: function(givenID) {
		this.currentID = givenID;
	},

	/**
	 * start timer
	 */
	startRotate: function() {
		this.timer = window.setInterval("newProducts.setNewProducts()", this.interval);

	},

	/**
	 * Stop timer
	 */
	stopRotate: function() {
		window.clearInterval(this.timer);
	},

	/**
	 * Set active tab
	 */
	setNewProducts: function() {
		var reference = this;


		if (this.ID != this.currentID) {
			jqf('.boxnew .box' + this.ID).fadeIn(this.fadeInInterval, function() {
				jqf('.boxnew .box' + reference.ID).show();
				jqf('.boxnew .box' + reference.currentID).fadeOut(reference.fadeInInterval);
				reference.setCurrentID(reference.ID);
				reference.setID(reference.ID + 1);
			});
		}

		else {
			this.setID(this.ID + 1);
		}
 	}
}

jqf(document).ready(function() {
	newProducts.init();
});
