playlist = "div#playlist"; 
tracks_container = "div#tracks";
play_button = "div#play";

jQuery( function($) {
	$("div.menu ul").tabs("div.page", { effect: "fade" }).history();

	$(playlist).scrollable({ 
		vertical: true,  
		size: 3
	});
	
	$(play_button).click(function() {
		Mp3Player.playButton();
	});
	
	$(playlist + " a").click(function() {
		Mp3Player.playList($(this));
	});
	
	$.preloadCssImages();
	
	FB.init("6dd7e9028c6c3657b1e12460ad17f350");
});

jQuery(window).load( function($) {
	$f("player", "/wp-content/themes/rvsq/swf/flowplayer-3.1.5.swf", {
		clip: { autoPlay: false },
		
		plugins: {
			controls: null,
			audio: { url: "/wp-content/themes/rvsq/swf/flowplayer.audio-3.1.2.swf" }
		}
	}).playlist(tracks_container, {loop: true});
	
	Mp3Player = {
		player: $f("player"),
		button: jQuery(play_button),
		playing: false,
		
		playButton: function() {
			if (this.playing) {
				this.pause();
				this.player.pause();
			} else {
				this.play();
				this.player.play();
			}
		},
		
		playList: function(a) {
			if (a.attr("href") != this.player.getPlaylist()[0].url || !this.playing) {
				this.play();
			} else {
				this.pause();
			}
		},
		
		play: function() {
			this.playing = true;
			this.button.addClass("pause");
			this.track = jQuery("a.playing").attr("href");
		},
		
		pause: function() {
			this.playing = false;
			this.button.removeClass("pause");
		}
		
	}
});
