function loadScript(location) {
	document.write("<script type=\"text/javascript\" src=\""+location+"\"></script>");
}

loadScript("./resources/jquery.lightbox-0.5.pack.js");
loadScript("./resources/jquery.cookie.js");
loadScript("./resources/audio-player/audio-player.js");
loadScript("./scripts/navigation.js");
loadScript("./scripts/audioplayer.js");
loadScript("./resources/mediaplayer/swfobject.js");
loadScript("./resources/jquery.floatobject.js");
loadScript("./resources/jquery.coda-slider-2.0.js");
loadScript("./resources/jquery.localscroll.min.js");
loadScript("./resources/jquery.innerfade.js");

$(document).ready(function() {
	
	// Hide shoutbox when button is clicked.
	$('#hide').click(function(){
		$(this).parent().slideUp();
		$.cookie("shoutbox",0,{expires: 1});
	});
	
	// Hide shoutbox if button has been clicked before.
	if($.cookie("shoutbox") == 0)
		$('#hide').parent().hide();

	// Search form functions
	$('#search input[type=text]').focus(function(){
		if($(this).val() == 'kernwoord') $(this).val('');
		$(this).css('color','#000');
	});
	
	$('#search input[type=text]').blur(function(){
		if($(this).val() == 'kernwoord') $(this).css('color','#ccc');
	});
	
	$('#search').submit(function(){
		search();
		return false;
	});
	
	
	// Make mail addresses links.
	$("a[href^='mailto']").css({'color':'#fff','border-bottom':'1px #fff dotted','padding-bottom':'1px'});
	$("a[href^='mailto']").hover(
		function(){
			$(this).css({'color':'#fff','border-bottom':'1px #fff solid','padding-bottom':'1px'})
		},
		function(){
			$(this).css({'color':'#fff','border-bottom':'1px #fff dotted','padding-bottom':'1px'})
		}
	);
	
	// Display photo captions on mouseover.
	$(".photo span").css('display','none');
	$(".photo").hover(
		function(){
			$(this).find("span").fadeIn(1500);
		},
		function(){
			$(this).find("span").fadeOut(500);
		}
	);
	
	// Make all lightbox links work with Lightbox.
	$('a.lightbox').lightBox();
	
	
	// Animate keywords
	/*$.getJSON("./scripts/get_info.php?type=keywords",function(data) {
		keywords = data;
		wordAnimation(0,'left');
	},"json");*/
	
	// Animate banner image
	$('#image').innerfade({
		speed: 3000,
		timeout: 15000,
		type: 'random',
		containerheight: '181px'
	});
	
	$('#logo-top').find('small').click(function() {
		// step: 25
		var menuheight = 140;
		if($(this).css("height") != menuheight+"px") {
			$(this).animate({
			    height: menuheight
			  }, 100, null);
		} else {
			$(this).animate({
			    height: '12'
			  }, 100, null);
		}
	});
			
});

function printMailAddress(name) {
 document.write("<a href=\"mailto:"+name+"@");
 document.write("tmuziekfrascati.be\">");
 document.write(name);
 document.write("@");
 document.write("tmuziekfrascati.be</a>");
}

function clearForm(form) {
  $(':input', form).each(function() {
 var type = this.type;
 var tag = this.tagName.toLowerCase(); // normalize case
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = "";
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

function search() {
 var keyword = $('#search input[type=text]').val();
 var google = "http://www.google.com/search?q=site:tmuziekfrascati.be+"+keyword.replace(" ","+");
 window.location.href = google;
}

var keywords;
function wordAnimation(index,direction) {
	if(index == keywords.length) index = 0;
	$('#image').find('span').html(keywords[index]);
	if(direction == 'left') {
		$('#image').find('span').animate({
			right: '+=300',
			opacity: 0
		}, 15000, function() {
			wordAnimation(++index,'right');
		});
	} else if(direction == 'right') {
		$('#image').find('span').animate({
			right: '-=300',
			opacity: 85
		}, 15000, function() {
			setTimeout("wordAnimation("+index+",'left')",3000);
		});
	}
}
