// ajax_tabs_team.js v1.0
// copyright 2010
// Easy2play BV


$(document).ready(function() {

	// Show the default tabcontent -> team profile
//	var varDefMethod = "get";
//	var varDefUrl  = 'inc/functions/ajax_get_team_profile.php';	
//	var varDefParam = 'id=' + $("#hiddentabid").attr("title") + '&l=' + $("#currentlang").attr("title");	
//	var varDefContent = "#tabcontent";
//	var varDefWait = "#tabloading";
//	AjaxMainHandler(varDefMethod, varDefUrl, varDefParam, varDefContent, varDefWait);

	var varMethod = "get";
	var varUrl  = 'inc/functions/ajax_subleagueprofile_standings.php';
	var varSlid = $('#subleagueID').attr('param');		
	var varParam = 'x=0&paramID=1&slid='+ $("#hiddentabid").attr("title");
	var varContent = "#tabcontent";
	var varWait = "#tabloading";
	AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);



	$("a.tab").livequery('click', function() {   
     
	  $(".active").removeClass("active");   
	  $(this).addClass("active");
	  
	  varShowWhat = $(this).attr("id");
		varDefParam = 'id=' + $("#hiddentabid").attr("title") + '&l=' + $("#currentlang").attr("title");					  
		var varContent = "#tabcontent";
		var varWait = "#tabloading";
	
		switch(varShowWhat) {
			case "subleagueprofile": // show the team profile
			var varDefParam = 'x=0&paramID=1&slid='+ $("#hiddentabid").attr("title");
				var varUrl  = 'inc/functions/ajax_subleagueprofile_standings.php';
			break;    
			case "subleagueblog": // show the team blog page
				var varDefParam = 'slid=' + $("#hiddentabid").attr("title") + '&l=' + $("#currentlang").attr("title") + '&blogtypeid=1';
				var varUrl  = 'inc/functions/ajax_get_blog.php';		
			break;   						
		}    
		
		AjaxMainHandler(varMethod, varUrl, varDefParam, varContent, varWait);
		
		return false;
	}); 
	
		// On pagination pagenumber clicks call in livequery to trigger the content refresh
	// push the params sorton (time, sprint, mountain) and showstage (general, first, second etc.)
	$('#pagination a').livequery('click', function() {
		var varParam = 'paramID=' + $(this).attr('id') + '&slid=' + $('#subleagueID').attr('param');
		AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);
		return false;
	}); 
	
	$('#joinsubpoolloggedin').livequery('click', function() {
		var varSlid = $('#subleagueID').attr('param');
		
		
		$.ajax({
			method: "post",url: "inc/functions/ajax_save_general_joinsubleague.php",data: "x=dummy&slid="+varSlid,
				success: function(){ 
					// reload the subleague
//					var varMethod = "get";
//					var varUrl  = 'inc/functions/ajax_subleagueprofile_standings.php';
//					var varSlid = $('#subleagueID').attr('param');		
//					var varParam = 'x=0&paramID=1&slid='+varSlid;
//					var varContent = "#ajaxcontent";
//					var varWait = "#ajaxwait";					
					AjaxMainHandler(varMethod, varUrl, varParam, varContent, varWait);
		    }
		});		
	});	
	$('#joinsubpoolnotloggedin').livequery('click', function() {
		var varSlid = $('#subleagueID').attr('param');
		window.location.href = "joinnow.php?slid="+varSlid;
	});				
		
});
