$(function() {

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

	$('.newsSlider ul li').live('click', function() {
		var objId = $(this).attr('id');
		var splitObjId = objId.split('-');
		var id = splitObjId[1];
		showNews(id);
	});

	newsCounter = 1;
	newsMax = 4;

	setInterval("switchNews()", 5000);

	$('.matchbox h4').live('click', function() {
		var id = $(this).attr('id');
		var nextMatch = $('.matchbox #nextGame');
		var lastMatch = $('.matchbox #lastGame');
		if (id == 'next') {
			lastMatch.slideUp();
			nextMatch.slideDown();
		}
		if (id == 'last') {
			nextMatch.slideUp();
			lastMatch.slideDown();
		}
	});

	$('ul#teamscroller > li > a.btn').live('click', function() {
		var parent = $(this).parent();
		var rel = parseInt(parent.attr('rel'));
		parent.hide();
		if ($(this).hasClass('right')) {
			var nextRel = rel + 1;
			//var nextParentSibling = parent.siblings().find('#team-2');
			var nextParentSibling = $('ul#teamscroller > li[rel="' + nextRel + '"]');
			nextParentSibling.show();
		}
		if ($(this).hasClass('left')) {
			var prevRel = rel - 1;
			var prevParentSibling = $('ul#teamscroller > li[rel="' + prevRel + '"]');
			prevParentSibling.show();
		}
	});

});

function switchNews() {
	var selectedItem = $('.newsSlider ul li.selected');
	var objId = selectedItem.attr('id');
	var splitObjId = objId.split('-');
	var id = splitObjId[1];
	var nextId = 0;
	if (id == newsMax) {
		nextId = 1;
	}
	else {
		nextId = parseInt(id) + 1;
	}
	showNews(nextId);
}

function showNews(id) {
	if (id !== undefined && id > 0) {
		var newsBox = $('.newsSlider').find('#news-' + id);
		var selector = $('.newsSlider ul li#select-' + id);
		// hide all news
		$('.newsSlider .newsBox').each(function() {
			$(this).hide();
		});
		// unmark all selectors
		$('.newsSlider ul li').each(function() {
			$(this).removeClass('selected');
		});
		// show selected news
		newsBox.show();
		// mark selector
		selector.addClass('selected');
	}
}


// OLD CMS STUFF

function change_news(title, header, file, link) {
	//div_title = document.getElementById('featured_title');
	//div_title.innerHTML = '<b>'+title+'</b><br/>'+header;
	div_image = document.getElementById('featured_image');
	div_image.style.background = 'url('+file+') no-repeat';
	div_link = document.getElementById('featured_link');
	div_link.href = link;
	div_link.innerHTML = title;
	div_header = document.getElementById('featured_header');
	div_header.innerHTML = header;
}
function stripslashes (str) {
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}
function sendPage() {
	mail_str = "mailto:?";
	mail_str += "body=" + "You have been sent a link from the Leigh East official website %0D%0A%0D%0A" + location.href + "%0D%0A%0D%0ARegards%0D%0A%0D%0ALeigh East";
	location.href = mail_str;
}
function addBookmark(title,url) {
	if (window.sidebar) {
	window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
	window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
	return true;
	}
}
function printPage() {
	window.print();
}
function live(id) {
	document.getElementById('live_fixtures').style.display = 'none';
	document.getElementById('live_results').style.display = 'none';
	document.getElementById('live_tables').style.display = 'none';
	document.getElementById('live_stats').style.display = 'none';
	document.getElementById('live_'+id).style.display = 'block';

	document.getElementById('live_link_fixtures').style.backgroundColor = '#bf1400';
	document.getElementById('live_link_results').style.backgroundColor = '#bf1400';
	document.getElementById('live_link_tables').style.backgroundColor = '#bf1400';
	document.getElementById('live_link_stats').style.backgroundColor = '#bf1400';
	document.getElementById('live_link_'+id).style.backgroundColor = '#990000';

	document.getElementById('live_link_fixtures').style.color = '#FFF';
	document.getElementById('live_link_results').style.color = '#FFF';
	document.getElementById('live_link_tables').style.color = '#FFF';
	document.getElementById('live_link_stats').style.color = '#FFF';
	document.getElementById('live_link_'+id).style.color = '#FFF';
}

function album(file) {
	document.getElementById('img_large').src = 'http://www.merseytigers.co.uk/gallery/'+file;
}
