
var fp_scrollinterval;
//////////////////////////////////////////////////////////////
// Feature products scrolling on left/right arrows rollover //
//////////////////////////////////////////////////////////////
$(document).ready(function() {
//////////////////////////////
	$('.featured_products .buttons .right').hover(function() {
		fp_scroll('+');
		fp_scrollinterval = setInterval('fp_scroll("+")', 1000);
	}, function() { // hout
		if(fp_scrollinterval) clearInterval(fp_scrollinterval);
	});
	$('.featured_products .buttons .left').hover(function() {
		fp_scroll('-');
		fp_scrollinterval = setInterval('fp_scroll("-")', 1000);
	}, function() { // hout
		if(fp_scrollinterval) clearInterval(fp_scrollinterval);
	});
}); // end document.ready

//////////////////////////////////////
// Actual feature products scroller //
//////////////////////////////////////
function fp_scroll(direction) {
///////////////////////////
	$('.featured_products .container').scrollTo(direction + '=740', 500, {axis: 'x', easing: 'swing'})
} // end function
/*
/////////////////////////////////////
// Feature products image enlarger //
/////////////////////////////////////
thumbnail_enlarger({
	item_selector:    '.featured_products .container img',
	source_attribute: 'src',
	large_size_ratio: 1.5,
	include_link:     true
});
*/
/////////////////////
var image_rotator = {
/////////////////////

	previous:    0,
	current:     1,
	max:         0,
	timer:       0,
	paused:      false,
	interval_id: 0,
	container:   '',
	navbuttons:  '',

	////////////////////////////////////////////////////////////////////////////////////////
	init: function(container_selector, navbuttons_selector, images_count, seconds_visible) {
	////////////////////////////////////////////////////////////////////////////////////////
		this.container   = container_selector;
		this.navbuttons  = navbuttons_selector;
		this.max         = images_count;
		this.timer       = seconds_visible;
		this.interval_id = setInterval('image_rotator.next()', this.timer * 1000);
	}, // end function

	//////////////////
	next: function() {
	//////////////////
		this.previous = this.current;
		this.current++;
		if(this.current > this.max) this.current = 1;
		this.show(this.current, 'right');
	}, // end function

	////////////////////
	goback: function() {
	////////////////////
		this.previous = this.current;
		this.current = this.current - 1;
		if(this.current < 1) this.current = this.max;
		this.show(this.current, 'left');
	}, // end function

	////////////////////////////
	set_current: function(seq) {
	////////////////////////////
		this.previous = this.current;
		this.current  = seq;
		this.show(this.current, 'rigth');
	},

	/////////////////////////////////////
	show: function(seq, show_direction) {
	/////////////////////////////////////
		var hide_direction = show_direction == 'left'? 'right': 'left';
		// $(this.container  + ' .item' + this.previous).fadeOut('fast');
		$(this.container  + ' .item' + this.previous).hide('slide', {direction: hide_direction}, 500);
		$(this.navbuttons + ' .item' + this.previous).toggleClass('this', false);
		// $(this.container  + ' .item' + seq).fadeIn('fast');
		$(this.container  + ' .item' + seq).show('slide', {direction: show_direction}, 500);
		$(this.navbuttons + ' .item' + seq).toggleClass('this', true);
	}, // end function

	//////////////////////////
	pause_resume: function() {
	//////////////////////////
		if(this.paused) {
			this.interval_id = setInterval('image_rotator.next()', this.timer * 1000);
			$(this.navbuttons + ' .pause').toggleClass('disabled', false);
			this.paused = false;
		} else {
			clearInterval(this.interval_id);
			this.paused = true;
			$(this.navbuttons + ' .pause').toggleClass('disabled', true);
		} // end if

	} // end function


///////////////////////
}; // end image_rotator
///////////////////////

