function createBeats(checkCookie) {

	if(checkCookie) {

		var cookie = new Cookie('audio',{duration: 1});
		if(!cookie.read('played')) {
			cookie.write('played');
		} else {
			return false;
		}
	}

	var swf = new Swiff('/swf/wimpy_button.swf', {
		id: 'x-audio',
		width: 18,
		height: 18,
		allowscriptaccess: 'always',
		vars: {
			theFile: '/media/song.mp3',
			playingColor: 'FFFFFF',
			buttonStyle: 'square',
			grinderColor: 'FFFFFF',
			theBkgdColor: 'FFFFFF',
			loop: true,
			autoplay: 'yes'
		}
	});
	$('flash_thing').grab(swf);


	return true;
}

window.addEvent('domready', function() {

	//neat menu effecthings
	$('fx').getElements('li').getElement('div').set('morph', {duration: 400, transition: Fx.Transitions.Bounce.easeOut});
	$('fx').getElements('li').getElement('a').set('morph', {duration: 500});
	$('fx').getElements('li').addEvents({
		'mouseenter': function() {
		  if(!$(this.className)) {
			this.getElement('div').morph({height:72});
			this.getElement('a').morph({color:'#666666'});
		  }
		},
		'mouseleave': function() {
		  //console.log($(this.className));
		  if(!$(this.className)) {
			this.getElement('div').morph({height:0});
			this.getElement('a').morph({color:'#ffffff'});
		  }
		}
	});


	function beatsOff() {
		$('btnAudio').getElement('span').set('html', 'ON');
		$('barAudio').set('src', '/images/bar_flat.gif');
		
		
		if($('x-audio')) {
			$('flash_thing').removeChild($('x-audio'));
		}
	}

	function beatsOn() {
		$('btnAudio').getElement('span').set('html', 'OFF');
		$('barAudio').set('src', '/images/bar.gif');
		createBeats(false);
	}

	//play music
	if(!createBeats(true)) {
		beatsOff();
	}


	$('btnAudio').addEvent('click', function() {
		if(this.getElement('span').get('html') == 'OFF') {
			beatsOff();
		} else {
			beatsOn();
		}
	});


});

