var bodyWidth = 0;
var imageContainer = null;
var currentImageIndex = 0;
var ctrWidth = 0;
var imgs = [0];
var last = 0;

var lnth = 0;
var st = 0;
var flowDirection = 'r';
var alts = [];
var title = [];
var color = [];
var links = 0;
var st_height = 0;
var imagesW = [];
var imgobj = [];


function setCaption() 
{
	$('#title').html(alts[currentImageIndex]).css({'color' : color[currentImageIndex]});;
	$('#descr').html(title[currentImageIndex]).css({'color' : color[currentImageIndex]});;;
	
}


function nextImage()
{
	if (currentImageIndex == lnth-1)
	{
		currentImageIndex = 0;
	}
	else
	{
		currentImageIndex++;

	}
	
	changeImage();
	

	
	
}


function initSettings(numberColor)
{
	
	
	bodyWidth = $(document).width();
	
	imageContainer = $($('#images'));

	tcnt = 0;
	imageContainer.find('img').each(function(){
		
		var temp = $(this).width();
		var temph = $(this).height();
		if (st_height < temph) 
		{
			st_height = temph;
		}
		
		$(this).attr('rel',lnth);
		ctrWidth += temp;
				
		lnth++;
		imagesW.push(temp);
		imgs.push(ctrWidth);
		imgobj.push($(this));
		if (tcnt != 0) 
		{
			$(this).fadeTo("fast", 0.15);
		}
		tcnt++;

		alts.push($(this).attr('alt'));
		title.push($(this).attr('title'));
		color.push($(this).attr('id'));
		
	});
	
	
	imageContainer.css('height', st_height+'px');
	imageContainer.css('width', ctrWidth+500+'px');
	st = parseInt((1000 - imagesW[currentImageIndex])/2)
	
	
	imageContainer.css('margin-left: 0px');
	setCaption();	

	
	$(function() {
    	setInterval( "nextImage()", 5000 );
    });
    
    
}


function changeImage() 
{

	 var tempp = (1000 - imagesW[currentImageIndex]) - (imgs[currentImageIndex]);

	var tempc = currentImageIndex;
	var templ = last
	

	setCaption();
	
	imageContainer.animate({ marginLeft: tempp}, 700, 'easeInOutQuad', function()
	{
	    imageContainer.css('margin-left:',tempp+'px');
		//imageContainer.css('margin-left:',tempp+'px');
		
		//alert(tempp)	
		
		imgobj[tempc].fadeTo("fast", 1.0);
		
	});	
	
	last = currentImageIndex;
}




