(function($){

  $.fn.appendArrowSpan = function (setposition) {
    return this.each(function () {
      var $anchor = $(this);
          $anchor.append('<span class="arrow">&nbsp;</span>');
      if(setposition === true){
        var leftpos = Math.floor( $anchor.width()/2 )+3;
            $anchor.find('span').css({'left':leftpos+'px'});
      }
    });
  }

  $.fn.tint = function(){
    return this.each(function(){      
      $(this).wrap('<span class="tint"></span>');
    });
  }
  
  $.fn.filterselection = function(){
    return this.each(function(){      
      var $select = $(this);      
      $select.change(function(){
        var _all = 'visalle';
        var _location, _type, _county;
        
        $select.parent().parent().find('select').each(function(){
        //$select.parents('select').each(function(){  
          var $subselect = $(this);
            switch($subselect.attr('class')){
              case 'type':
                _type = $subselect.val();
                break;
              case 'location':
                _location = $subselect.val();
                break;
              case 'county':
                _county = $subselect.val();
                break;
              default:
                break;
            }                   
        });
        
        $('table.schools').find('tr.inforow').each(function(){
          var $row = $(this);
              $row.removeClass('odd');          
          if(     (_type      == _all || _type      == $row.find('td.type').text() ) 
              &&  (_location  == _all || _location  == $row.find('td.location').text()) 
              &&  (_county    == _all || _county    == $row.find('td.county').text()) ){
            $row.show();
          }else{
            $row.hide()
          }          
        });
        $('table.schools tr:visible:odd').addClass('odd');
      });               
    });
  }
  
  
  
  $(document).ready(function(){
    $('ul.mainnav a.active').appendArrowSpan(true);
    $('ul.language a.active').appendArrowSpan(false);
    $('ul.sidenav a.active').appendArrowSpan(false);
    $('a.sizes span.box').appendArrowSpan(false);
    $('div.slideshow').slideshow();
    $('div.job img').tint();
    $('select').filterselection();
    
    $('table.schools tr:odd').addClass('odd');
    $('table.schools').on('mouseover mouseout', 'tr.inforow', function(e){
      if( e.type == 'mouseover' ){
        $(this).addClass('rowhover');
      }else{
        $(this).removeClass('rowhover');
      }            
    });
    
  });
})(jQuery);
