var mycarousel_itemList = [
    {url: "sp", title: "Стильные мужские костюмы"},
    {url: "GoldenSailCN", title: "Отправка товаров из Китая. Услуги переводчика."},
    {url: "Ride", title: "Закажи поездку Минск-Хмельницкий-Минск"},
    {url: "Reklama", title: "Закажи рекламу на ПроБазар"},
    {url: "Pilot", title: "Лучшая женская обувь на Хмельницком рынке"},
//    {url: "Radio", title: "Рекламное агентство Пирамида: Радиобазар"},
    {url: "Pelle", title: "широкий ассортимент турецких качественных изделий из натуральной кожи и меха"}
];

var currentItem = 1;

function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = 1; i <= carousel.last; i++) {
        if(i==1)
        {
                carousel.remove(i);
        }

        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
    }
};

function mycarousel_getItemHTML(item)
{
    return '<a href="http://ProBazar.com.ua/' + item.url + '.aspx" target="_blank"><img src="http://ProBazar.com.ua/pp/' + item.url + '.gif" width="468" height="60" border="0" alt="' + item.title + '" /></a>';
};

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

};


function SetCookie(sName, sValue)
{
  _date = new Date();
  _date.setHours(_date.getHours()+24);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + _date.toGMTString();

}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

if(GetCookie("ProBazarBanner")!=null)
{
	currentItem = parseInt(GetCookie("ProBazarBanner"));
	if(currentItem==mycarousel_itemList.length)
	{
		currentItem = 1;
	}
	else
	{
		currentItem = currentItem + 1;
	}
}
SetCookie("ProBazarBanner", currentItem);

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 7,
        wrap: 'last',
	scroll: 1,
	size: mycarousel_itemList.length,
        itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback},
        initCallback: mycarousel_initCallback,
        start: currentItem
    });
});
