/**
 * @package Spark Bibles
 * @author {@link mailto:ss@toolboxstudios.com Steve Simons, Toolbox Studios, Inc.}
 * @license http://toolboxstudios.com Contact about usage
 * @revision $Revision: $
 * @copyright Copyright 2010
**/



// Only for Home Page
if ( jQuery( 'body').hasClass( 'home')) {
	var hidePanel = 'div.panel.nrsv';
	var showPanel = 'div.panel.story';
	if ( document.location.href.match( /nrsv/i)) {
		hidePanel = 'div.panel.story';
		showPanel = 'div.panel.nrsv';
	}

	jQuery( '#mainContent')
		.find( hidePanel)
			.hide()
			.end()
		.addClass( 'js');
	
	jQuery( '<a />')
		.attr( 'href', '#View%20NRSV%20Bible')
		.attr( 'title', 'View NRSV Bible')
		.text( 'View NRSV Bible')
		.addClass( 'nrsv')
		.click( function(e) {
			jQuery( 'div.panel.story')
				.fadeOut( 'fast', function() {
					jQuery( 'div.panel.nrsv')
						.fadeIn( 'fast');
				});
			hidePanel = 'div.panel.story';
			showPanel = 'div.panel.nrsv';
			if ( pageTracker)
				pageTracker._trackPageview( '/click-view/Spark-Bible-NRSV')
		})
		.appendTo( 'div.panel.story div.left')
		.wrap( '<div class="toggleButtons" />');
	
	jQuery( '<a />')
		.attr( 'href', '#View%20Story%20Bible')
		.attr( 'title', 'View Story Bible')
		.text( 'View Story Bible ')
		.addClass( 'story')
		.click( function(e) {
			jQuery( 'div.panel.nrsv')
				.fadeOut( 'fast', function() {
					jQuery( 'div.panel.story')
						.fadeIn( 'fast');
				});
			hidePanel = 'div.panel.nrsv';
			showPanel = 'div.panel.story';
			if ( pageTracker)
				pageTracker._trackPageview( '/click-view/Spark-Story-Bible')
		})
		.appendTo( 'div.panel.nrsv div.left')
		.wrap( '<div class="toggleButtons" />');
	
	
	jQuery( '#mainContent li.action > a')
		.hover( 
			function(e) {
				jQuery( this).parent().addClass( 'hover');
			},
			function(e) {
				jQuery( this).parent().removeClass( 'hover');
			}
		);

}

if ( swfobject.hasFlashPlayerVersion( '9.0.18')) {
	jQuery( 'li.peek')
		.slideDown( 'slow')
		.find( 'a')
			.add( 'img.peekHotspot')
			.show()
			.addClass( 'enabled')
			.css( 'cursor', 'hand')
			.css( 'cursor', 'pointer')
			.click( function(e) {
				jQuery( '<div>')
					.attr( 'id', 'flashOverlay')
					.click( function(e) {
						closeFlipBook();
					})
					.hide()
					.appendTo( 'body')
					.show( 'normal', function() {
						jQuery( '<p>')
							.attr( 'id', 'bookInstructions')
							.text( 'Click or drag book corners to view pages')
							.css( 'left', ( jQuery( '#flashOverlay').width() - 363) / 2)
							.appendTo( 'body');
						
						jQuery( '<div id="flashBox">')
							.append( '<div id="flash" />')
							.css( 'left', ( jQuery( '#flashOverlay').width() - 1004) / 2)
							.appendTo( 'body')
						var swf = showPanel.match( /story/) ? 'spark_story_bible/loader.swf' : 'spark_bible_sam/loader.swf';
						var flashvars = false;
						var params = {};
						params.wmode = 'transparent';
						var attributes = {};
						swfobject.embedSWF( swf, 'flash', 1007, 924, '9.0.18', false, flashvars, params, attributes);
						
					});
				if ( pageTracker)
					pageTracker._trackPageview( showPanel.match( /story/) ? '/flash/Spark-Story-Bible' : '/flash/Spark-Bible-NRSV')
			})
			.hover(
				function() {
					jQuery( showPanel + ' div.peekBalloon')
						.show(); /* IE stupidity prevents softly fading this */
				},
				function() {
					jQuery( showPanel + ' div.peekBalloon')
						.hide(); /* IE stupidity prevents softly fading this */
				}
			)
			.end()
		.closest( 'body')
			.addClass( 'flash')
			.end();
}

function closeFlipBook() {
	if ( document.getElementById( 'flash'))
		swfobject.removeSWF( 'flash');
	
	jQuery( '#flashBox')
		.remove();
		
	jQuery( '#flashOverlay, #bookInstructions')
		.fadeOut( 'normal', function() {
			jQuery( this)
				.remove();
		});
}

function shareThis(book) {
	alert("Share this book: " + book) ; 
}



// Only for Testimonial Page
jQuery( '#testimonialOther h2').each( function( index) {
	
	var jH2 = jQuery( this);
	var jQuote = jH2.next( 'blockquote').first();
	if ( jQuote.length > 0) {
		jQuote
			.addClass( 'jQuote')
			.hide();
		jQuery( '<a />')
			.data( 'quote', jQuote)
			.attr( 'href', '#Read%20More')
			.html( '&gt;&gt;&gt; Read More')
			.addClass( 'readMore')
			.click( function( e) {
				var jLink = jQuery( this);
				if ( jLink.text().match( /More/))
					jLink
						.html( jLink.html().replace( /More/, 'Less'))
						.data( 'quote')
							.slideDown( 'slow');
				else
					jLink
						.html( jLink.html().replace( /Less/, 'More'))
						.data( 'quote')
							.slideUp( 'slow');
			})
			.appendTo( jH2);
	}
		
	
});


// Only for Testimonails Page - Videos
var jVideosArea = jQuery( '#testimonialVideos');
if ( jVideosArea.length > 0) {
	
	var jUl = jVideosArea.find( 'ul');
	var jVideoLIs = jUl.find( 'li');
	
	jUl
		.width( jVideoLIs.length * 320)
		.end();
	
	if ( jVideoLIs.length > 1) {
		var showingVideo = 1;
		var jRA = jQuery( '<a />')
			.attr( 'id', 'videoRightArrow')
			.addClass( 'videoArrow')
			.addClass( 'right')
			.html( '&gt;')
			.click( function(e) {
				if ( !jUl.hasClass( 'moving')) {
					jUl
						.addClass( 'moving')
						.animate( 
							{ 'margin-left': '-=320px' },
							'slow',
							'swing',
							function() {
								showingVideo++;
								if ( showingVideo >= jVideoLIs.length)
									jRA.hide();
								jLA.show();
								jUl.removeClass( 'moving');
							}
						);
				}
			})
			.appendTo( jVideosArea.find( 'div.inset'));
		var jLA = jQuery( '<a />')
			.attr( 'id', 'videoLeftArrow')
			.addClass( 'videoArrow')
			.addClass( 'left')
			.html( '&lt;')
			.click( function(e) {
				if ( !jUl.hasClass( 'moving')) {
					jUl
						.addClass( 'moving')
						.animate( 
							{ 'margin-left': '+=320px' },
							'slow',
							'swing',
							function() {
								showingVideo--;
								if ( showingVideo == 1)
									jLA.hide();
								jRA.show();
								jUl.removeClass( 'moving');
							}
						);
				}
			})
			.appendTo( jVideosArea.find( 'div.inset'));
	}
	
	jVideosArea
		.show();
	

}

