/**
 * @author David Sugden
 */
var onlineNow = false;
hideOnlineNow = function(event) {
	$("#onlinenow").slideUp("normal", function() {
		$("#onlinenow").remove();
		onlineNow = false;
	});
};
showOnlineNow = function(event) {
	if ( ! onlineNow ) {
		onlineNow = true;
		$.get("/onlinenow.php", function(data) {
			$("#onlineUL").append('<div id="onlinenow">'+data+'</div>');
			$("#onlinenow").slideDown("fast", function() {
				$(this).bind("click", hideOnlineNow);
			});
		});
	}
	event.preventDefault();
};
closeNewComments = function(permanent) {
	$('#title').slideUp('slow');
	if (permanent == '1') {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + 365);
		document.cookie = 'showNewComments=0;expires=' + exdate.toGMTString();
	}
};
newComments = function(count) {
	if ( count == 1) {
		$('#home').append('<div id="title"><p>There is <a href="/comments/">1 new comment</a> since your last visit. (<a href="#" onclick="javascript:closeNewComments(\'0\');return false;">close</a> | <a href="#" onclick="javascript:closeNewComments(\'1\');return false;">never show again</a>)</p></div>');
	} else {
		$('#home').append('<div id="title"><p>There are <a href="/comments/">'+count+' new comments</a> since your last visit. (<a href="#" onclick="javascript:closeNewComments(\'0\');return false;">close</a> | <a href="#" onclick="javascript:closeNewComments(\'1\');return false;">never show again</a>)</p></div>');			
	}
	$('#title').slideDown('slow');
};
closeTitle = function() {
	$('#title').slideUp('slow');
};
openEditBand = function(count) {
	$('#bands').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this band profile</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditBlog = function(count) {
	$('#blogs').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this page</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditCDReview = function(count) {
	$('#recorded').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this CD Review</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditLiveReview = function(count) {
	$('#live').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this Live Review</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditInterview = function(count) {
	$('#interviews').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this Interview</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditProfile = function(count) {
	$('#profiles').append('<div id="title"><p>You can <a href="/profile/">edit this user profile</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditDownload = function(count) {
	$('#mp3s').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this download page</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
openEditNews = function(count) {
	$('#news').append('<div id="title"><p>You can <a href="/article/edit/'+article_id+'/">edit this news article</a>. (<a href="#" onclick="javascript:closeTitle();return false;">close</a>)</p></div>');
	$('#title').slideDown('slow');
};
menuToggle = function(menu) {
	if ( menu == 1) {
		$('.secondMenu').css({display: "none"});
		$('.firstMenu').css({display: "inline"});
	} else {
		$('.secondMenu').css({display: "inline"});
		$('.firstMenu').css({display: "none"});		
	}
};
//Stuff that can be done once the page is ready (but not fully loaded).
$(document).ready(function(){
	if (top != self) {
		top.location.replace(self.location.href);
	}
	if ( top.location.hostname != currentHostName ) {
		top.location.href = 'http://'+currentHostName+currentPage;
	}
	$corners = $('div.contentContainer');
	$corners.corner('round 10px');
});
//  Stuff that can be delayed until the page has fully loaded.
$(window).load(function(){
	$("#resources a:contains('Online Now')").bind("click", showOnlineNow);
	$('span.email').each( function() {
		var emailAddress = $(this).html().replace(" [ at ] ", "@");
		$(this).replaceWith('<a href="mailto:'+emailAddress+'">'+emailAddress+'</a>');
	});
	$('#featuretext span.seeLink').replaceWith('<a href="http://www.seetickets.com/see_multi/price.asp?code=418708&filler1=see&filler2=multisee&pgroup=all&orderby=dpostage&filler3=id1leedsmusicscene">See Tickets</a>');
	$('#featuretext span.ticketmasterLink').replaceWith('<a href="http://ticketsuk.at/davesugden?DURL=www.ticketmaster.co.uk/Leeds-Festival-tickets/artist/958477">Ticketmaster</a>');
	$("#ticketsearch p").html('Loading latest Leeds gig tickets...').each(function() {
		$(this).feed();
	});
	var $search = $("#searchstring");
	var $search2 = $("#searchstring2");
	$search.val('Site Search');
	$search.focus(function() {
		$(this).val('');
	});
	$search2.val('Site Search');
	$search2.focus(function() {
		$(this).val('');
	});
	$search2.blur(function() {
		$(this).val('Site Search');
	});

});