
/**
 * Image src URLs
 **/
var imageList = [
				 "#",
				 "/img/trash/gazprom.gif",
			 	 "/img/trash/tele2_.gif",
		 		 "/img/trash/rzhd2.gif",
	 			 "/img/trash/synterra.gif",
 				 "/img/trash/m_industry.gif",
 				 "/img/trash/eurosib.gif",
	 			 "/img/trash/comstar.gif",
	 			 "/img/trash/spbcc.png",
	 			 "/img/trash/spbopen.gif",
	 			 "/img/trash/peterstar.png",
	 			 "/img/trash/executive.gif",
	 			 "/img/trash/talosto.gif",
	 			 "/img/trash/gruzomob.gif",
				 "/img/trash/start_tel.gif",
				 "/img/trash/setlestate.png",
				 "/img/trash/top_manager.gif",
				 "/img/trash/jacob_del.gif",
				 "/img/trash/otsp.png",
				 "/img/trash/nge.gif",
				 "/img/trash/may.png",
				 "/img/trash/soda.gif",
				 "/img/trash/innova.png"
				 
				 ];
				 
var urlList = [
				 "#",
				 "/clients/78.html",
				 "/clients/59.html",
				 "/clients/80.html ",
				 "/clients/37.html",
				 "/clients/49.html",
				 "/clients/6.html",
				 "/clients/73.html ",
				 "/clients/100.html",
				 "/clients/84.html",
				 "/clients/102.html",
				 "/clients/7.html",
				 "/clients/64.html",
				 "/clients/23.html",
				 "/clients/46.html",
				 "/clients/103.html",
				 "/clients/15.html",
				 "/clients/38.html",
				 "/clients/101.html",
				 "/clients/74.html",
				 "/clients/97.html",
				 "/clients/82.html ",
				 "/clients/98.html"

				 ];
				 
var altList = [
				 "#",
				 "одна из крупнейших нефтегазовых компаний России &#34;Газпром нефть&#34;",
				 "оператор мобильной связи TELE2 Россия",
				 "ОАО &#34;Российские железные дороги&#34;",
				 "национальный оператор связи &#34;Синтерра&#34;",
				 "группа строительных компаний &#34;М-Индустрия&#34;",
				 "холдинг &#34;Евросиб&#34;",
				 "подразделение ОАО &#34;Комстар - ОТС&#34; - ОАО &#34;Тюменнефтегазсвязь&#34;",
				 "Правительство Санкт-Петербурга",
				 "теннисный турнир ATP &#34;St. Petersburg Open&#34;",
				 "Оператор связи &#34;ПетерСтар&#34;",
				 "online сообщество менеджеров &#34;E-xecutive&#34;",
				 "лидер по производству замороженных продуктов питания ГК &#34;Талосто&#34;",
				 "поставщик техники &#34;Грузомобиль&#34;",
				 "телекоммуникационная компания &#34;Старт Телеком&#34;",
				 "Ведущая компания в составе международного холдинга Setl Estate",
				 "популярное деловое издание Top-manager",
				 "французский производитель элитной сантехники Jacob Delafon",
				 "Крупнейшая полиграфическая компания Санкт-Петербурга &#34;Образцовая Типография&#34;",
				 "группа компаний в области энергетики &#34;НГ-Энерго&#34;",
				 "Сеть салонов красоты &#34;Май&#34;",
				 "сеть магазинов модной одежды SODA",
				 "Российский издатель онлайн-игр Innova Systems"

				 ];

var lastRan = -1;


/**
 * Since carousel.addItem uses an HTML string to create the interface
 * for each carousel item, this method formats the HTML for an LI.
 **/

var fmtItem = function(imgUrl, url, title, alttext) {

  	var innerHTML = 
  		'<a href="' + 
  		url + 
  		'" title="' + alttext + '" ><img src="' + 
  		imgUrl +
		'" width="' +
		132 +
		'" height="' +
		81+
		'"/>' + 
  		title + 
  		'</a>';
  
	return innerHTML;
	
};

/**
 * Custom inital load handler. Called when the carousel loads the initial
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadInitHandler
 **/
var loadInitialItems = function(type, args) {

	var start = args[0];
	var last = args[1]; 

	load(this, start, last);	
};

/**
 * Custom load next handler. Called when the carousel loads the next
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadNextHandler
 **/
var loadNextItems = function(type, args) {	

	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

/**
 * Custom load previous handler. Called when the carousel loads the previous
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadPrevHandler
 **/
var loadPrevItems = function(type, args) {
	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

var load = function(carousel, start, last) {
	for(var i=start;i<=last;i++) {
		//var randomIndex = getRandom(13, lastRan);
		//lastRan = randomIndex;
	    lastRan = i;
		carousel.addItem(i, fmtItem(imageList[lastRan], urlList[lastRan], "", altList[lastRan]));
/*
		// Example of an alternate way to add an item (passing an element instead of html string)
		var p = document.createElement("P");
		var t = document.createTextNode("Item"+i);
		p.appendChild(t);
		carousel.addItem(i, p );
*/
	}
};

var getRandom = function(max, last) {
	var randomIndex;
	do {
		randomIndex = Math.floor(Math.random()*max);
	} while(randomIndex == last);
	
	return randomIndex;
};

/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 **/
var handlePrevButtonState = function(type, args) {

	var enabling = args[0];
	var lnk = args[1];
	
	if(enabling) {
		lnk.style.display = 'block';
	} else {
		lnk.style.display = 'none';
	}
	
};
var handleNextButtonState = function(type, args) {

	var enabling = args[0];
	var lnk = args[1];
	
	if(enabling) {
		lnk.style.display = 'block';
	} else {
		lnk.style.display = 'none';
	}
	
};
/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'dhtml-carousel'.) See the
 * HTML code below.
 **/

var carousel;
var pageLoad = function() 
{
	carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
		{
			numVisible:        4,
			animationSpeed:   .25,
			scrollInc:         3,
			navMargin:         40,
			size: 22,
			//scrollAfterAmount:  2,
			//wrap: false,
			prevElement:       "prev-arrow",
			nextElement:       "next-arrow",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);