var contentShowing = true;
var currentContent = 'home.php';
var paused = false;
var muted = false;
var flashReady = false;

// Load more news button
function loadMoreNews(){
	$('#load_more').click(function(){
		// Get the number of news items already there.
		var newsNumber = $('#news .nContent').size();
		$.get('morenews.php?start=' + newsNumber, function(data){
				$('#news').append(data);
		});
		return false;
	});
}

// function muteVideo(mute){
// 	swfobject.getObjectById("flash")._muteVideo(mute);
// }
// 
function outputStatus(e){
	// alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
	if (e.success == true) {
		flashReady = true;
	};
}

function pauseVideo(pause){
	// alert(flashReady);
	if (flashReady == true) {
		swfobject.getObjectById("flash")._pauseVideo(pause);
		if (pause) {
			$('.hide_content').text('Start Video');
		}
	};
}

function muteVideo(mute){
	swfobject.getObjectById("flash")._muteVideo(mute);
}

function externalLinks(){
	//External links.
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
}

$(document).ready(function(){

	externalLinks();

	$('#div_menu').css('opacity', '0.2');

	$('.hide_content').click(function(){
		if (contentShowing == true) {
			$('#content').animate( { marginLeft:'-9999px'}, 200);
			$(this).text('Show Content');
			pauseVideo(false);
			contentShowing = false;
		} else {
			$('#content').animate( { marginLeft:'-475px'}, 200);
			contentShowing = true;
			$(this).text('Hide Content');
			pauseVideo(true);
		}
		return false;
	});
	
	
	$('.mute_video').click(function(){
		if (muted == false) {
			muteVideo(true);
			muted = true;
			$(this).text('UN-MUTE VIDEO');
		} else {
			muteVideo(false)
			muted = false;
			$(this).text('MUTE VIDEO');			
		}
		return false;
	});
	

	$.address.change(function(event) {

		if (event.parameters.id) {
			// News page links
			$('.nContent').hide();
			$('#news' + event.parameters.id).show();
		} else if (event.path != currentContent){
			// alert(event.path + " != " + currentContent);
			switch (event.path) {
				case '/':
					// Home page
					currentContent = 'home.php';
					$('.hide_content').text('Hide Content');
					pauseVideo(false);
					break;

				case '/lyrics':
					// Lyrics page
					currentContent = 'lyrics.php';
					pauseVideo(true);
					break;

				default:
					// Load the content.
					currentContent = './' + event.value + '.php';
					pauseVideo(true);
					break;
			}
			
			$('#content').fadeOut(function(){
				$.get(currentContent, function(data){
					$('#content').html(data).fadeIn();
					loadMoreNews();
					$(".photolink").colorbox();
				});
			});
		}
	 });
	
	var flashMovie = $('#flash');
	
	if (jQuery.browser.msie) {
	  if(parseInt(jQuery.browser.version) == 6) {
			$(window).scroll(function() {
				$('#flash').css('top', $(this).scrollTop());
			});

			$(window).scroll(function() {
				$('#control_links').css('bottom', $(this).scrollTop());
			});
			
	  }
	}
});

