jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

var curMtItem = [];
var itemsCount = [];
var mtWidget = [];
var stopMtPlay = [];

function mtWidgetItemOver(id, mtIndex)
{
  $('#mtWidgetBlock'+ mtIndex + ' div.content').removeClass("displayed");
  $('#mtWidgetBlock'+ mtIndex + ' div#mtItem' + mtIndex + "_" + id).addClass("displayed");
  $('#mtWidgetImgList'+ mtIndex + ' li').removeClass("selected");
  $('li#mtTeaseItem'+ mtIndex + "_" + id).addClass("selected");
  curMtItem[mtIndex] = id;
}

function initMtWidget(count, mtIndex)
{
  curMtItem[mtIndex] = 1;
  itemsCount[mtIndex] = 3;
  stopMtPlay[mtIndex] = false;

  if (!mtIndex) mtIndex = 1;
  itemsCount[mtIndex] = count;

  mtWidget[mtIndex] = $('#mtWidgetImgList' + mtIndex).serialScroll({
  items:'li',
  offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
  start:1, //as we are centering it, start at the 2nd
  duration:1200,
  force:true,
  stop:true,
  lock:false,
  cycle:true, //don't pull back once you reach the end
  jump: true
//  easing:'easeOutQuart' //use this easing equation for a funny effect
});

  setMtWidgetTimer(mtIndex);
}

function mtWNext(mtIndex)
{
  curMtItem[mtIndex]++;
  
  if (curMtItem[mtIndex] > itemsCount[mtIndex]) curMtItem[mtIndex] = 1;
  scrollItems(curMtItem[mtIndex], mtIndex);
  mtWidgetItemOver(curMtItem[mtIndex], mtIndex);
}

function mtWPrev(mtIndex)
{
  curMtItem[mtIndex]--;
  if (curMtItem[mtIndex] < 1) curMtItem[mtIndex] = itemsCount[mtIndex];
  scrollItems(curMtItem[mtIndex], mtIndex);
  mtWidgetItemOver(curMtItem[mtIndex], mtIndex);

}

function nextMtItem(mtIndex)
{
  if (stopMtPlay[mtIndex]) return false;
  curMtItem[mtIndex]++;
  if (curMtItem[mtIndex] > itemsCount[mtIndex]) curMtItem[mtIndex] = 1;
  scrollItems(curMtItem[mtIndex], mtIndex);
  mtWidgetItemOver(curMtItem[mtIndex], mtIndex);
}


function scrollItems(item_id, mtIndex)
{
  if (itemsCount[mtIndex] > 3)
    mtWidget[mtIndex].scrollTo($("#mtTeaseItem" + mtIndex + "_" + item_id), 700 );
}

function setMtWidgetTimer(mtIndex)
{
  setInterval(function () {nextMtItem(mtIndex); }, 5000);
}

function mtWidgetOver(mtIndex)
{
  stopMtPlay[mtIndex] = true;
}
function mtWidgetOut(mtIndex)
{
  stopMtPlay[mtIndex] = false;
}
  