var url = window.location.href;
var url_part = url.split("#");
if( url_part[1] == 'li_galeria' || 
	url_part[1] == 'li_biografia' ||
	url_part[1] == 'li_discografia' ||
	url_part[1] == 'li_naweb' ||
	url_part[1] == 'li_agenda') {
		
	window.location = url_part[0];
}
$(document).ready(function() {
	/* Plugin scrollTo */	
	
	$('.navigation').click(function() {
		$.scrollTo( $(this).attr("href"), 800);		
	});	
	
	/* Home */	
	$('#pagina_home_menu a').mouseover(function() {
		$(this).parent().parent().find('p').fadeIn(1000);		
	});
	
	$('#pagina_home_menu a').mouseout(function() {
		$(this).parent().parent().find('p').fadeOut(1000);
	});
		
	/* biografia */
	
	// Easing equation, borrowed from jQuery easing plugin
	// http://gsgd.co.uk/sandbox/jquery/easing/
	jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};	
	$('#pagina_bio_conteudo').serialScroll({
		items:'li',
		prev:'#li_conteudo_bio a.prev',
		next:'#li_conteudo_bio a.next',
		//offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true //click on the images to scroll to them

	});
	$('#pg2').html( $('#pagina_bio_conteudo div').length );
	$('#li_conteudo_bio a.next').click(function() {
		var pagina = $('#pg1').html();
		var qtd_conteudo = $('#pagina_bio_conteudo div').length;
		if( pagina != qtd_conteudo ) {
			pagina++;
		}
		$('#pg1').html(pagina);
	});
	$('#li_conteudo_bio a.prev').click(function() {
		var pagina = $('#pg1').html();
		var qtd_conteudo = $('#pagina_bio_conteudo div').length;
		if( pagina != 1 ) {
			pagina--;
		}
		$('#pg1').html(pagina);
	});

	/* discografia */	
	var album_clicado = '';
	$('#pagina_disco_albuns a, #pagina_disco_conteudo a').click(function() {
		album_clicado = $(this).attr("class");		
		$('#pagina_disco_albuns, #pagina_disco_conteudo').fadeOut(1);
		if( album_clicado == 'pagina_disco_album_box2' ) {
			$('#pagina_disco_conteudo_box').css("margin-top", "-80px").css("height", "495px");
		}
		if( album_clicado == 'pagina_disco_album_box3' ) {
			$('#pagina_disco_conteudo_box').css("margin-top", "-110px").css("height", "535px");
		}
		if( album_clicado == 'pagina_disco_album_participacao' ) {
			$('#pagina_disco_album_participacao').css("margin-top", "15px");
		}
		$('#' + album_clicado).insertBefore('#pagina_disco_conteudo');
		$('#' + album_clicado).fadeTo("slow", 1);
		return false;
	});
	$('.fechar').click(function() {		
		$('#' + album_clicado).fadeTo("slow", 0);
		$('#' + album_clicado).insertAfter("#pagina_disco_albuns");
		$('#pagina_disco_albuns, #pagina_disco_conteudo').fadeIn(1);
		$('#pagina_disco_conteudo_box').css("margin-top", "0").css("height", "432px");
		$('#' + album_clicado).fadeTo("slow", 1);
	});
	$('.ficha_tecnica a').click(function() {
		var link_clicado = $(this).attr("href");		
		$(link_clicado).insertAfter('#pagina_disco_album_box_conteudo_empty');		
		return false; 
	});
				
	$('.mp3').media({ 
		width: 100, 
		height: 19, 
		autoplay: false,
		caption: false
	});
	
	$('div[@id^=pagina_disco_album_cifra_box], div[@id^=pagina_disco_album_release_box], div[@id^=pagina_disco_album_musica_box], div[@id^=pagina_disco_album_ficha_box], div[@id^=pagina_disco_album_foto_box]').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
		
	$('#pagina_disco_album_participacao_conteudo').serialScroll({
		items:'li',
		prev:'#li_conteudo_disco a.prev',
		next:'#li_conteudo_disco a.next',
		//offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true //click on the images to scroll to them

	});	
	$('#pg4').html( $('#pagina_disco_album_participacao_conteudo li').length );
	$('#li_conteudo_disco a.next').click(function() {
		var pagina = $('#pg3').html();
		var qtd_conteudo = $('#pagina_disco_album_participacao_conteudo li').length;
		if( pagina != qtd_conteudo ) {
			pagina++;
		}
		$('#pg3').html(pagina);
	});
	$('#li_conteudo_disco a.prev').click(function() {
		var pagina = $('#pg3').html();
		var qtd_conteudo = $('#pagina_disco_album_participacao_conteudo li').length;
		if( pagina != 1 ) {
			pagina--;
		}
		$('#pg3').html(pagina);
	});
	
	
	/* galeria */		
	$('a[@href=#li_galeria]').click(function() {
		if( $.browser.msie && $.browser.version == 6 ) {
			$('#sections ul').css('background-position', '-280px 20px');
		}
		else {
			$('#sections ul').css('background-position', '-280px 20px');
		}
	});
	$('a[@href!=#li_galeria]').click(function() {
		if( $.browser.msie && $.browser.version == 6 ) {
			$('#sections ul').css('background-position', '-280px center');
		}
		else {
			$('#sections ul').css('background-position', '-280px center');
		}
	});
	$('#pagina_gal_gallery a').click(function() {		
		if( $.browser.msie && $.browser.version == 6 ) {
			$('#sections ul').css('background-position', '-280px 20px');
		}
		else {
			$('#sections ul').css('background-position', '-280px 20px');
		}
	});
	
	var results =[];
	var elements = $("#pagina_gal_gallery_box").children('div');
	$.map( elements  , function(i, n){
			if( n%2 === 0 ){
					results.push(n);
			}
	});
	$.each( results , function(i,v){
			elements.slice(v, v+2).wrapAll('<li>');
	});
	$("#pagina_gal_gallery_box").children().wrapAll('<ol>');
	$('#pagina_gal_gallery_box').serialScroll({
		items:'li',
		prev:'#li_conteudo_gal a.prev',
		next:'#li_conteudo_gal a.next',
		//offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:1200,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true //click on the images to scroll to them

	});
	$('#pg6').html( $('#pagina_gal_gallery_box li').length );
	$('#li_conteudo_gal a.next').click(function() {
		var pagina = $('#pg5').html();
		var qtd_conteudo = $('#pagina_gal_gallery_box li').length;
		if( pagina != qtd_conteudo ) {
			pagina++;
		}
		$('#pg5').html(pagina);
	});
	$('#li_conteudo_gal a.prev').click(function() {
		var pagina = $('#pg5').html();
		var qtd_conteudo = $('#pagina_gal_gallery_box li').length;
		if( pagina != 1 ) {
			pagina--;
		}
		$('#pg5').html(pagina);
	});
	
	/* contato */
	var form_show = $('#tipo_form #show').html();
	form_show = '<form action="include/processa_contato.php" method="post" id="jqform">' + form_show + '</form>';	
	var form_fa = $('#tipo_form #fa').html();
	form_fa = '<form action="include/processa_contato.php" method="post" id="jqform">' + form_fa + '</form>';	
	var form_imprensa = $('#tipo_form #imprensa').html();
	form_imprensa = '<form action="include/processa_contato.php" method="post" id="jqform">' + form_imprensa + '</form>';	
	var form_outro = $('#tipo_form #outro').html();
	form_outro = '<form action="include/processa_contato.php" method="post" id="jqform">' + form_outro + '</form>';	
		
	$('#tipo_contato input').click(function() {
		var form_escolhido = $(this).attr("value");		
		$('#tipo_form').children().fadeTo('slow', 0);
		//$('#tipo_form #'+form_escolhido).insertBefore('#tipo_form :first-child');
		$('#tipo_form').empty();
		if( form_escolhido == 'show' ) {
			$('#tipo_form').append(form_show);
		}
		if( form_escolhido == 'fa' ) {
			$('#tipo_form').append(form_fa);
		}
		if( form_escolhido == 'imprensa' ) {
			$('#tipo_form').append(form_imprensa);
		}
		if( form_escolhido == 'outro' ) {
			$('#tipo_form').append(form_outro);
		}		
		$('#tipo_form').children().fadeTo('slow', 1);
		$('#jqform').submit(function() { 
			$(this).ajaxSubmit({
				success: function(resposta) {					
					$.jGrowl(resposta);
				},
				url: 'include/processa_contato.php',
				type: 'post',
				resetForm: true
			}); 
			return false; 
		}); 
	});	
    $('form').submit(function() { 
		$(this).ajaxSubmit({
			success: function(resposta) {					
				$.jGrowl(resposta);
			},
			url: 'include/processa_contato.php',
			type: 'post',
			resetForm: true
		}); 
		return false;		
	});
});
