String.prototype.trim=function(){return this.replace(/^\s*/,"").replace(/\s*$/,"")}
$(function(){var delay=(function(){var timer=0;return function(callback,ms){clearTimeout(timer);timer=setTimeout(callback,ms)}})();$.datepicker.setDefaults($.datepicker.regional['pt-BR']);function scroller(){$('.scroll-container').filter(':last').bind('mousemove',function(e){var posX=e.pageX-$(this).offset().left;var posY=e.pageY-$(this).offset().top;var offset=posY*(scrollHeight-containerScrollHeight)/containerScrollHeight;if($('.scroll').filter(':last').height()<$(this).height()){return false}$('.scroll').filter(':last').css({top:-offset});return true})}scroller();$('input#termo').focus(function(){$('.tooltip').stop(true,true).animate({top:'-=8'},{queue:false,duration:'fast'}).fadeIn().delay(2500).animate({top:'-=8',opacity:0},'fast').fadeOut(function(){$(this).css({opacity:'',top:''})})});$('.voltar').live('click',function(){history.back()});$('.noticia p').expander({expandText:'',slicePoint:160});$('#subscrever').live('click',function(){emailSubscribe()});$('#cancelar').live('click',function(){emailCancel()});function notice(type){var message,color;switch(type){case'invalid':message='E-mail inválido, tente novamente.';color='red';break;case'empty':message='Preencha o campo com um e-mail válido.';color='red';break;case'inexistent':message='Este e-mail não existe.';color='red';break;case'active':message='Este e-mail já está subscrito.';color='green';break;case'subscribed':message='O seu e-mail foi subscrito.';color='green';break;case'unsubscribed':message='O seu e-mail foi removido.';color='green'}$('#notice').html(message).addClass(color).fadeIn().delay(3000).fadeOut(function(){$(this).html('').removeClass()})}function emailCheck(email){if(email.trim()===''){notice('empty');return false}else{return true}}function emailSubscribe(){var email=$('#email').val();if(emailCheck(email)){$.ajax({url:'newsletter.php',data:{email:email,task:'subscribe'},success:function(data){notice(data)}})}}function emailCancel(){var email=$('#email').val();if(emailCheck(email)){$.ajax({url:'newsletter.php',data:{email:email,task:'unsubscribe'},success:function(data){notice(data)}})}}function updateMenu(seccao){if(seccao!==undefined){var sub_menu='#sub_'+seccao;if(!$(sub_menu).closest('.submenu').is(':hidden')){$('.submenu li').removeClass('sub_selected');$(sub_menu).addClass('sub_selected')}else{$('.head').removeClass('selected');$('.submenu').slideUp();$(sub_menu).addClass('sub_selected').closest('.submenu').slideDown().prev('.head').addClass('selected')}}else{$('.head').removeClass('selected');$('.submenu li').removeClass('sub_selected');$('.submenu').slideUp();$('#menu_home').addClass('selected')}}function showEvent(evento){var template=_.template($('#evento-template').html(),evento);$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template);$('.box').fadeIn();$('#top-box > div').fadeIn();$('.container').scrollbarPaper();$('.municipio, .espaco').bind('click',function(){var term=$(this).text();router.navigate('programacao/'+term.toLowerCase(),true)})});updateMenu()}$('#menu li div').live('click',function(){if($(this).next().is(':hidden')){$('.submenu').slideUp();$('.head').removeClass('selected');$(this).addClass('selected');$(this).next('.submenu').slideDown()}else{var _this=$(this);$(this).next('.submenu').slideUp(function(){_this.removeClass('selected')})}});$('.submenu li a').live('click',function(){$('.submenu li').removeClass('sub_selected');$(this).addClass('sub_selected')});var AdvancedSearchModel=Backbone.Model.extend({defaults:{titulo:'',area:'',municipio:'',teatro:'',companhia_artista:'',data_inicio:'',data_fim:''},isNotEmpty:function(){var notEmpty=false;for(attr in this.attributes){if(this.attributes[attr]!==''){notEmpty=true}}if(notEmpty){return true}else{return false}}});var SimpleSearchModel=Backbone.Model.extend({defaults:{term:''}});var AdvancedSearchView=Backbone.View.extend({el:'.searchform:last',events:{'keyup #advanced_search input':'saveState','change #advanced_search input':'saveState','change #advanced_search select':'saveState'},template:_.template($('#advanced-search-template').html()),initialize:function(){_.bindAll(this,'render','update','saveState','search');this.model=new AdvancedSearchModel();myModel=this.model;this.model.bind('reset',this.update)},render:function(){$(this.el).fadeIn().html(this.template(this.model.toJSON()));$('.search_data_inicio, .search_data_fim',this.el).datepicker({inline:true,dateFormat:'yy-mm-dd'})},update:function(){$(this.el).html(this.template(this.model.toJSON()))},saveState:function(){var _this=this;delay(function(){_this.model.set({titulo:_this.$('#search_titulo').val(),area:_this.$('#search_area').val(),municipio:_this.$('#search_municipio').val(),teatro:_this.$('#search_teatro').val(),companhia_artista:_this.$('#search_companhia_artista').val(),data_inicio:_this.$('.search_data_inicio').val(),data_fim:_this.$('.search_data_fim').val()});if(_this.model.isNotEmpty()){_this.search()}else{listaEventos.getAll();arquivoView.getAll()}},600)},search:function(){$(listaEventos.el).empty();listaEventos.list.fetch({data:$.param(this.model.toJSON())})}});var advancedView=new AdvancedSearchView();var SimpleSearchView=Backbone.View.extend({el:'.searchform:last',events:{'keyup input#termo':'saveState'},template:_.template($('#simple-search-template').html()),initialize:function(){_.bindAll(this,'render','saveState','search');this.model=new SimpleSearchModel()},render:function(){$(this.el).fadeIn().html(this.template(this.model.toJSON()))},saveState:function(){var _this=this;delay(function(){_this.model.set({term:_this.$('#termo').val()});_this.search()},600)},search:function(){var termo=this.model.get('term');if(termo.length===0){listaEventos.getAll()}else if(termo.length<3){return}else{$(listaEventos.el).empty();listaEventos.list.fetch({data:$.param(this.model.toJSON())})}}});var simpleView=new SimpleSearchView();ArquivoSimpleSearchView=SimpleSearchView.extend({el:'.box .searchform',search:function(){var termo=this.model.get('term');if(termo.length===0){arquivoView.getAll()}else if(termo.length<3){return}else{$(arquivoView.el).empty();arquivoView.list.fetch({data:$.param(this.model.toJSON())})}}});var ArquivoAdvancedSearchView=AdvancedSearchView.extend({el:'.box .searchform',search:function(){$(arquivoView.el).empty();arquivoView.list.fetch({data:$.param(this.model.toJSON())})}});var Evento=Backbone.Model.extend({});var ListaEventos=Backbone.Collection.extend({model:Evento,url:'pesquisa.php'});var EventoView=Backbone.View.extend({template:_.template($('#eventos-template').html()),initialize:function(){_.bindAll(this,'render')},render:function(){return $(this.el).html(this.template(this.model.toJSON()))}});var ListaEventosView=Backbone.View.extend({el:'.scroll:last',list:new ListaEventos(),initialize:function(){_.bindAll(this,'render','appendItem','getAll');this.list.bind('reset',this.render);this.getAll()},render:function(){var view=this;this.$(this.el).empty();if(this.list.length>0){this.list.forEach(function(model){view.appendItem(model)});window.containerScrollHeight=$('.scroll-container').filter(':last').height();window.scrollHeight=$('.scroll').filter(':last').height()}else{this.$(this.el).html('A sua pesquisa não devolveu resultados')}$('.scroll').css('top','0')},getAll:function(){this.$(this.el).empty();this.list.fetch()},appendItem:function(evento){var eventoView=new EventoView({model:evento});$(this.el).append(eventoView.render())}});var listaEventos=new ListaEventosView();var Arquivo=ListaEventos.extend({url:'pesquisa.php?tipo=arquivo'});var arquivoCollection=new Arquivo();var ArquivoView=ListaEventosView.extend({el:'#programacao-arquivo .scroll',list:new Arquivo()});$('.searchform .advanced').live('click',function(){$(this).parent().fadeOut(function(){advancedView.render()})});$('.searchform .simple').live('click',function(){$(this).parent().fadeOut(function(){simpleView.render()})});$('.box .searchform .advanced').live('click',function(){$(this).parent().fadeOut(function(){ArquivoAdvancedSearch.render()})});$('.box .searchform .simple').live('click',function(){$(this).parent().fadeOut(function(){ArquivoSimpleSearch.render()})});var Router=Backbone.Router.extend({routes:{'':'home','noticia/:id':'noticia','evento/:id':'evento','associados':'associados','teatros':'teatros','programacao/:municipio':'programacao','programacao':'programacao','arquivo':'arquivo','b2b':'b2b','newsletter':'newsletter',':path':'seccao'},home:function(){$('#top-box .box, #bottom-box .box').remove();$('#top-box > div, #bottom-box > div').fadeIn();updateMenu()},seccao:function(path){var template=_.template($('#box-template').html()),seccao;$.ajax({url:'conteudo.php?seccao='+path,success:function(data){if(data!=='false'){seccao=$.parseJSON(data);$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template({seccao:seccao.titulo,texto:seccao.conteudo}));$('.box').fadeIn();$('.container').scrollbarPaper()});if(seccao.titulo==='Apresentação'){$('#top-box > div').fadeOut(function(){var videoTemplate=_.template($('#video-promocional').html());$('#top-box .box').remove();$('#top-box').append(videoTemplate());$('#top-box .box').fadeIn();var flashvars={},params={},attributes={base:'media/video_promocional/'};swfobject.embedSWF("media/video_promocional/video_promocional.swf","video","295","235","10.0.0",flashvars,params,attributes)})}else{$('#top-box > div').fadeIn()}updateMenu(path)}}})},noticia:function(id){var template=_.template($('#noticia-template').html());$.ajax({url:'conteudo.php?seccao=noticias&id='+id,success:function(data){if(data!=='false'){$('#top-box > div').fadeOut(function(){$('#top-box .box').remove();noticia=$.parseJSON(data);$('#top-box').append(template({seccao:noticia.titulo,texto:noticia.conteudo}));$('#top-box .box').fadeIn();$('.container').scrollbarPaper()})}}})},evento:function(id){$.ajax({url:'evento.php',data:{id:id},success:function(data){var evento=$.parseJSON(data);showEvent(evento)}})},associados:function(){var template=_.template($('#associados-template').html());$.ajax({url:'associados.php',success:function(data){var associados=$.parseJSON(data);$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template({associados:associados}));$('.box').fadeIn();$('#top-box > div').fadeIn();$('.container').scrollbarPaper()});updateMenu('associados')}})},teatros:function(){var template=_.template($('#teatros-template').html());$.ajax({url:'teatros.php',success:function(data){var teatros=$.parseJSON(data);$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template({teatros:teatros}));$('.box').fadeIn();$('#top-box > div').fadeIn();$('.container').scrollbarPaper()});updateMenu('teatros')}})},programacao:function(term){$('.box').remove();$('#bottom-box > div, #top-box > div').fadeIn();updateMenu('programacao');if(!term){listaEventos.getAll()}else{listaEventos.list.fetch({data:$.param({'term':term})})}},arquivo:function(){var template=_.template($('#arquivo-template').html());$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template());$('.box').fadeIn();$('#top-box > div').fadeIn();arquivoView=new ArquivoView();scroller();ArquivoSimpleSearch=new ArquivoSimpleSearchView();ArquivoAdvancedSearch=new ArquivoAdvancedSearchView();ArquivoSimpleSearch.render()});updateMenu('arquivo')},b2b:function(){var template=_.template($('#b2b-template').html());$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template());$('.box').fadeIn();$('#top-box > div').fadeIn();$('.container').scrollbarPaper()});updateMenu('b2b')},newsletter:function(){var template=_.template($('#newsletter-template').html());$('#bottom-box > div').fadeOut(function(){$('.box').remove();$('#bottom-box').append(template());$('.box').fadeIn();$('#top-box > div').fadeIn();$('.container').scrollbarPaper()});updateMenu('newsletter')}});var router=new Router();Backbone.history.start()});

