(function($) {


    $.fn.teamfilter = function() {

       $(".teamfilter-team").mouseover(function() {
					  $(this).addClass("teamfilter-active");
					  $.selectTeam($(this).attr("id"));
				       }).click(function() {
						   // set team variables
						   var teamOpt = /[A-Z]+/.exec($(this).attr("id"));
						   var teamName = teamlocs[teamOpt].city + " " + teamlocs[teamOpt].name;
						   $("#teamfilter-options-team").html(teamName);
						   $("#teamfilter-options-team").attr("team", teamOpt);
						   $("#teamfilter-options").show();
						});
       
       $("#teamfilter-options-close").click(function() {
					       $("#teamfilter-options").hide();
					    });
       
       $("#teamfilter-options-select-next").click(function() {
						     var teamOpt = $("#teamfilter-options-team").attr("team");
						     $("#teamfilter-options").hide();
						     $.selectNextGame(teamOpt);
						  });
       $("#teamfilter-options-goto-next").click(function() {
						   var teamOpt = $("#teamfilter-options-team").attr("team");
						   $("#teamfilter-options").hide();
						   $.gotoNextGame(teamOpt);
						});
       
       $(".teamfilter-team-include").click(function() {
					      var team = /[A-Z]+/.exec($(this).attr("id"));
					      if($(this).attr("checked")) {
						 $("#teamfilter-team-" + team).removeClass("excluded-team");
						 $(".gg-game-cell[home='"+team+"']").removeClass("gg-game-cell-exclude");
					      } else {
						 $("#teamfilter-team-" + team).addClass("excluded-team");
						 $(".gg-game-cell[home='"+team+"']").addClass("gg-game-cell-exclude");
					      }
					      $.excludeList(team);
					   });
       
       $(".teamfilter-team").mouseout(function() {
					 $(this).removeClass("teamfilter-active");
					 $.unSelectTeam($(this).attr("id"));
				      });
       
       $("#teamfilter-exclude-all").click(function() {
					     $(".teamfilter-team-include").attr('checked', false);
					     $(".teamfilter-team").addClass("excluded-team");
					     $(".gg-game-cell").addClass("gg-game-cell-exclude");
					     $.excludeList("all");
					  });
       
       $("#teamfilter-include-all").click(function() {
					     $(".teamfilter-team-include").attr('checked', true);
					     $(".teamfilter-team").removeClass("excluded-team");
					     $(".gg-game-cell").removeClass("gg-game-cell-exclude");
					     $.excludeList("none");
					  });
       
       $(".teamfilter-team-include").attr('checked', true);
       
       $("#teamfilter-expand").click(function() {
					if($(this).hasClass("teamfilter-expanded")) {
					   $("#teamfilter-select-all").hide();
					   $("#teamfilter table").hide();
					   $("#teamfilter-expand").html("+").removeClass("teamfilter-expanded");    
					} else {
					   $("#teamfilter-select-all").show();
					   $("#teamfilter table").show();
					   $("#teamfilter-expand").html("-").addClass("teamfilter-expanded");    
					}
				     });
       return this.each(function() {
			   /*
			   var i,j,k;
			   var html = "";
			   
			   for(i = 0; i < json.league.length; i++) {
			      for(j = 0; j < json.league[i].divisions.length; j++) {
				 for(k = 0; k < json.league[i].divisions[j].teams.length; k++) {
				    var city = json.league[i].divisions[j].teams[k].city;
				    var name = json.league[i].divisions[j].teams[k].lname;
				    var abbv = json.league[i].divisions[j].teams[k].abbv;
				    html += "<span id=\"teamfilter-team-" + abbv + "\"class=\"teampicker-div-team\">" + city + " " + name + "</span>";
				    html += "<input type=\"checkbox\" id=\"teamfilter-exclude-" + abbv +  "\" /><br/>";
				 }
			      }
			   }

			   $(this).append(html);  */
			});

    };

 })(jQuery);

  

