jQuery(document).ready(function($){
	var arrayItems = ['image','linkimage'];
	var data = [];
	var counter = 1;
	var total,timer = null;
        var index = 0;
	
	function showContent() {
		clearInterval(timerInitial);
		index = counter - 1;
			if(data[index] != undefined){
				$('#global-movie').fadeOut(600,function(){
					data[index].image = data[index].image.substr(9);
					$('#square-image').css({'background-image':'url(' + data[index].image + ')'});
					$('#desc-movie span').html(data[index].title);
					$('#desc-movie h2').html(data[index].info);
					$('#desc-movie .mais').attr('href',data[index].linkimage);
					$(this).fadeIn(1000);
				})
			}
				
		if (counter == total){
			counter = 1;
		} else {
			counter++;
		}
	}
	
	$.ajax({
		type: 'GET',
		url: URL_BASE + '_conteudo/xml/home.xml',
		dataType: 'xml',
		success: function(xml) {
			$(xml).find('item').each(function(){
				var $this = $(this);
				data.push({
					image: $this.attr('image'),
					linkimage: $this.attr('link'),
					title: $this.find('title').text(),
					info: $this.find('info').text()
				});
			});
			total = data.length;
			timer = setInterval( showContent, 5000);
		}
	});
	
	var timerInitial = setInterval( showContent, 500);
	
	$('#global-movie').hover(function(){
		clearInterval(timer);
	}, function(){
		timer = setInterval( showContent, 5000);
	});
});
