var swf_width = 250;

$(document).ready(function() {
	// do stuff when DOM is ready

	$('#search').focus().select();

	AudioPlayer.setup((window.location.host == 'localhost' ? '/bible.rodandstaffbooks.com' : '') + "/swf/player.swf", {
		width: swf_width,
		menu: 'false',
		transparentpagebg: 'yes'
	}); 
	
	$(".audio a").each(function(){
		var mp3 = $(this).attr('href');
		var title = $(this).attr('title');
		$(this).parent().attr('target',mp3);

		AudioPlayer.embed(this.id, {
			soundFile: mp3,
			titles: title,
			leftbg: 'FFFFFF'
		});
		
	});
		
	$(".audio").each(function(){
		$(this).append(" <span class='a-instr noprint'><span class='noscreen'>[</span>Listen to chapter<span class='noscreen'>]</span>" +
		" <span class='noscreen'>[</span><a href='" + $(this).attr('target') + "'>Download mp3</a><span class='noscreen'>]</span></span>");
	});

	$(".hidden .swf").mouseup(function(){
		$(".hidden").removeClass('active'); // set everything inactive
		$(this).parent().parent().addClass('active');
	});
	
	$(".chapter.link.hidden").mouseover(function(){
		$(this).addClass('hover');
	}).mouseout(function(){
		$(this).removeClass('hover');
	});
	
	$(".kjv_words .show").click(function(){
		$(this).siblings().filter('.kjv_word').removeClass('hidden');
		$(this).addClass('hidden');
		$(".kjv_words .hide").removeClass('hidden');
		return false;
	});
	
	$(".kjv_words .hide").click(function(){
		$(this).siblings().filter('.kjv_word').addClass('hidden');
		$(this).addClass('hidden');
		$(".kjv_words .show").removeClass('hidden');
		return false;
	});

	$(".verses").mouseover(function(e){
		target = $(e.target);
		if(target.hasClass("w")) {
			target.addClass("hover");
		}
		if(target.parent().hasClass("w")) {
			target.parent().addClass("hover");
		}
	}).mouseout(function(e){
		target = $(e.target);
		if(target.hasClass("w")) {
			target.removeClass("hover");
		}
		if(target.parent().hasClass("w")) {
			target.parent().removeClass("hover");
		}
	}).click(function(e){
		target = $(e.target);
		var lemma = null;
		if(target.hasClass("w")) {
			lemma = target.attr('lemma');
		}
		if(target.parent().hasClass("w")) {
			lemma = target.parent().attr('lemma');
		}
		if (lemma) {
			window.location = (window.location.host == 'localhost' ? '/bible.rodandstaffbooks.com' : '') + '/search/' + lemma;
		}
	});
	
	// CUSTOMIZE options on help page
	
	$(".customize.css_results_block").click(function(){
		$.cookie('Results_block',this.value,{expires:365});
		if (this.value) {
			$(".verses").addClass('block_p');
		} else {
			$(".verses").removeClass('block_p');
		}
	});
	
	$(".customize.results_show").click(function(){
		$.cookie('Results_show',this.value,{expires:365});
	});
	
});
