/*Задание основных параметров*/
var imgPath = "/images/";			//Путь к папке с картинками
var items = Array();				//Массив картинок
items[0] = "inkotek.png";
items[1] = "massa.png";
items[2] = "nixdorf.png";
items[3] = "schetmash.png";
items[4] = "shtih.png";
items[5] = "bs2.png";
items[6] = "chdlogo.png";
items[7] = "aclas.png";

/*
items[i] = "imgName.ext";
*/
var imgWidth = 180;
var imgHeight = 65;
var imgTop = 10;
var imgDistanse = 30;
var numImgShow  = 4;
var imgTime  = 30000;
var goToHref = "http://kkm.by/partners.html"	// Путь для перехода
/*Задание основных параметров*/
$(document).ready(function(){
	   onDocumentReady();
	});
function onDocumentReady()
{	$("#brandslider")[0].style.cursor='pointer';
	$("#brandslider")[0].style.overflow='hidden';
	$("#brandslider").click(function(){		location.href = goToHref;	})
	$("#brandslider").mouseover(function(){
		stopAnimate();
	})
	$("#brandslider").mouseout(function(){
		startAllAnimate();
	})
	startItemsMove();}

function startItemsMove()
{	for (var i=0;i<items.length;i++)
	{
		var img = $("<div style='width:"+imgWidth+"px;height="+imgHeight+"px;'><img src='"+imgPath+items[i]+"' width='"+imgWidth+"' height='"+imgHeight+"' /></div>");
		img[0].style.left =$("#brandslider")[0].offsetWidth+(i*(imgWidth+imgDistanse))+"px";
		img[0].style.position = "absolute";
		img[0].id = "item"+i;
		img[0].style.top = imgTop+"px";
		img.appendTo("#brandslider");
		animateItem(img);
	}
}

function animateItem(img)
{	var time = imgTime*((parseInt(img[0].style.left)+(imgWidth+imgDistanse)))/($("#brandslider")[0].offsetWidth);
	img.animate({left:-((imgWidth+imgDistanse))+"px"},time,"linear",function(){restartItem(this);});}

function restartItem(obj)
{	obj.style.left = calculateLastPosition();
	animateItem($("#"+obj.id));}

function calculateLastPosition()
{    var objs = $("div#brandslider div");
    var maxLeft = 0;
    for (var i=0;i<objs.length;i++)
    {       maxLeft = (parseInt(objs[i].style.left)>maxLeft) ? parseInt(objs[i].style.left) : maxLeft ;    }
    maxLeft = (maxLeft < $("#brandslider")[0].offsetWidth) ? $("#brandslider")[0].offsetWidth : maxLeft+imgWidth+imgDistanse;
    return maxLeft+"px";}

function stopAnimate ()
{    var objs = $("div#brandslider div");
    objs.stop();
}

function startAllAnimate()
{	var objs = $("div#brandslider div");
    for(var i=0;i<objs.length;i++)
    {    	animateItem($("#"+objs[i].id));    }}

function fnShowProps(obj, objName){
    var result = "";
    for (var i in obj) // обращение к свойствам объекта по индексу
        result += objName + "." + i + " = " + obj[i] + "<br />\n";
    return result;
}
