var aLargura;
var aTitle = new Array();

function slide () {
	var atual = 1;
	aLargura = new Array ();
	var larguraSlide = 0;
	
	var x = 1;
	jQuery('#slide .item').each (function () {
		aLargura[x] = parseInt(jQuery(this).attr('widthIE'));
		aTitle[x] = jQuery(this).attr('title');
		
		larguraSlide += parseInt(jQuery(this).attr('widthIE')) + 10;
		
		x ++;
	});
	
	jQuery('#slide').css('margin-left','0').css('width',larguraSlide+'px');
	
	jQuery('#btSlideEsquerda').click(function(){
		atual --;

		if (atual <= 0) {
			atual = aLargura.length - 1;
		}
		
		navegar(atual);
	});
	
	jQuery('#btSlideDireita').click(function(){
		atual++;
		
		if(atual == aLargura.length){
			atual = 1;
		}
		
		navegar(atual);
	});
	
	jQuery('#slide .item').css('opacity','0.3').css('cursor','pointer');
	jQuery('#slide .item:first-child').css('opacity','1').css('cursor','default');
	jQuery('.subtit div').html(jQuery('#slide .item:first-child').attr('title'));
	
	var x = 1;
	
	jQuery('#slide').find('.item').each (function () {
		jQuery(this).attr('onClick','navegar('+x+')').attr('id','itemId'+x);
		
		x ++;
	})
	
	navegar (1);
};
function navegar(prIndice) {
	var soma = 0;
	
	for(x = 1; x < prIndice; x++){
		soma = soma + aLargura[x] + 10;
	}
	
	deslocamento = ((soma * -1) - (aLargura[prIndice] / 2)) + 'px';
	
	jQuery('#slide').animate({
		'marginLeft' : deslocamento
	}, {
		duration: 700, 
		queue: false, 
		easing:'easeInOutCubic'
	});
	
	jQuery('#slide .item').css({
		'opacity':'0.3',
		'cursor':'pointer'
	});
	
	jQuery('#itemId'+prIndice).css('opacity','1');
	jQuery('.subtit div').html(aTitle[prIndice]);
}
