var gbScrollFeatured = true;
var gbScrollOver = false;
var gbStand = false;
var giScrollFeaturedPos = 0;
var giScrollMiliseconds = 10000;

function scrollListUpdate(oEvent, oTarget, oScrolled, aCollection, iPosition) {
	if (!gbScrollFeatured && !gbStand) return false;

	// positioning the background
	var oUL = jQuery('div.block-slide > div.list-slide > ul');
	var oThis = jQuery('div.block-slide > div.list-slide a:eq(' + String(iPosition) + ')');
	var sPosition = String((iPosition * oThis.parent().outerWidth()) - (iPosition + 1) *  3 - oUL.width()) + 'px bottom';

	giScrollFeaturedPos = iPosition;
	jQuery('div.block-slide div.list-slide').css('background-position', sPosition);
	oUL.find('li').css('fontWeight', 'normal');
	oThis.parent().css('fontWeight', 'bold');
}

function scrollPositioning(oAnchor) {
	var oContainer = jQuery('div.block-slide div.slide-container');
	var oThis = jQuery(oAnchor);
	var oUL	  = jQuery('div.block-slide > div.list-slide ul');
	var iPosition = 1;

	gbStand = true;

	// font weight
	oUL.find('li').css('fontWeight', 'normal');
	oThis.parent().css('fontWeight', 'bold');

	// positioning the scroller
	var aClass = oAnchor.href.split('-');
	iPosition = parseInt(aClass[aClass.length - 1]);
	oContainer.trigger('goto', iPosition);

	// positioning the background
	var sPosition = String((iPosition * oThis.parent().outerWidth()) - (iPosition + 1) *  3 - oUL.width()) + 'px bottom';
	jQuery('div.block-slide div.list-slide').css('background-position', sPosition);

	gbStand = false;
}

// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jQuery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(document).ready( function(){
	var oMenu		= jQuery('div.block-slide > div.list-slide a');
	var oContainer	= jQuery('div.block-slide div.slide-container');
	var oUL	  		= jQuery('div.block-slide > div.list-slide ul');

	oMenu.mouseover(function(){scrollPositioning(this);});
//	oMenu.mousemove(function(){scrollPositioning(this);});
	oMenu.click(function(){scrollPositioning(this); return false; });

	oUL.hover(function(){gbScrollFeatured = false;}, function(){gbScrollFeatured = true;});

	oContainer.find('li.item').mouseover(function(){
		gbScrollFeatured = false;
	});

	oContainer.find('li.item').mouseout(function(){
		gbScrollFeatured = true;
	});

	oContainer.serialScroll({
		items: 'li.item',
		duration: 600,
		force: true,
		axis: 'x',
		easing: 'easeOutQuart',
		offset: -13,
		stop: true,
		lock: false,
		lazy: false,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
		interval: giScrollMiliseconds, // yeah! I now added auto-scrolling
		step: 1, // scroll 2 news each time
		margin: true,
		onBefore: scrollListUpdate
	});

});



