var updatingJsControls = false;

function refreshCluetips() {
	$('a.basic').cluetip({showTitle: false, dropShadow: true, dropShadowSteps: 6});
	$('a.player').cluetip({width: 600,showTitle: false});
	$('a.bidList').cluetip({width: 600,showTitle: false});
	$('a.playerBox').cluetip({width: 600,showTitle: false});
	$('a.playerStrengthChart').cluetip({width: 360, showTitle: false});
	$('a.thickbox').cluetip({width: 400,showTitle: false});
	$('a.custom-width').cluetip({width: 300,showTitle: false});
	$('a.tt-coach').cluetip({width: 300,showTitle: false});
	$('a.tt-rteam').cluetip({width: 180,showTitle: false});        
	$('a.coachlevel-detail').cluetip({width: 770, showTitle: false, dropShadow: true});        
    $('a.context-help').cluetip({showTitle: false});
	$('h4').cluetip({attribute: 'id', hoverClass: 'highlight'});
	$('a.tt').cluetip({local: true, width: 130, showTitle: false, cursor: 'pointer'});
	$('#sticky').cluetip({'sticky': true});
	$('a.load-local').cluetip({local:true, cursor: 'pointer'});
}

function renameThickboxCloseLabel() {
	$('div#TB_title > div:has(a#TB_closeWindowButton)').html("<a href='#' id='TB_closeWindowButton' title='Close'>X</a>");
	$("#TB_closeWindowButton").click(tb_remove);
}
		
$(document).ready(function() {
	$.ajaxSetup({ cache: false });
	updateJSControls();
});

function clearUpdatingJsControlsFlag(){
	updatingJsControls = false;
}

function updateJSControls(){
	if(!updatingJsControls ){
		updatingJsControls = true;
		// add timeout in order to make clueTip work inside of a Thickbox
		window.setTimeout("refreshCluetips()", 500); 
		$('a.thickbox, area.thickbox, input.thickbox').click(function(){
			renameThickboxCloseLabel();
		});
		window.setTimeout("clearUpdatingJsControlsFlag()", 500); 
	}
};

function updateCredits(userId, callback){
	$.getJSON("rest/user/" + userId, function(data) {
		credits = data.credits;
		$("#creditsStatus:last :last").empty().append(credits);
		callback(credits);
	});
}