function startMusic(force) {
	var music;
	if((music = $.cookie('music')) || force) {
		if(music == 'off') {
			return;
		}
		if(music == 'on' || force) {
			if (jQuery('#jpId').length) {
				jQuery('#jpId').jPlayer("play");
			}
			jQuery('#togglePlayer').text('On');
		}
	}
}

jQuery(document).ready(function() {
	jQuery('#togglePlayer').text('Off');

	// mp3 player control handlers
	jQuery('#togglePlayer').click(function() {
		
		// Turn off
		if($(this).text() == 'On') {
			jQuery(this).text('Off');
			jQuery('#jpId').jPlayer("pause");
			
			$.cookie('music', 'off', {
				expires: new Date("1/1/2300"),
				path: '/'
			});
		}
		// Turn on
		else {
			jQuery(this).text('On');
			jQuery('#jpId').jPlayer("play");
			
			$.cookie('music', 'on', {
				expires: new Date("1/1/2300"),
				path: '/'
			});
		}
	
		return false;	

	});

	jQuery("#jpId").jPlayer({
		preload: 'auto',
		ready: function() {
			jQuery(this).jPlayer("setMedia", {
				mp3: "/assets/music/music.mp3" // Defines the mp3 url
			});
			//startMusic();
		},
		ended: function() { // The jQuery.jPlayer.event.ended event
			jQuery(this).jPlayer("play"); // Repeat the media
		},
		supplied: "mp3",
		swfPath: "/assets/js/"
	});

	//setTimeout("startMusic()", 2000);
});
