var recaptcha = "6LdTCcQSAAAAAKFfn_AjGuOjlXaOUkzbcVbHPIPZ";




function showRecaptcha(element) {
	Recaptcha.create(recaptcha, element, {
		theme: "red"
	});
}

function cricketAjax() {
	$.ajax({ 
		url: siteURLajax1 + "/ajax/tennis-odds.html", 
		cache: true,
		context: document.body, 
		success: function(html){
			$('#odds-container').html(html);
			reRunableFunctions();
		}
	});	
}

function oddsSlider() {
	$('#arrow-up').click(function(){
		$('#odds-container').slideUp('fast',function(){
			$('#odds-slide-down').slideDown('fast');
		});
		
	});
	
	$('#arrow-down').click(function(){
		$('#odds-slide-down').slideUp('fast',function(){
			$('#odds-container').slideDown('fast');
		});
	});	
}

function oddsDisplayTidy() {
	$('.had-home').each(function(){
		if ($(this).html() == "") {
			$(this).html("-");
		}
	});
	
	$('.had-visitor').each(function(){
		if ($(this).html() == "") {
			$(this).html("-");
		}
	});
	
	$('.had-draw').each(function(){
		if ($(this).html() == "") {
			//$(this).html("-");
		} else {
			if ($(this).parent().parent().hasClass('done')) {
				
			} else {
				$(this).parent().parent().addClass('done');
				$(this).parent().parent().find('.had-draw').removeClass('hide');
				$(this).parent().parent().find('.draw-head').html("<strong>Draw Odds</strong>");
			}
		}
	});	
	
}

function forceUpdate() {
	
	pageUrl = document.URL;
	ajaxUrl = pageUrl + "/forceupdate";
	
	
// Do the ajax
	$.ajax({
		// Use the passed in url
		url: ajaxUrl,   
		success: function(html) {
			
			//$('.col1_2').html($(html).find('.col1_2').html());
			//$('#content').find('div:first').html($(html).find('#content').find('div:first').html());
			//$('#content').html($(html).find('#content').html());
			
			$('#content').find('div.col1_3').html($(html).find('#content').find('div.col1_3').html());
			$('#content').find('div.col1_2').html($(html).find('#content').find('div.col1_2').html());
			
			reRunableFunctions();
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			
			// Might want to change this to a more appropriate error message
			// alert('something went wrong');
		}
	});	
	
	
}

function googleTrack(a,b) {
	
}

function tableCssFix() {
	$('tr').each(function(){
		$(this).find('td:first').addClass('first');
	});
}

function templateBannerLoad() {
	
	submitTo = "/ajax/banner.html";
	dataString = "type=5";
	
	$.ajax({
		type: "POST",
		url: submitTo,  
		data: dataString,  
		success: function(html) {
			
			// Insert the returned information after the specified
			$('#template_banner').html(html);
			
		}
	});
	
	
	
}

// Just grouping functions that need to be re-run at the same time, if more are needed stick them in here later
function reRunableFunctions() {
	
	// Run the twitter content link adder
	tweetLinking();
	
	// Make divs that need to be links!
	makelink();
	
	// Make sure any dates are processed
	processDate();
	
	// Make sure all of the list items on the page have first and last approprietly
	setUpLists();
	
	// Sort out popups
	jqueryPopups3();
	
	// Sort out odds format
	showCorrectOddsTypeSetup();
	
	// Css layering
	tableCssFix();
	
	// puts a "-" into empty odds fields in tables
	//oddsDisplayTidy();
	
}

$(document).ready(function() {

	navHighlight();

	document.write=function(e){
		$('#template_banner').html(e);
	}
	
	
	//oddsSlider();
	
	reRunableFunctions();
	divExpander('li.bannerofferhead');
	startTheAjaxPagination();
	//templateBannerLoad();
	tabBoxSetup();
	
	$('.update-odds').live('click', function(event) {
		event.preventDefault();
		$(this).parent().parent().find('.spantimetogo').html('<img src="' + imagesDir + 'furniture/ajax-loader.gif" class="loader" />');
		forceUpdate();
	});

	// Set up the comments submitter
	submitCommentPrimer();
	cricketAjax();
	debugInfo();
});
