// default for audioplayer
AudioPlayer.setup("img/player.swf", {  
	width: 390,  
	initialvolume: 100,  
	transparentpagebg: "yes",
	bg: "000000",
	leftbg: "000000",
	rightbg: "000000",
	lefticon: "000000",
	track: "000000",
	border: "000000",
	righticonhover: "ffffff",
	rightbghover: "000000",
	animation: "no",
	text: "ffffff",
	tracker: "393c3f",
	loader: "555555"
});

var loaded_songs = 0;
// play the requested song
function playSong(song) {
	loaded_songs += 1;
	if(loaded_songs > 0) {
		$('#recently-played-songs').fadeIn('slow');
	}
	$('.song').removeClass('playing');
	
	var songUrl = song.attr('href');
	var songSlug = song.attr('rel');
	var songTitle = song.attr('title');

	AudioPlayer.embed("music-player", {  
		soundFile: songUrl,
		artists: "Mono et Mono",
		titles: songTitle,
		autostart: "yes"
	});
	return false;
}

$(function() {
	
	// load appropriate wrapper as per hash tag
	var hash = window.location.hash;
    var href = $('body > header nav li a').each(function(){
		$(this).removeClass('current');
        var href = $(this).attr('href');
		var pageTitle = $(this).attr('title');
		if(hash.length) {
	        if(hash == href){
				if(pageTitle.length && hash != "#home") {
					document.title = pageTitle;			
				}
				$(this).addClass('current');
	        }			
		} else {
			$('.home').addClass('current');
		}

    });

	// website navigation
	// this sets the current class
	$('a[href*=#]').click(function(e) {
		var linkId = $(this).attr('href')+"-link";
		$('body > header nav li a').removeClass('current');
		$(linkId).addClass('current');
		var pageTitle = $(this).attr('title');
		if(pageTitle.length) {
			document.title = pageTitle;			
		}
		$(this).addClass('current');
	});
	
	
	//load song
	$('.song').click(function(e) {
		e.preventDefault();
		var song = $(this);
		playSong(song);
	});
	
	$("#home nav li a, ul.music li").hover(function() {
	    $(this).stop().animate({ marginTop: "-4px" }, 200);
	},function(){
	    $(this).stop().animate({ marginTop: "0px" }, 300);
	});
	
	$("a[href^='http']").click(function() {
	 	window.open($(this).attr('href'));
	 	return false;
	 });
	
	// resize the wrappers and stuff for those of us with 27 inch imacs
	$(window).resize(function(){
		var numberOfWrappers = $('body > section').size();
		$('body > section').css({
			width: $(window).width()
		});
		$('body').css({
			width: ($('body > section').outerWidth()*numberOfWrappers)
		});
	});

	// To initially run the function:
	$(window).resize();
});