/* Author: 

*/

// carregamento de imagens
$("img").lazyload({
     effect : "fadeIn"
});


// efeito menu
$("#menu > ul > li").prepend("<span></span>"); 
$("#menu > ul > li").each(function() {
	var linkText = $(this).find("a").html(); 
	$(this).find("span").show().html(linkText);
}); 
$("#menu > ul > li").hover(function() {
	$(this).find("span").stop().animate({ 
		marginTop: "-40"
	}, 250);
} , function() { 
	$(this).find("span").stop().animate({
		marginTop: "0" 
	}, 250);
});
$(".festival").hover(function() {
	$(this).children("ul").fadeIn();
} , function() { 
	$(this).children("ul").fadeOut();
});

// slider principal
$('#sliderContent > li:first').fadeIn();
$('#sliderContent')
	.after('<div class="nav wrap"><button class="prev ir">Anterior</button> <button class="next ir">Próximo</button></div>')
	.cycle({
	    fx: 'fade',
	    speed: 1000,
	    timeout: 10000,
	    cleartype: 1,
	    prev:'.prev',
	    next:'.next'
});


//muda a aba
$("#agenda .tab:first").fadeIn();
$("#nav-agenda > li").click(function() {
	$("#nav-agenda li").removeClass("active");
	$(this).addClass("active");
	$("#agenda > .tab").hide();
	var activeTab = $(this).find("a").attr("href");
	$(activeTab).fadeIn();
	return false;
});


// agenda
$('#shows')
	.append('<div class="nav"><button class="prev1 prev ir">Anterior</button> <button class="next1 next ir">Próximo</button></div>')
	.cycle({
		fx:     'scrollHorz',
		slideExpr: 'ul.slide',
		timeout: 0,
		prev:   '.prev1',
		next:   '.next1'
});
$('#filmes')
	.append('<div class="nav"><button class="prev2 prev ir">Anterior</button> <button class="next2 next ir">Próximo</button></div>')
	.cycle({
		fx:     'scrollHorz',
		slideExpr: 'ul.slide',
		timeout: 0,
		prev:   '.prev2',
		next:   '.next2'
});
$('#oficinas')
	.append('<div class="nav"><button class="prev3 prev ir">Anterior</button> <button class="next3 next ir">Próximo</button></div>')
	.cycle({
		fx:     'scrollHorz',
		slideExpr: 'ul.slide',
		timeout: 0,
		prev:   '.prev3',
		next:   '.next3'
});


// painel de destques
$('.kwicks').kwicks({
    max : 707,
    min : 43,
    spacing : 2
});

//efeitos no painel de destaques
$('.kwicks li a').hover(function() {
	$(this).parent('li').siblings().find('dfn').stop().animate({textIndent: "-20em"}, {queue:false,duration:500});
	$(this).parent('li').find('dfn').animate({fontSize: "3em"}, {queue:false,duration:500});
	if($(this).parent('li').hasClass("shows")){   
		$(this).parent('li').find('dfn').animate({textIndent: "-14em"}, {queue:false,duration:1000});
	}
	if($(this).parent('li').hasClass("filmes")){   
		$(this).parent('li').find('dfn').animate({textIndent: "-6em"}, {queue:false,duration:1000});
	}
	if($(this).parent('li').hasClass("oficinas")){   
		$(this).parent('li').find('dfn').animate({textIndent: "-2em"}, {queue:false,duration:1000});
	}
	if($(this).parent('li').hasClass("feira")){   
		$(this).parent('li').find('dfn').animate({textIndent: "-9em"}, {queue:false,duration:1000});
	}
	if($(this).parent('li').hasClass("expo")){   
		$(this).parent('li').find('dfn').animate({textIndent: "-4em"}, {queue:false,duration:1000});
	}
}, function() {
	$(this).parent('li').find('dfn').stop().animate({ fontSize: "1.7em", textIndent: "0"}, {queue:false,duration:500});
    $(this).parent('li').siblings().find('dfn').animate({textIndent: "0", fontSize: "1.7em"}, {queue:false,duration:500});
});

//abre foto
$("a.photo").fancybox({
	'overlayShow'	: false,
	'opacity'		: true,
	'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic'
});

//toca o video
$('.play').click(function() {
	var url = $(this).attr('href');
	var id = url.match("[\?&]v=([^&#]*)")[1];
	$("#video").html('<iframe class="youtube-player" type="text/html" width="355" height="260" src="http://www.youtube.com/embed/'+id+'?fs=1&amp;hl=pt_BR&amp;rel=0&autoplay=1" frameborder="0" style="border:8px solid #282524"></iframe>');
	$('html,body').animate({scrollTop: $("#youtube").offset().top},'slow');
	return false;
});


// agenda
$('#apoio').append('<button id="galo">galo</button>');
$('#galo').click(function(){
    $("#apoio").append('<div id="galo-msg">Faça como o galo, valorize o que é da terra! <embed src="http://www.festivalmundo.com.br/static/sound/galo.swf" loop="false" autoplay="true" width="1" height="1" class="visuallyhidden"></embed></div>');
	$("#galo-msg").fadeIn();
	setTimeout(function() {
	  	$("#galo-msg").fadeOut();
		$("#galo-msg").remove();
	}, 5000);	
});

// search input do blog
$("#id_search").val("Digite sua busca");
$("#id_search").focus(function(){
     if ($("#id_search").val() == "Digite sua busca")
         $("#id_search").val("");
         return false;
});
$("#id_search").blur(function(){
     if ($("#id_search").val() == "")
         $("#id_search").val("Digite sua busca");
         return false;
});


//efeito na listagem das bandas
$('.viewport').mouseenter(function(e) {
    $(this).children('a').children('img').animate({ height: '154', left: '0', top: '0', width: '154'}, 100);
    $(this).children('figcaption').fadeIn(200);
	$(this).children('figcaption').css({display:"table"});
}).mouseleave(function(e) {
    $(this).children('a').children('img').animate({ height: '174', left: '-20', top: '-20', width: '174'}, 100);
    $(this).children('figcaption').fadeOut(200);
});

// efeito scroll
$(".comments").click(function(){
	var full_url = this.href;
	var parts = full_url.split("#");
	var trgt = parts[1];
	var target_offset = $("#"+trgt).offset();
	var target_top = target_offset.top;
	$('html, body').animate({scrollTop:target_top}, 500);
});

//muda a aba
$("#prog-sec .tab:first").fadeIn();
$("#prog-nav > li > a").click(function() {
	$("#prog-nav > li > a").removeClass("active");
	$(this).addClass("active");
	$("#prog-sec .tab").hide();
	var activeTab = $(this).attr("href");
	$(activeTab).fadeIn();
	return false;
});


