var playerURL = '';
var playing = false;
var teaserShown = true;
var autoLoadPics = true;

function loadRandomPic() {
	if (autoLoadPics) {
		new conclurerAjaxRequest({
			url: _BASEPATH+'library/randomPic.php',
			onRequestComplete: function (t) {
				setTeaserPhoto(t,false,true);
			}
		});
	}
	window.setTimeout(loadRandomPic, 10000);
}

function pageLoad() {
	e('menubar').move(0,0,'explosion');
	e('playbutton').clickEv(function() {
			if (playing) {
				pauseMusic();
				e('playbutton').style.backgroundPosition = '0px 0px';
				playing = false;
			}
			else {
				playMusic();
				e('playbutton').style.backgroundPosition = '0px -27px';
				playing = true;
			}
	});
	loadRandomPic();
	loadPage('news.html');
	startPlay('music/'+song);
	addNavButton('NEWS+CHARTS', function () { showTeaser(function () { autoLoadPics = true; loadPage('news.html'); }); return true; });
	addNavButton('ABOUT ME', function () { hideTeaser(function () { autoLoadPics = true; loadPage('about.html'); }); return true; });
	addNavButton('MUSIC', function () { hideTeaser(function () {loadPage('music.php');}); return true; });
	addNavButton('GALLERY', function () { showTeaser(function () { autoLoadPics = true; loadAlbums(); }); return true; });
	addNavButton('GUESTBOOK', function () { window.location.href="http://265576.guestbook.onetwomax.de/?vd=061102"; return true; });
	addNavButton('CONTACT', function () { hideTeaser(function () {loadPage('contact.html');}); return true; });
}

function startPlay (t) {
	if (!playing) e('playbutton').style.backgroundPosition = '0px -27px';
	playMusic(t);
	playing = true;
}

function hideTeaser(f) {
	if (teaserShown) {
		e('teasermain').fadeOut(function () {e('contentmain').move(0, 100, 'blast'); if (f) f();});
		
		teaserShown = false;
	}
	else {
		if (f) f();
	}
}

function showTeaser(f) {
	if (!teaserShown) {
		e('contentmain').move(0, 664, 'blast');
		window.setTimeout(function () {e('teasermain').fadeIn(function () { if (f) f(); });},300);
		
		teaserShown = true;
	}
	else {
		if (f) f();
	}
}

function addNavButton(title, onclick) {
	var tmp = e('navbase').addHtml('div', title);
	tmp.className = 'nav';
	e(tmp.id).clickEv(onclick);
}

function player() {
	return document.getElementById("musicPlayer");
}
function playMusic (t) {
	if (!t) {
		if (playerURL == '') {
			playerURL = 'music/'+song;
			player().SetVariable("method:setUrl", playerURL);
			player().SetVariable("method:play", "");
		}
		else {
			player().SetVariable("method:play", "");
		}
	}
	else {
		playerURL = t;
		player().SetVariable("method:setUrl", playerURL);
		player().SetVariable("method:play", "");
	}
}
function pauseMusic() {
	player().SetVariable("method:pause", "");
}

function setTeaserPhoto(t, nofade, nobreak) {
	if (!nobreak) autoLoadPics = false;
	if (!nofade)e('imgframe').fadeOut(function () {
		e('imgframe').style.backgroundImage = 'url('+t+')';
		e('imgframe').fadeIn();
	});
	else e('imgframe').style.backgroundImage = 'url('+t+')';
}

function loadAlbums() {
	loadPage('gallery.php?action=albums');
}

function loadAlbum(t) {
	loadPage('gallery.php?action=album&t='+t);
}

function loadPage (t) {
	if (t) {
		new conclurerAjaxRequest({
			url: _BASEPATH+'pages/'+t,
			onRequestComplete: function (t) {
				e('contentmain').content(t);
			}
		});
	}
}

function dlPic(t) {
	window.open(t);
}
