﻿lastHash = '';
ajaxadd = '';
cookieoptions = { path: '/' };
teasertrans = false;

playerradio = new Object();
tpobject = new Object();

function $$(string) {
	return document.getElementById(string);
}

function embedyoutube() {
	if(jQuery.trim($('#youtubeplayer').html()) != '') {
		var so = new SWFObject($('#youtubelink').attr('href'), 'youtubevideo', '303', '181', '10', '#000000');
		so.addParam('allowFullScreen', 'true');
		so.addParam('allowscriptaccess', 'always');
		so.write('youtubeplayer');
	}
}

function afterajax() {
	embedyoutube();
	
	if($('.ituneslink').length == 1 && $('.ituneslink').attr('href') != '')
		$('.ituneslink').css('display', 'block');
	
	if($('#teaser').height() < $('#content').height())
		$('#followus').css({height: ($('#content').height()-$('#teaser').height())+3+$('#followus').height()+'px'});
	else
		$('#content').css({height: ($('#teaser').height()-3)+'px'});

	if($('#trackpodlisting a').length >= 1) {
		tpobject.appendTo('trackpodwrap', 'trackpod');
		$('#tpobject').disableSelection();
		tpobject.url = $('#trackpodlisting a').attr('title')+'.mp3';
	}
	
	if(lang != window.location.hash.substring(1,3)) {
		lang = window.location.hash.substring(1,3)
		$('#radiolist').load('http://'+window.location.hostname+'/'+ajaxadd+lang+'/radio.html #actuallist>*');
	}
	
//	if($('#actuallist').length == 1) {
//		var temp = $('#actuallist').html();
//		$('#radiolist *').remove();
//		$(temp).appendTo('#radiolist');
//		playerradio.url = './radioplayer/'+$('#track').text();
//	}
}

function pollHash() {
	if(lastHash == '#') {
		if(window.location.hostname == 'www.kyauvsalbert.de')
			window.location.hash = '#de/home';
		else
			window.location.hash = '#en/home';
	}
	if(lastHash !== window.location.hash) {
		lastHash = window.location.hash;
		
		if($('#tpobjectobject').length == 1)
			tpobject.reset();
		
		if(lastHash != '') {
			$(document).scrollTop(0);
			$('#pagewrapper').load('http://'+window.location.hostname+'/'+ajaxadd+lastHash.replace('#', '')+'.html #page', function(responseText, textStatus, XMLHttpRequest) {
				setTimeout("afterajax()", 200);
				document.title = responseText.slice(responseText.search(/<title>/)+7, responseText.search(/<\/title>/)).replace('&amp;','&');
			});
		}

	}
}

function hideradio() {
	if($('#radiolist').css('display') == 'none') {
		$('#radioplayer').animate({
			marginTop: '-24px'
		});
	}
}

$(document).ready(function () {
	if(lastHash == '' && window.location.hash == '')
		window.location.hash = '#en/home';
	setInterval("pollHash()", 100);
	
	if($('#headerimg').length == 1) {
		$('#headerimg').livequery(function(){
			$('#headerimg').cycle({ 
			    fx:     'fade',
			    speed:   1000, 
			    timeout: 6000
			});
		});
	}
			
	lang = window.location.hash.substring(1,3);
	
	$('#content').css('margin-bottom', 0);
	
	$('#radiolist').livequery(function() {
		$(this).css({
			display: 'none'
		});
		$('#podcastlink').css({
			display: 'none'
		});
		setTimeout("hideradio()", 20000);
	});
	
	$('#radioplayer').livequery(function(e) {
		$('#radioflap, #radionowplaying').click(function() {
			if($('#radiolist').css('display') == 'none') {
				$('#radiolist').css({
					display: 'block'
				});
				$('#radiowrapper').css({
					top: '0'
				});
				$('#playerradio').css({
					marginTop: '0'
				});
				$('#podcastlink').css({
					display: 'block'
				});
				$('#radionowplaying').css('display', 'none');
				$('.flapdown').removeClass('flapdown').addClass('flapup');
			}
			else {
				$('#radiolist').css({
					display: 'none'
				});
				$('#podcastlink').css({
					display: 'none'
				});
				$('#radiowrapper').css({
					top: '-4px'
				});
				$('#playerradio').css({
					marginTop: '4px'
				});
				$('#radionowplaying').css('display', 'block');
				$('.flapup').removeClass('flapup').addClass('flapdown');
			}
		});
		$(this).hover(
			function(){
				$(this).stop();
				$(this).animate({
					marginTop: '0'
				});
			},
			function(){
				$(this).stop();
				if($('#radiolist').css('display') == 'none') {
					$(this).animate({
						marginTop: '-24px'
					});
				}
			}
		);
	});
	$('#radiolist').css({
		minHeight: '447px',
		background: '#000000'
	});
	
	$('#radiowrapper').css('display', 'block');
	playerradio = new Musicplayer('playerradio');
	playerradio.appendTo('playerwrap', 'player');
	//playerradio.url = './radioplayer/'+$('#trackpodlisting a').attr('rel');
	$('#playerradio').disableSelection();
	
	$('#radiolist').load('http://'+window.location.hostname+'/'+ajaxadd+lang+'/radio/firstlistwithsound.html #actuallist>*', function(responseText) {
		if(playerradio) {
			playerradio.url = './radioplayer/'+$('#radiolist .radiotrack').text();
			//setTimeout("playerradio.play()", 2000);
			$('#radionowplaying').text($('#radiolist .singlehead').text()+' '+$('#radiolist .singesubhead').text());
		}
	});
	
	$('.pageradio .sound1').livequery(function() {
		if(this.rel == '')
			$(this).remove();
		else {
			if(playerradio.url == './radioplayer/'+$(this).attr('rel')) {
				$(this).css({
					background: 'url("./templates/kyauandalbert/img/ka_icon2.php5?c=443344_sound") center no-repeat'
				});
			}
			else {
				$(this).css({
					background: 'url("./templates/kyauandalbert/img/ka_icon.php5?c=ffffff_sound") center no-repeat'
				});
			}
		}
	});

	tpobject = new Musicplayer('tpobject');
	if($('#trackpodlisting a').length >= 1)
		tpobject.url = $('#trackpodlisting a').attr('title')+'.mp3';
	
	$('a.trackpodlist').live('click', function(e) {
		e.preventDefault();
		if($(this).attr('title') != '') {
			$('.trackpodlist').each(function(){
				$(this).removeClass('bg_dgreeni');
			});
			$(this).addClass('bg_dgreeni');
			playerradio.pause();
			tpobject.stop();
			tpobject.url = $(this).attr('title')+'.mp3';
			tpobject.play();
		}
	});
	
	$('a.trackpodprev').live('click', function(e) {
		e.preventDefault();
		if(!$.cookie('musicplayerpage'))
			$.cookie('musicplayerpage', 0, cookieoptions);
		if($.cookie('musicplayerpage') > 0)
			$.cookie('musicplayerpage', parseInt($.cookie('musicplayerpage'))-1, cookieoptions);
		$('#trackpodlisting').load('http://'+window.location.hostname+'/'+ajaxadd+lastHash.replace('#', '')+'.html #trackpodlisting > *');
	});
	
	$('a.trackpodnext').live('click', function(e) {
		e.preventDefault();
		if(!$.cookie('musicplayerpage'))
			$.cookie('musicplayerpage', 1, cookieoptions);
		else if($.cookie('musicplayerpage') == (parseInt($('#trackpodamount').html())-1))
			$.cookie('musicplayerpage', (parseInt($('#trackpodamount').html())-1), cookieoptions);
		else
			$.cookie('musicplayerpage', parseInt($.cookie('musicplayerpage'))+1, cookieoptions);
		$('#trackpodlisting').load('http://'+window.location.hostname+'/'+ajaxadd+lastHash.replace('#', '')+'.html #trackpodlisting > *');
	});

	$('a:not(.trackpodlist):not(.trackpodnext):not(.trackpodprev):not(.contentlinker):not(.noajax)').live('click', function(e) {
		if(this.href.indexOf('http://'+window.location.hostname) != -1) {
			e.preventDefault();
			window.location.hash = '#'+this.href.replace('http://'+window.location.hostname+'/'+ajaxadd, '').replace('.html', '');
		}
	});

	$('.list').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				step: function () {
					$('#date_'+this.id.replace('content_','')).css('color', $(this).css('backgroundColor'));
				}
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#77CCEE'}, {
						duration: 400,
						step: function() {
							$('#date_'+this.id.replace('content_','')).css('color', $(this).css('backgroundColor'));
						}
					});
				},
				step: function () {
					$('#date_'+this.id.replace('content_','')).css('color', $(this).css('backgroundColor'));
				}
			});
		}
	});


	$('.homenewsfirst').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				step: function () {
					$('.homeimg').css('backgroundColor', $(this).css('backgroundColor'));
				}
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#77CCEE'}, {
						duration: 400,
						step: function() {
							$('.homeimg').css('backgroundColor', $(this).css('backgroundColor'));
						}
					});
				},
				step: function () {
					$('.homeimg').css('backgroundColor', $(this).css('backgroundColor'));
				}
			});
		}
	});
	$('.homenews').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#77CCEE'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.newswidget, .newswidgetfirst').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#0099BB'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#77CCEE'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.guestbookwidget, .guestbookwidgetfirst').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#FFCC66'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#FFCC66'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#FFEEBB'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.pagenews .blogcomment a span').livequery(function(){
		if($(this).parent().attr('href') == '')
			$(this).unwrap();
	});
	
	$('.pageguestbook .guestbooklist a span').livequery(function(){
		if($(this).parent().attr('href') == '')
			$(this).unwrap();
	});
	
	$('.guestbooklist').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#FFCC66'}, {
				duration: 200,
				step: function () {
					$('#date_'+this.id.replace('guestbook_','')).css('color', $(this).css('backgroundColor'));
				}
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#FFCC66'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#FFEEBB'}, {
						duration: 400,
						step: function() {
							$('#date_'+this.id.replace('guestbook_','')).css('color', $(this).css('backgroundColor'));
						}
					});
				},
				step: function () {
					$('#date_'+this.id.replace('guestbook_','')).css('color', $(this).css('backgroundColor'));
				}
			});
		}
	});

	$('.releaseswidget, .releaseswidgetfirst').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#AADD77'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.trackpodlist').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#AADD77'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.pagereleases .contentlister').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#669933'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#AADD77'}, {
						duration: 400
					});
				}
			});
		}
	});

	$('.pageradio .sendtoradioplayer').live('click', function(event) {
		if($(this).attr('rel') != '') {
			event.preventDefault();
			$('#radiolist').load('http://'+window.location.hostname+'/'+ajaxadd+window.location.hash.replace('#', '')+'.html #actuallist>*', function(responseText) {
				if(playerradio) {
					playerradio.url = './radioplayer/'+$('#radiolist .radiotrack').text();
					$('#radionowplaying').text($('#radiolist .singlehead').text()+' '+$('#radiolist .singesubhead').text());
				}
			});
			
			playerradio.url = './radioplayer/'+$(this).attr('rel');
			playerradio.play();
		}
	});

	$('.pagepress .contentlister').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#444433'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#444433'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#777766'}, {
						duration: 400
					});
				}
			});
		}
	});
	
	$('.pageradio .contentlister').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: '#997799'}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: '#997799'}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: '#BBAABB'}, {
						duration: 400
					});
				}
			});
		}
	});
	var test = '.pagedates .contentlister, .dateswidget, .dateswidgetfirst';
	var testarr = new Array('#CC6633', '#FFBB99');
	
	$(test).live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop();
			$(this).animate({backgroundColor: testarr[0]}, {
				duration: 200
			});
		} else {
			$(this).stop();
			$(this).animate({backgroundColor: testarr[0]}, {
				duration: 200,
				complete: function() {
					$(this).animate({backgroundColor: testarr[1]}, {
						duration: 400
					});
				}
			});
		}
	});
	
	/*
	$(document).scroll(function(){
		if(($('#teaser').position().top - $(this).scrollTop()) < 3 && $('#teaser').css('position') != 'fixed') {
			$('#teaser').css({position: 'fixed', top: '3px', left: $('#teaser').position().left});
		}
		else if(($(this).scrollTop()) < 108)
			$('#teaser').css({position: 'static'});
	});
	*/

	$('form').live('submit', function(e){
		e.preventDefault();
		$(document).scrollTop(0);
		array = new Object();
		$('#'+e.currentTarget.id+' input, #'+e.currentTarget.id+' textarea').each(function(index, element) {
			array[element.name] = element.value;
		});
		$('#page').load('http://'+window.location.hostname+'/'+ajaxadd+lastHash.replace('#', '')+'.html #page>*', array, function(responseText, textStatus, XMLHttpRequest) {
			afterajax();
		});
	});
	
	$('a.extern').live('click', function(e) {
		e.preventDefault();
		window.open(this.href);
	});
	
	$('html').css({overflowY: 'scroll'});
});
