

var bwMatchCenter = {
	
		saveTeam: function(teamabr) {

	    	var a = $.manageAjax.create('clearQueue', {queue: 'clear', maxRequests: 2, cacheResponse: true});
	    	var url     =     flashNaviBaseUrl + teamabr;
	        if(flashNaviHomePage){
	        	location.href = url;
           		return;
	        }
	        $('#matchcenter-changeInnerContent').html('<div class=\"loader\">&nbsp;</div>');
	        a.add({
	        	url: url,
	        	dataType: 'html', 
               /*
                * 		"xml": Returns a XML document that can be processed via jQuery.
                *       "html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.
                *       "script": Evaluates the response as JavaScript and returns it as plain text. Disables caching unless option "cache" is used. Note: This will turn POSTs into GETs for remote-domain requests.
	            *       "json": Evaluates the response as JSON and returns a JavaScript Object.
	            *       "jsonp": Loads in a JSON block using JSONP. Will add an extra "?callback=?" to the end of your URL to specify the callback. (Added in jQuery 1.2)
	            *       "text": A plain text string.
	            */
	            success: function(html) {
                                	 
	                $('#matchcenter-changeInnerContent').html(html);
	                $('.matches').MatchTableColorizer();
	                a.add({
	                      url: url,
	                      dataType: 'html', 
	                    success: function(html) {
	                    }
	                });
	        	}
	        });
	      }
}

var bwNewsDetailAjaxContentLoader = {
	
	init: function() {
		var a = $.manageAjax.create('clearQueue', {queue: 'clear', maxRequests: 2, cacheResponse: true});;
		$('#matchcenter-newsdetaillinks a').each(function(i, obj){
			
			$(this).click(function(){
			
				$('#matchcenter-leftContent').html('<div class=\"loader\">&nbsp;</div>');
				 a.add({
                      url: $(this).attr('rel'),
                      dataType: 'html', 
					  success: function(html) {
						  $('#matchcenter-leftContent').html(html);
						  $('.matches').MatchTableColorizer();
						  
                      }
	             });
				 
			});
			
		});
		
		
	}
	
}

var LoginLoader = {
		
		showMainFrame: function() {
			$('#login-layer').show();
		},
		hideMainFrame: function() {
			$('#login-layer').hide();
			$('#login-layer').html("");
		},
		load: function(toLoad, msg) {
			LoginLoader.showMainFrame();
			$('#login-layer').html('<div class=\"loader\" style=\"width:200px;height:40px;\">&nbsp;</div>');
				var toLoadUrl = ajaxbase + "loginbox.jsp.html?show=" + toLoad;
				if(msg != null){
					toLoadUrl = toLoadUrl + "&msg=" + encodeURIComponent(msg);
				}
				$.post(toLoadUrl, function(data){
					$("#login-layer").html(data);
			});
		},
		changePassword: function () {
			$('#myProfilePasswordContainer1').hide();
			$('#myProfilePasswordContainer2').show();
		},	
		changeEmail: function () {
			$('#myProfileEmailContainer1').hide();
			$('#myProfileEmailContainer2').show();
		}
	}

function logoutUser(){
	$.post(ajaxbase + "logout.jsp.html", function(data){
		if(loginOutUrl == "NULL"){
			location.reload();
		} else {
			location.href = loginOutUrl;
		}
	});
}

$(document).ready( function(){
	//Custom.init;
	initWceJQueryWM2010(); 
	
	/*init click*/
	$('.loggedIn .my-soccer-world .btn a').click(function () {
		logoutUser();
	});
	$('.notLoggedIn .my-soccer-world .btn a').click(function () {
		LoginLoader.load("login");
	});
	$(".my-soccer-world #userName").click(function () {
		LoginLoader.load("update")
	});
	
	$('.change-language .footer a').click(function() {
			$('#change-language-layer').hide();
	});
});

function initWceJQueryWM2010(){
	bwNewsDetailAjaxContentLoader.init();
}
