// eatmusic specific code.

function update_content(page) {
	$('#content-fallback').hide();
	content_url = 'lib/getcontent.php?page=' + page;
	$('#content').fadeOut("fast", function() {
		if (page != '/') {
			$('#content').load(content_url, function() {
				$('#content').fadeIn("fast");
				set_links();
				Vanadium.init();
			})
		}
	});
}

function set_links() {
/*	$('.nav').click(function() {
		$.address.value($(this).attr('href'));
		new_page = this.getAttribute('rel');
		if (new_page != current_page) {
			current_page = new_page;
			update_content(new_page);
		}
		this.blur();
		return false;
	});
*/

	$('.content_link').click(function() {
		$.get($(this).attr('href'), function(data) {
			$('.content .detail').html(data);
			$('.content .detail').fadeIn('slow');
			set_links();
			$('#close_button').fadeIn('slow');
		});
		return false;
	});
	
	$('#close_button').click(function() {
		$('.content .detail').fadeOut('slow');
		$('#close_button').fadeOut('slow');
	});
	
	$('.listen').click(function() {
		listen_id = $(this).attr('rel');
		if ($(this).hasClass('explicit_warning')) {
			if (confirm('Warning: Explicit Content. Do you wish to continue?')) {
				listen_window = window.open('listen.php?id='+listen_id, 'eatmusic_listen', 'resizable=1,status=1,scrollbars=0,width=450,height=230');
			}
		}
		else {
			listen_window = window.open('listen.php?id='+listen_id, 'eatmusic_listen', 'resizable=1,status=1,scrollbars=0,width=450,height=320');
		}
		this.blur();
		return false;
	});
	
	$('#back-button').click(function() {
		history.back();
		return false;
	});
	
	$('.emailform').submit(function() {
		//setup the ajax email form.
		dataString = $(this).serialize();
		$('.content-spinner').show();
		$('.content-spinner').stop().fadeTo('fast', 0.4);
		$.post($(this).attr('action'), dataString, function(data) {
			$('#emailform').hide();
			$('#post_message').show();
			$('.content-spinner').stop().fadeTo('fast', 0.0);
			$('.content-spinner').hide();
		});
		
		return false;

	});
	
	$('.show').hover(function() {
		$(this).children('a').children('.summary').stop().fadeTo('fast', 1.0);
		$(this).children('a.latest_show').stop().fadeTo('fast', 1.0);
	},
	function () {
		$(this).children('a').children('.summary').stop().fadeTo('fast', 0.0);
		$(this).children('a.latest_show').stop().fadeTo('fast', 0.0);
	});
}

function updateLive() {
	$.getJSON("mpdinfo.php", function(data){
		$('#song_title').html(data.album +' #'+data.track+ ' with '+data.artist);
	});
}

$(document).ready(function(){
	// Call stylesheet init so that all stylesheet changing functions 
	// will work.
	$.stylesheetInit();
	
	$("#showpanes").scrollable({
	    size: 1,
	    clickable: true,
	    loop: true
	}).circular().mousewheel(400);
	
	current_page = '';
	
	$("#news ul").marquee();
	
	$("#listen a").hover(function() {
		$('#listen img').attr('src', 'images/listen_monster_hover.png');
	},
	function() {
		$('#listen img').attr('src', 'images/listen_monster.png');
	});
			
	// When one of the styleswitch links is clicked then switch the stylesheet to
	// the one matching the value of that links rel attribute.
	$('.colour-link').bind('click',
		function(e) {
			$.stylesheetSwitch(this.getAttribute('rel'));
			return false;
		}
	);
	
	$.address.change(function(event) {  
		// do something depending on the event.value property, e.g.
		// $('#content').load(event.value + '.xml');
		update_content(event.value);
	});
	
	$('a.tipTip').tipTip();
	
	set_links();
	
	updateLive();
	setInterval('updateLive()', 5000);

});


