var returnController = 'welcome';
var back = false;
var landingPageVisible = false;

$(function(){
	
	$('#slide-landingpage').click(function(){
		var margin = 0;
		if (landingPageVisible){
			margin = -569;	
		}
			
		landingPageVisible = !landingPageVisible;
		
		$('#flash').animate({
			marginTop: margin
		}, 1000, function() {
			// Animation complete
		});
		
		
	});
	
		
	// Loading content...
	$('#content-welcome-top').click(function(){		
		removeContent();		
		returnController = 'welcome';
		back = false;
		loadContent('/site/welcome');			
	});
	
	$('#content-news-top, #content-news-bottom').click(function(){
		removeContent();
		returnController = 'news';
		back = true;
		loadContent('/site/news');	
	});
	
	$('#content-band-top, #content-band-bottom').click(function(){
		removeContent();
		returnController = 'band';
		back = true;
		loadContent('/site/band');	
	});
	
	$('#content-live-top, #content-live-bottom').click(function(){
		removeContent();
		returnController = 'live';
		back = true;
		loadContent('/site/live');	
	});
	
	$('#content-community-top, #content-community-bottom').click(function(){
		removeContent();
		returnController = 'community';
		back = true;
		loadContent('/site/community');	
	});
		
	$('#content-fanclubs-top, #content-fanclubs-bottom').click(function(){
		removeContent();
		returnController = 'fanclubs';
		back = true;
		loadContent('/site/fanclubs');	
	});
	
	$('#content-store-top, #content-store-bottom').click(function(){
		removeContent();
		returnController = 'store';
		back = true;
		loadContent('/site/store');	
	});
		
	$('#content-contact-top').click(function(){
		removeContent();
		returnController = 'contact';
		back = true;
		loadContent('/site/contact');	
	});
		
	$('#content-imprint-bottom').click(function(){
		removeContent();
		returnController = 'imprint';
		back = true;
		loadContent('/site/imprint');	
	});
	
//---Facebook
	$('#content-facebook-top').click(function(){
		removeContent();
		returnController = 'facebook';
		back = true;
		loadContent('/site/facebook');	
	});
//---Facebook /	
	
	// Live functions
	// Read more
	$('div.readmore a').live('click', function() {
		var idAttr = $(this).attr('id');
		var last = idAttr.lastIndexOf('-');
		var id = idAttr.substr(last+1);
		var url = '/site/article/display/back/' + back + '/id/' + id;
		removeContent();
		loadContent(url);	
	});
	
	// Back
	$('div.back a').live('click', function() {
		var url = '/site/' + returnController;
		removeContent();
		loadContent(url);	
	});
	
});

function loadContent(loadUrl) {
	$.ajax({
		url: loadUrl,			
		dataType: 'html',
		success: function(data) {
			displayContent(data);			
		}
	});
}

function removeContent() {
	var contentHeight = $('#collapsible-content').height();
	$('#collapsible-content').children().remove();
	$('#collapsible-content').height(contentHeight);
	displayLoading();
}

function displayContent(data) {
	$('#measure-content').append(data);
	var contentHeight = $('#measure-content').height();
	
	$('#collapsible-content').animate({
		height: contentHeight
	}, 1000, function() {
		$('#measure-content').children().remove();
		$('#collapsible-content').children().remove();
		$('#collapsible-content').append(data);
		$('#collapsible-content').find('a[rel=lightbox]').lightbox({
			fileLoadingImage: '/css/site/img/lightbox/loading.gif',
			fileBottomNavCloseImage: '/css/site/img/lightbox/close.gif'
		});		
	});
}

function displayLoading() {
	$('#collapsible-content').append('<div id="loading-animation"><img src="/css/site/img/lightbox/loading.gif"></div>');	
}

