var duration = 200;
var timePages;
var slidePalestrante;
var actualPage = 1;

function ocultarTodosParticipantes() {
	$('#speakersList .palestrante .info').stop(true, true);
	$('#speakersList .palestrante .info').css({'display': 'none', 'width': '0'});
}

/*function changePage(goTo) {
	
	if(goTo == 1) {
		actualPage = 2;
	} else if(goTo == 2) {
		actualPage = 1;
	}
	
	if(actualPage == 1) {
		$('#pagina1').fadeOut('fast', function() {
			$('#pagina2').fadeIn('slow');
		});
		$('.roundedNavigation .p1').removeClass('active');
		$('.roundedNavigation .p2').addClass('active');
		actualPage = 2;
	} else {
		$('#pagina2').fadeOut('fast', function() {
			$('#pagina1').fadeIn('slow');
		});
		$('.roundedNavigation .p2').removeClass('active');
		$('.roundedNavigation .p1').addClass('active');
		actualPage = 1;
	}
	window.clearInterval(timePages);
	timePages = window.setInterval(changePage, 8000);
	
	return false;
}*/

function pularLinha() {
	$('#speakersList .linha.active:first').slideUp('slow', function() {
		$('#speakersList .linha.active:last').after($('#speakersList .linha.active:first'));
	}).next().next().next().addClass('active').slideDown();
}
timePages = window.setInterval(pularLinha, 7000);

function changeDestaque() {
	if($('.prstrs img.active').next().attr('src') != undefined) {
		$('.prstrs img.active').css({'display': 'none'}).removeClass('active').next().fadeIn('slow').addClass('active');
	} else {
		$('.prstrs img.active').css({'display': 'none'}).removeClass('active').parent().find('img:first-child').fadeIn('slow').addClass('active');
	}
}



$(document).ready(function(){
	$("#display .block").hide();
	
	$("#display .block:first").show();
	
	$("#menuMap li a").click(function() {								  								  
		var t = $("div#map").attr("class");
		$("div#map").removeClass(t).addClass($(this).attr('id'));
		$("#display .block").hide();
		$("#display div#d_"+$(this).attr('id')).fadeIn();
		return false;
	});
	
	$("#linkWrap").click(function() {
		$("#wrap").fadeIn();
		return false;
	});
	
    $("#fecharWrap").click(function() {
		$("div#map").attr("class","").addClass($("#menuMap li a:first").attr('id'));
		$("#display .block").fadeOut().hide();
		$("#display .block:first").fadeIn();
		$("#wrap").fadeOut();

		return false;
	});
	
	$('#speakersList .palestrante').hover(
		function() {
			$(this).addClass('active');
			ocultarTodosParticipantes();
			$(this).find('img').css({'opacity': '1'});
			$(this).find('.info').animate({'width': '168px', 'opacity': '1'}, duration);
		},
		function() {
			$(this).parent().find('.active img').css({'opacity': '0.8'});
			$(this).removeClass('active');
			$(this).find('.info').animate({'width': '0', 'opacity': '0.5'}, duration);
		}
	);
	$('#speakersList .palestrante .info').hover(function() {
		ocultarTodosParticipantes();
	});
	
	$('#speakersList').hover(
		function() {
			$(this).find('img').css({'opacity': '0.8'});
			window.clearInterval(timePages);
		},
		function() {
			$(this).find('img').css({'opacity': '1'});
			$(this).find('.info').css({'width': '0'});
			/*timePages = window.setInterval(changePage, 8000);*/
			timePages = window.setInterval(pularLinha, 7000);
		}
	);
	
	/*timePages = window.setInterval(changePage, 8000);*/
	
	slidePalestrate = window.setInterval(changeDestaque, 7000);

	$('#altInscricao').click( function()
	{
		window.open($('#altInscricao').attr("href"),"InterCon2009","width=660px, height=500px, top=50px, left=100px, scrollbars=yes");

		return false;
	});
	
	$('a.openPopUp').click( function()
	{
		window.open($(this).attr("href"),"InterCon2009","width=660px, height=500px, top=50px, left=100px, scrollbars=yes");
		
		return false;
	});
	
	if ("" != $('input#ref').val() ) {
		$('#'+$('#ref').val()).show();
	}

	$('a.veja').click(
		function() {
			var vetURL;
			var ref;

			vetURL = $(this).attr('href').split("/");

			ref = vetURL[vetURL.length-2];

			$('#'+ref).slideToggle(650);
			
			return false;
		}
	);
});
