var contentDown = false, contentAnim = '';
var bandDown = false, bandAnim = '';
var t1 = null, t2 = null;

function loadSite(siteURL) {
	// if visible, hide band_hint layer
	if (bandDown || bandAnim != '') {
		if (bandAnim != '') {
			// kill running animation of the band-hint layer
			t2.stop();
			t2.onMotionFinished = null;
			bandAnim = '';
		}
		t2 = new Tween(document.getElementById('band_hint').style, 'top', Tween.strongEaseIn, parseInt(document.getElementById('band_hint').style.top), -2000, 0.4, 'px');
		bandDown = false;
		bandAnim = 'up';
		t2.start();
		t2.onMotionFinished = function() {
			bandAnim = '';
			readSite(siteURL);
		}
	} else {
		readSite(siteURL);
	}
}

function readSite(siteURL) {
	// offers a clean tween-animation using firefox (for scrollable layers)
	document.getElementById('content').style.overflow = 'hidden';

	if (contentDown) {
		if (contentAnim != '') {
			// remove the finished function for the current tween animation
			t1.stop();
			t1.onMotionFinished = null;
			contentAnim = '';
		}
	
		// layer is already shown
		t1 = new Tween(document.getElementById('paper').style, 'top', Tween.strongEaseIn, document.getElementById('paper').offsetTop, -900, .6, 'px');
		contentAnim = 'up';
		contentDown = false;
		t1.start();
		t1.onMotionFinished = function() {
			//contentAnim = '';
			var myAjax = new Ajax.Request(
		    	siteURL + '?rand=' + Math.random(),
		    	{ method: 'get', onComplete: showSite }
			);
		}
	} else {
		// layer is hidden yet
		var myAjax = new Ajax.Request(
		    siteURL,
		    { method: 'get', onComplete: showSite }
		);
	}
}

function showSite(originalRequest) {
	// hide clickable band images
	document.getElementById('band_left').style.top = '-2000px';
	document.getElementById('band_right').style.top = '-2500px';
	
	// load site
	document.getElementById('content').innerHTML = originalRequest.responseText;
	showContentLayer();
}

function showContentLayer() {
	if (!contentDown) { // && !bandDown && bandAnim == '') {
		if (contentAnim != '') {
			t1.stop();
			t1.onMotionFinished = null;
			contentAnim = '';
		}
	
		t1 = new Tween(document.getElementById('paper').style, 'top', Tween.elasticEaseOut, document.getElementById('paper').offsetTop, -200, 1.5, 'px');
		contentAnim = 'down';
		t1.start();
		// offers a clean tween-animation using firefox (for scrollable layers)
		t1.onMotionFinished = function() { 
			document.getElementById('content').style.overflow = 'auto';
			contentDown = true;
			contentAnim = '';
		}
	}
}

function showBand() {
if (!bandDown && bandAnim != 'down') {
	if (contentAnim != '') {
		t1.stop();
		t1.onMotionFinished = null;
		contentAnim = '';
	}

	// hide content-layer
	t1 = new Tween(document.getElementById('paper').style, 'top', Tween.strongEaseIn, document.getElementById('paper').offsetTop, -900, .6, 'px');
	contentAnim = 'up';
	t1.start();
	t1.onMotionFinished = function() {
                document.getElementById('content').innerHTML = '';
		contentDown = false;
		contentAnim = '';
		if (!bandDown) {
			t2 = new Tween(document.getElementById('band_hint').style, 'top', Tween.elasticEaseOut, -2000, -1745, 1.4, 'px');
			bandAnim = 'down';
			t2.start();
			t2.onMotionFinished = function() { 
				bandDown = true;
				bandAnim = '';
			}
		}
	}
	
	// show clickable band images
	document.getElementById('band_left').style.top = '-700px';
	document.getElementById('band_right').style.top = '-1060px';
}
}


// speed - the smaller the faster
var speed = 100; 
// vertical - positive values == from top to bottom; 
// vertical - negative values == from bottom to top
var vertical = -0.75; 
// the size of the scroller
var size_y = 25;
var y = size_y;
// wait while displaying one concert
var isWaiting = false;
var waitInterval = 3000;

function scroll() {
	if (!isWaiting) {
		var concertScroll = document.getElementById('concert_scroll');
		if ((-y) >= ((concertScroll.offsetHeight - 14)))
			y = size_y;
		else
			y = y + vertical;
			
		if ((y == -0.5) || (y == -20)) {
			// wait for 3 seconds
			isWaiting = true;
			setTimeout('isWaiting = false;', waitInterval);
		} else {
			concertScroll.style.top = y + 'pt';
			concertScroll.style.display = 'block';
		}
	}
}
      
function initScroller() {
	// setInterval('scroll()', speed);
}


function debugHelping() {
	if (!isWaiting) {
		var concertScroll = document.getElementById('concert_scroll');
		if ((-y) >= ((concertScroll.offsetHeight - 14)))
			y = size_y;
		else
			y = y + vertical;
			
		if ((y == -0.5) || (y == -20)) {
			// wait for 3 seconds
			isWaiting = true;
			setTimeout('isWaiting = false;', waitInterval);
		} else {
			concertScroll.style.top = y + 'pt';
			concertScroll.style.display = 'block';
		}
	}
	document.getElementById('concert_scroll').innerHTML = 'contentDown: '+contentDown+'<br/>contentAnim: '+contentAnim;
}

