// Initialisations and site dependant settings
var t = "";
var q = "";
var dataSubmitting = -1;
var siteURL = "http://" + window.location.host;
var siteURLlength = siteURL.length;
var siteURLajax1 = siteURL;
var siteURLajax2 = siteURL;
var siteDir = "/";
var currentAjaxCall = "";
var ajaxDropDownPage = siteURLajax2 + siteDir + "ajax/dropdown.html";
var imagesDir = siteDir + "images/";
var commentFormSubmitUrl = siteDir + "ajaxnc/comment_submit.html";
var offsetValue = 0;
var ddmAjax = "";
var topAdAjax = "";
var topAdvertRotateTime = 60000;
var scoresEventsAjax = "";
var dropDownClear = "";

function navHighlight() {
	$('#navigation ul li a').each(function(){
		if (window.location.pathname == $(this).attr('href')) {
			$(this).parent().addClass('selected');
		}
	});
}

function submitForm() {
	errorMessage = 'Please complete all required fields.';
	if (commentFormValidation(errorMessage) === true) {
		$('.new-form-submit').click(function(){
			dataString = "";
			i = 0;
			$('#comment_form input, #comment_form textarea, #comment_form select').each(function(){
				if (i===0) {
					dataString = $(this).attr('id') + "=" + encodeURIComponent($(this).val());
				} else {
					dataString = dataString + "&" + $(this).attr('id') + "=" + encodeURIComponent($(this).val());
				}
				i++;
			});
			submitTo = $('#comment_form').attr('action');
			$.ajax({
				type: "POST",
				url: submitTo,  
				data: dataString,  
				success: function(html) {
					$('<span class="comment-pass-message error"><br />' + html + '</span>').insertAfter('.form-submit');
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$('#post-comment').append('<p class="error">Error</p>');
				}
			});
		});
	}
}

function submitCommentPrimer() {	
	$(document.getElementById('comment_form')).find('.form-submit').click(function(){
		if (dataSubmitting != 10000000) {
			dataSubmitting = 1;
			errorMessage = 'Please complete all required fields.';
			if (commentFormValidation(errorMessage) == true) {
				if ($(this).hasClass('comment-form')) {
					var post_id = 'post_id=' + $('#comment_post_id').val();
					var comment_name = 'comment_name=' + encodeURIComponent($('#comment_name').val());
					var comment_email = 'comment_email=' + encodeURIComponent($('#comment_email').val());
					var comment_content = 'comment_content=' + encodeURIComponent($('#comment_content').val());
					var submitTo = commentFormSubmitUrl;
					var dataString = post_id + "&" + comment_name + "&" + comment_email + "&" + comment_content;
					$.ajax({
						type: "POST",
						url: submitTo,  
						data: dataString,  
						success: function(html) {
							$('#post-comment').append(html);
							dataSubmitting = -1;
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							dataSubmitting = -1;
							$(document.getElementById('post-comment')).append('<p class="error">Error</p>');
						}
					});
				}
				else {
					dataString = "";
					i = 0;
					$('#comment_form input, #comment_form textarea, #comment_form select').each(function(){
						if (i==0) {
							dataString = $(this).attr('id') + "=" + encodeURIComponent($(this).val());
						} else {
							dataString = dataString + "&" + $(this).attr('id') + "=" + encodeURIComponent($(this).val());
						}		
						i++;
					});
					submitTo = $(document.getElementById('comment_form')).find('#st').val();
					$.ajax({
						type: "POST",
						url: submitTo,  
						data: dataString,  
						success: function(html) {
							dataSubmitting = -1;
							$('#comment_form').addClass('hide')
							$('<span class="comment-pass-message error"><br />' + html + '</span>').insertAfter('#comment_form');							
						},
						error: function(XMLHttpRequest, textStatus, errorThrown) {
							dataSubmitting = -1;
							$('#post-comment').append('<p class="error">Error</p>');
						}
					});
				}
			}
		} else {
			alert('Please wait before trying to re-submit');
			var f = setTimeout("resetFormSubmition()",5000);
		}
	});
}

function resetFormSubmition() {
	dataSubmitting = -1;
}

function formSetup() {
	$('.submit-form').each(function() {
		thisForm = $(this);
		$(this).find('.submit').click(function(){
			if (formValidation($(this).parents('.submit-form').attr('id'),"Please fill in all required fields","") == true) {
				$('<span class="pass">Winner</span>').insertAfter(this);
				submitTo = $(this).parents('.submit-form').find('#st').val();
				dataString = "";
				i = 0;
				returnMessageElement = '#' + $(this).parents('.submit-form').attr('id');
				$(this).parents('.submit-form').find('input,textarea').each(function() {
					if (i = 0) {
						dataString = "submit_" + $(this).attr('id') + "=" + $(this).val();
					} else {
						dataString = dataString + "&" + "submit_" + $(this).attr('id') + "=" + $(this).val();
					}
				});
				ajaxSubmit(submitTo,dataString,returnMessageElement);
			}
		});
	});
}

function emailValidation(value) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	if(typeof(arr) == 'object') {
		for(var item in arr) {
			var value = arr[item];
			if(typeof(value) == 'object') {
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else {
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function commentFormValidation(errorMessage) {
	var pass = 0;
	var counter = 0;
	$('.comment-error-message').remove();
	$('.comment-pass-message').remove();
	$('input.required,textarea.required').each(function(){
		counter++;
		$('.comment-specific-error-message').remove();
		if ($(this).val() != "") {			
			if ($(this).hasClass('email')) {
				if (emailValidation($(this).val())) {
					$(this).removeClass('error');
					pass++;	
				} else {
					$(this).addClass('error');
				}
			} else {
				if ($(this).hasClass('length')) {
					if ($(this).val().length < 300) {
						$(this).removeClass('error');
						pass++;	
					} else {
						$(this).addClass('error');
						$('<span class="comment-specific-error-message error">Too many characters, limit is 300</span>').insertAfter(this);
					}
				} else {
					$(this).removeClass('error');
					pass++;	
				}
			}
		} else {
			$(this).addClass('error');
		}
	});
	var recaptchaTest = authoriseRecaptcha();
	if (recaptchaTest == "ok") {
		counter++;
		pass++;
	} else {
		showRecaptcha('recaptcha_div');
		errorMessage = errorMessage + "<br />reCaptcha incorrect, please re-try";
		counter++;
	}
	if (pass == counter) {
		return true;
	} else {
		$('<span class="comment-error-message error"><br />' + errorMessage + '</span>').insertAfter('.form-submit');
		return false;
	}
}

function formValidation(formId,errorMessage,errorPosition) {
	var pass = 0;
	var counter = 0;
	$('#' + formId).find('.error-message').remove();
	$('#' + formId).find('input.required,textarea.required').each(function(){
		counter++;
		if ($(this).val() != "") {
			$(this).removeClass('error');			
			if ($(this).hasClass('email')) {
				if (emailValidation($(this).val())) {
					$(this).removeClass('error');
					pass++;	
				} else {
					$(this).addClass('error');
				}
			} else {
				pass++;
			}
		} else {
			$(this).addClass('error');
		}
	});
	$('#' + formId).find('select.required').each(function(){
		counter++;
		if ($(this).find('option:selected').val() == "-") {
			$(this).addClass('error');
		} else {
			$(this).removeClass('error');
			pass++;	
		}
	});
	if (pass == counter) {
		return true;
	} else {
		if (errorPosition == '') {
			$('<span class="error-message error">' + errorMessage + '</span>').insertAfter($('#' + formId).find('.submit'));
		} else {
			$('<span class="error-message error">' + errorMessage + '</span>').insertAfter('#' + errorPosition);
		}
		return false;
	}
}

function authoriseRecaptcha() {
	theUrl3 = siteURLajax1 + siteDir + "ajaxnc/captcha.html";
	var outputCaptcha = "";
	$.ajax({ 
		type: 'POST',
		async: false,
		cache: false,
		url: theUrl3,
		data: "recaptcha_challenge_field=" + $('#recaptcha_challenge_field').val() + "&recaptcha_response_field=" + $('#recaptcha_response_field').val(),
		success: function(html){
			outputCaptcha = html;
		}
	});
	return outputCaptcha;
}

function tabBoxSetup() {
	$('div.tab-box ul.content').parent().addClass('hide');
	$('div.tab-box ul.content:first').parent().removeClass('hide');	
	$('div.tab-box ul.tabs li').click(function(){
		$('div.tab-box ul.content').parent().removeClass('hide');		
		$('div.tab-box ul.content').parent().addClass('hide');
		$('div.tab-box ul.content:eq('+$(this).attr('rel') +')').parent().removeClass('hide');
		$(this).parent().find('li').removeClass('selected');
		$(this).addClass('selected');
	});
}

function paginationAjax(targetDiv) {
	$('.' + targetDiv + ' .pagination a, .' + targetDiv + ' .autopagination a').click(function(ev){
		if ($(this).hasClass('no-ajax')) {
		} else {
			ev.preventDefault();
			ajaxCall($(this).attr('href'),targetDiv);
		}
	});	
}

function paginationAjaxAuto(targetDiv) {
	paginationAjax(targetDiv);
	$('.' + targetDiv + ' .autopagination .autonext a').each(function(){
		timerValue = $('.' + targetDiv + ' .autopagination .autotimer').text() + "000";
		autoTimers[targetDiv] = setInterval("ajaxCall($('." + targetDiv + " .autopagination .autonext a').attr('href'),'" + targetDiv + "')",timerValue);
	});	
}

function ajaxCall(pageUrl,targetDiv) {
	if (pageUrl == "" || pageUrl == undefined) {
		clearTimeout(autoTimers[targetDiv]);
	} else {
		$.ajax({
			url: pageUrl,   
			success: function(html) {
				if ($('.' + targetDiv).hasClass('noscroll')) {
				} else {
					$('html, body').animate({
						scrollTop: $('.' + targetDiv).offset().top
					}, 500);				  
				}
				$('.' + targetDiv).html($(html).find('.pagination').parent().html());
				paginationAjax(targetDiv);
				reRunableFunctions();
			}
		});	
	}
}

function ajaxSubmit(submitTo,dataString,returnMessageElement) {
	$.ajax({
		type: "POST",
		url: submitTo,  
		data: dataString,  
		success: function(html) {
			$(returnMessageElement).append(html);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			$(returnMessageElement).append('<p class="error">Error</p>');
		}
	});
}

function startTheAjaxPagination() {
	$('div.pagination').parent().each(function(){
		var randomName = Math.round(Math.random() * 100000);
		$(this).addClass('rp' + randomName);
		if ($(this).find('.autotimerenable').html() == 1) {
			paginationAjaxAuto('rp' + randomName);
		} else {
			paginationAjax('rp' + randomName);
		}
	});
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function divExpander(itemInFocus) {
	$(itemInFocus).hover(function(){
		$(this).find('div:first').next().show();
	},function() {
		$(this).find('div:first').next().hide();
	});
}

function showCorrectOddsType (type) {
	$('.price_fractional').hide();
	$('.price_european').hide();
	$('.price_american').hide();
	$('.price_starting').hide();
	$('.' + type).show();
	$(document.getElementById('odds-type-switcher')).find('span').removeClass('active');
	$(document.getElementById('odds-type-switcher')).find('span.sprite_' + type).addClass('active');
	$.cookie('price_type', type, { expires: 30, path: '/' });
	$('#content div.odd-list ul li, .scores, .best-odds, .oddprice').each(function() {
		if ($(this).find('.price_fractional').html() == "") {
			$(this).find('.price_fractional').hide();
			$(this).find('.price_european').hide();
			$(this).find('.price_american').hide();
			$(this).find('.price_starting').show();
		};
	});
}

function showCorrectOddsTypeSetup() {
	$('#odds-type-switcher').find('span').each(function(){
		$(this).click(function(){
			showCorrectOddsType($(this).attr('title'));
		});
	});
	if ($.cookie('price_type') == "price_fractional" || $.cookie('price_type') == "price_european" || $.cookie('price_type') == "price_american") {
		showCorrectOddsType($.cookie('price_type'));
	}
}

function jqueryPopups3() {
	$('a.popup, .banner a, a.odd-popup, a.auto-external').unbind('click');
	$('a.popup, .banner a, a.auto-external').click(function(){	 
		window.open(this.href);
		return false;
	});
	$('a.odd-popup').click(function(){	 
		var strWidth = "1024";
		var strHeight = "580";
		window.open($(this).attr('href'),"myWindow","resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width=640,height=480,top=0,left=0");
		return false;
	});
	$('#content a').each(function(){
		if ($(this).hasClass('popup')) {
			$(this).click(function(){
				googleTrack("Content: " + $(this).attr('href'),"Post external link");
			});
		} else {
			if ($(this).hasClass('auto-external')) {
				$(this).click(function(){
					googleTrack("Content: " + $(this).attr('href'),"Post external link");
				});
			} else {
				if ($(this).attr('href')) {
					if ($(this).attr('href').substr(0,7) == 'http://') {
						if ($(this).attr('href').substr(0,siteURLlength) == siteURL) {
						} else {
							$(this).addClass('auto-external');
							$(this).click(function() {
								googleTrack("Content: " + $(this).attr('href'),"Post external link");
								window.open(this.href);
								return false;
							});
						}
					}
				}
			}
		}
	});
}
var autoTimers=new Array();
var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};
	return function (date, mask, utc) {
		var dF = dateFormat;
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) {
		} else {
			mask = String(dF.masks[mask] || mask || dF.masks["default"]);
			if (mask.slice(0, 4) == "UTC:") {
				mask = mask.slice(4);
				utc = true;
			}
			var	_ = utc ? "getUTC" : "get",
				d = date[_ + "Date"](),
				D = date[_ + "Day"](),
				m = date[_ + "Month"](),
				y = date[_ + "FullYear"](),
				H = date[_ + "Hours"](),
				M = date[_ + "Minutes"](),
				s = date[_ + "Seconds"](),
				L = date[_ + "Milliseconds"](),
				o = utc ? 0 : date.getTimezoneOffset(),
				flags = {
					d:    d,
					dd:   pad(d),
					ddd:  dF.i18n.dayNames[D],
					dddd: dF.i18n.dayNames[D + 7],
					m:    m + 1,
					mm:   pad(m + 1),
					mmm:  dF.i18n.monthNames[m],
					mmmm: dF.i18n.monthNames[m + 12],
					yy:   String(y).slice(2),
					yyyy: y,
					h:    H % 12 || 12,
					hh:   pad(H % 12 || 12),
					H:    H,
					HH:   pad(H),
					M:    M,
					MM:   pad(M),
					s:    s,
					ss:   pad(s),
					l:    pad(L, 3),
					L:    pad(L > 99 ? Math.round(L / 10) : L),
					t:    H < 12 ? "a"  : "p",
					tt:   H < 12 ? "am" : "pm",
					T:    H < 12 ? "A"  : "P",
					TT:   H < 12 ? "AM" : "PM",
					Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
					o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
					S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
				};
	
			return mask.replace(token, function ($0) {
				return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
			});
		
		}
		
	};
}();

dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};

function convertUTCtoLocal(inputDate,conversionFormat,returnType){	
	wasMozilla = "";
	jQuery.each(jQuery.browser, function(i, val) {
		if (i == "mozilla"){
			wasMozilla = "yes";
		}
	});
	if (wasMozilla == "yes") {
		inputDate = inputDate;
	} else {
		inputDate = inputDate.replace(/-/gi,"/");
	}
	if ($.browser.mozilla) {
		inputDate = inputDate;
	} else {
		inputDate = inputDate.replace(/-/gi,"/");
	}
	var localDate = new Date(inputDate);
	offset = localDate.getTimezoneOffset();
	newDate = Date.parse(inputDate) - (offset *60 * 1000);
	veryNewDate = new Date(newDate);
	finalDate = dateFormat(veryNewDate, conversionFormat);
	return finalDate;	
}

function processDate() {
	$('.date').each(function(){
		if ($(this).hasClass('done')) {
		} else {
			if ($(this).text() != "0000-00-00 00:00:00" && $(this).text() != "") {
				dateToPass = $(this).text();
				jQuery.each(jQuery.browser, function(i, val) {
					if (i == "mozilla"){
						dateToPass = dateToPass.replace(' ','T');
					}
				});
				conversionFormat = $(this).attr('rel');
				finalDateFormat = convertUTCtoLocal(dateToPass,conversionFormat);
				$(this).attr('title',convertUTCtoLocal(dateToPass,$(this).attr('rev')));
				$(this).text(finalDateFormat);
			} else {
				$(this).text("-- No date --");
			}
			$(this).addClass('done');
		}
	});
}

function makelink() {
	$('.makelink').unbind();
	$('#content .odd-list li.makelink').click(function(){
		googleTrack($(this).find('a:first').attr('href'),"Event odds");
	});
	$('.makelink').each(function(){	
		if ($(this).hasClass('link-noeventid')) {
			$(this).removeClass('makelink');
		}
	});
	$('.makelink').click(function(){
		if ($(this).hasClass('link-popup')) {
			var strWidth = "1024";
			var strHeight = "580";
			window.open($(this).find('a:first').attr('href'),"myWindow","resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width=640,height=480,top=0,left=0");
			target = $(this).find('a:first').attr('href');
			clickedArea = "makelink";
			pageTracker._trackEvent('Target: ' + target, clickedArea, 'Location: ' + window.location.href, 1);
			$('#test').html($('#test').html() + ' <br />' + 'Target: ' + target + ' | ' + clickedArea + ' | ' + 'Location: ' + window.location.href);
			return false;
		} else {
			window.location = $(this).find('a:first').attr('href');
		}
	});
}

function setUpLists() {
	$('ul').each(function(){
		$(this).find('li:first').addClass('first');
		$(this).find('li:last').addClass('last');
	});
}

function tweetLinking() {
	var test = "http://twitter.com/search?q=%23";
	$('.tweetformat').each(function(){
		if ($(this).hasClass('fixed') == false) {
			$(this).html($(this).html().replace(/#(.*?)(\s|$)/g,'<a class="hash" href="$1">#$1 </a>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,'<a href="$&">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g,'<a class="twitteruser" href="http://twitter.com/$1">@$1 </a>$2'));
			$(this).find('.hash').each(function(){
				$(this).attr('href',test + $(this).attr('href'));
			});
			$(this).find('.twitteruser,.hash').click(function(){
				window.open(this.href);
				return false;
			});
			$(this).addClass('fixed');
		}
	});
}

function debugInfo() {
		$('#debuginfo').each(function(){
		if ($(this).html() !== "") {
			$(this).prepend('<img src="/images/furniture/close-button.gif" class="close" alt="" />' + '<img src="/images/furniture/full-screen.gif" class="icon" alt="" />');
			$('#debuginfo img.icon').click(function(){
				$('#debuginfo').toggleClass('expand');
			});
			$('#debuginfo img.close').click(function(){
				$('#debuginfo').toggleClass('hide');
				 $.cookie('debugstatus', 'true', { expires: 9999, path: '/', domain: window.location.host });
			});
		} else {
		}
	});
}

function oddsDisplayTidy2() {
	$('.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("-");
		}
	});
	$('.had-draw').each(function(){
		if ($(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("D");
			}
		}
	});	
}

jQuery.fn.mailme = function() {
    var at = / at /;
    var dot = / dot /g;
    this.each( function() {
        var addr = jQuery(this).text().replace(at,"@").replace(dot,".");
        var title = jQuery(this).attr('title')
        $(this)
            .after('<a href="mailto:'+addr+'" title="'+title+'">'+ addr +'</a>')
            .remove();
    });
};

function contentLink() {
	var siteURL = "http://" + window.location.host;
	$('#post-content').each(function(){
		var post_id = $(this).attr('class');
		var ajaxUrl = siteURL + "/ajax/post_with_links.html"
		var dataString = "post_id=" + post_id;
		$.ajax({
			url: ajaxUrl,
			data: dataString,
			success: function(html) {
				$('#post-content').html(html);
				reRunableFunctions();
			}
		});	
	});
}

function changeFeatured() {
	$(document.getElementById('featured-select-list')).find('.thumb').click(function(){
		$(document.getElementById('featured-select-list')).find('.thumb').parent().removeClass('selected');
		$(this).parent().addClass('selected');
		$(document.getElementById('featured-current')).html($(this).parent().find('.main').html());
	});
}

function cycleFeature() {
	$('#featured-select-list').find('li:last').addClass('last');
	$('#featured-select-list').find('li:first').addClass('first');	
	$('#featured-select-list li.selected').each(function(){
		$(this).removeClass('selected');
		if ($(this).hasClass('last')) {
			$(this).parent().find('.first').addClass('selected');
			$('#featured-current').html($(this).parent().find('.first').find('.main').html());
		} else {
			$(this).next().addClass('selected');
			$('#featured-current').html($(this).next().find('.main').html());
		}
	});
}

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
