mc = {
  init: function() {
    mc.recarga_elemento();
    mc.toggle_calendar();
    mc.greybox();
    mc.show_filter();
    mc.show_row();
    mc.show_pop_concept();
    mc.slider();
    mc.select_options();
  },
  
  recarga_elemento: function(target, content) {
    var target = '#'+target;
    //$(target).html(content);
    $(target).load(content);
  },
  
  recarga_elemento: function(target,target2,content) {
	    var target = '#'+target;
	    var target2 = '#'+target2;
	    $(target2).load("jsp/loading.jsp",{},function(){
	    	$(target).load(content);
	    });
  },
  
  toggle_calendar: function() {
	  $('.date_range').daterangepicker({
	    arrows: false,
	    dateFormat: 'd M, yy', 
	    appendTo: '.datepicker',
	    datepickeroptions: { 
	        firstDay:1
	    }
	  });
	  $('.date_range').click(function(){
      $('.options').css('overflow','hidden');	    
	  });

  },
  
  greybox: function(){
    $("a.greybox").click(function(){
      var t = this.title || $(this).text() || this.href;
      GB_show(t,this.href,821,990);
      return false;
    });
  },
  show_filter: function() {
    $('form#filters h3 a').click(function(){
      $(this).parent(1).next('.filter_content').children('.extra').toggle();
      return false;
    });
    $('form#filters a.show').click(function(){
      $('form#filters .filter_content .extra').show();
      $(this).hide();
      $('form#filters a.hide').show();
      return false;
    });
    $('form#filters a.hide').click(function(){
      $('form#filters .filter_content .extra').hide();
      $(this).hide();
      $('form#filters a.show').show();
      return false;
    });
    
  },
  
  show_row: function() {
    $('#menciones_table tr td.marca a').click(function(){
      $(this).parent().parent().toggleClass('expanded');
      $(this).parent().parent().next('.more_info').toggle();
      return false;
    });
  },
  show_pop_concept: function() {

	    $('#pop-concept a.show').click(function(){
	      $('#pop-concept #concepts_popularity').show();
	      $(this).hide();
	      $('#pop-concept a.hide').show();
	      return false;
	    });
	    $('#pop-concept a.hide').click(function(){
	      $('#pop-concept #concepts_popularity').hide();
	      $(this).hide();
	      $('#pop-concept a.show').show();
	      return false;
	    });
	    
	  },
	  
  slider: function() {
    // $('.slider').slider();
    $('select#sentimientos').accessibleUISlider({width: 159});
    $('select#popularidad').accessibleUISlider({width: 159});
  },
  
  select_options: function() {
    $('.select_options .all').click(function(){
      var target = $(this).parents('.select_options').next('.options').find('input').attr({checked: 'checked'});
      return false;
    });
    $('.select_options .none').click(function(){
      var target = $(this).parents('.select_options').next('.options').find('input').attr({checked: ''});
      return false;
    });
  }
  
}

var GB_ANIMATION = true;

$(document).ready(mc.init);