$(document).ready(function(){
  
  /* - */
  
    $(".slider_title").click(function(){
  
    $(this).toggleClass("active");
    $(".slider_content").slideToggle(200);
    return false;
  
  });  

  
  
  /* place footer */

  function resizeContent(){
  
    screenHeight = $(window).height();
    footerHeight = $("#footer").height();
    contentHeight = screenHeight-footerHeight;
  /*  $("#wrapper").height(contentHeight); */
    $("#wrapper").css("minHeight", contentHeight);
  
  }

  resizeContent();
  $(window).resize(resizeContent);


  /* frontpage box */

  // $("#box a.title").click(function(){
  //   if($(this).next().hasClass('active')) { return false; }
  //   
  //   $(".slide.active").animate({width: "0px"}, {"duration": 500, "easing": "easeMK"});
  //   $("#box .slide").removeClass("active");
  //   $(this).next().addClass("active");
  // 
  //   $(this).css({backgroundPosition: '-15px 0px'});
  //   $(this).nextAll("#box a.title").css({backgroundPosition: '-15px -300px'});
  //   $(this).prevAll("#box a.title").css({backgroundPosition: '-15px -600px'});
  //   
  //   $(this).next().animate({width: "695px"}, {"duration": 500, "easing": "easeMK"});
  // 
  //   return false;
  //   
  // });
  
  $('#box .slide').tabslider({
    visibleTitles : true, 
    area : 'slide', 
    trigger : 'title',
    speed : 220,
    onComplete : function() {
      $(this).parent().removeClass('after').removeClass('before').siblings().removeClass('active').end().addClass('active');
      $(this).parent().nextAll().removeClass('after').removeClass('before').addClass('after');
      $(this).parent().prevAll().removeClass('after').removeClass('before').addClass('before');
    }
  });

  $("#content_drillconsmoy a:not(.title)").hover(function(){
  
    $(this).animate({marginLeft: "+=8px"}, 150);
  
  }, function(){
  
    $(this).animate({marginLeft: "-=8px"}, 150);
  
  });
  
  
  /* fancy checkbox */
  
  $(".accordioncontent input:checked").next().addClass("check");

  $(".accordioncontent label").click(featClick);

  $(".accordioncontent label").prev().hide();


  /* Reference according */
  
  $(".sideaccordion").not(".active").next().hide();

  
  $(".sideaccordion").click(function(){
  
    $(this).toggleClass("active");
    $(this).next().slideToggle(400);

    return false;
  
  });
  
  
  /* lightbox */
  
  $(".sidegallery a.image, .gallery a.image").lightBox({
  
    overlayBgColor: "#d5d9d3",
    overlayOpacity: 0.8,
    containerResizeSpeed: 100,
    imageBtnClose: '/templates/drillcon/images/lightbox_close.png',
    imageBtnPrev: '/templates/drillcon/images/lightbox_prev.png',
    imageBtnNext: '/templates/drillcon/images/lightbox_next.png'
  
  });
  
  $('.referenceresults').tablesorter({widgets:['zebra']}).tablesorterPager({container:$('#pager'),size:30});
});

function featClick() {
  var cb = $(this).prev();
  
  check = cb.attr('checked')?1:0;
  
  if(cb.hasClass('single')) {
    var className = cb.attr('id').split('_')[1];
    // console.log(className);
    $.each($('#references input.feat.'+className+':checked'),function() {
      if($(this).attr('id') != cb.attr('id')) {
        $(this).attr('checked', false).next().removeClass('check');        
      }
    });
  }

  if(check == "0"){
    cb.attr('checked', true);
  } else {
    cb.attr('checked', false);
  }

  $(this).toggleClass("check");
    
  return false;
}
function checkRefs() {
  return;
    
  var feats = [];
  var years = [];
  
  $('#references input.feat:checked').each(function() {
    if($(this).attr('id').substr(0,4) == 'year') {
      years[years.length] = $(this).attr('id');
    }
    else {
      feats[feats.length] =  'feat_'+$(this).attr('id').split('_')[2];
    }
  });

  $('.referenceresults .row').each(function() {
    var show = (years.length == 0) ? true : false;
    
    for(var i = 0;i < years.length;i++) {
      if($(this).hasClass(years[i])) {
        show = true;
        continue;
      }
    }
    
    if(show) {
      for(var i = 0;i < feats.length;i++) {
        if(!$(this).hasClass(feats[i])) {
          show = false;
          continue;
        }
      }
    }
    
    if(show) {
      $(this).show();
    }
    else {
      $(this).hide();
    }
  });
  
  

}
