
var setTabs = function ( initStyle )
{
	$( '#all-books ul' ).idTabs( { start: initStyle }, function ( id, list, set )
		{ 
			var cur;
			
			for ( i in list )
			{
				if ( list[ i ] == id )
				{
					cur = parseInt( i );
					
					break;
				}
			}
			
			switchStyle( cur );
			
			return true; 
  		}
	); 
};

var switchStyle = function ( index )
{
	switch( index )
	{ 
		case 0: // eg
		
			$( 'body' ).removeClass( 'bm2 cp2 bmbm cp' ).addClass( 'eg' );
			
			$.cookie( 'ps_selected_book', '0', { path: '/', expires: 7 } );
			
			break;
			
		case 1:  // bm2
			
			$( 'body' ).removeClass( 'eg cp2 bmbm cp' ).addClass( 'bm2' );
			
			$.cookie( 'ps_selected_book', '1', { path: '/', expires: 7 } );
			
			break;

		case 2: // cp2
			
			$( 'body' ).removeClass( 'eg bm2 bmbm cp' ).addClass( 'cp2' );
			
            $.cookie( 'ps_selected_book', '2', { path: '/', expires: 7 } );
           
			break; 
			
		case 3: // bmbm
		
			$( 'body' ).removeClass( 'eg bm2 cp2 cp' ).addClass( 'bmbm' ); 
			
			$.cookie( 'ps_selected_book', '3', { path: '/', expires: 7 } );
			
			break;
		
		case 4: // cp
		
			$( 'body' ).removeClass( 'eg bm2 cp2 bmbm' ).addClass( 'cp' );
			
			$.cookie( 'ps_selected_book', '4', { path: '/', expires: 7 } );
			
			break; 	
	}
	
	return;
};

var setAudio = function ()
{
	AudioPlayer.setup("http://schiff.brickyardpartners.com/scripts/player.swf", 
		{  
         width: '100%',  
         initialvolume: 100,  
         transparentpagebg: "yes",
		 animation: 'no',
		 bg: 'bcb6ab',
		 leftbg: 'bcb6ab',
		 rightbg: 'bcb6ab',
		 lefticon: 'ffffff',
		 righticon: 'ffffff',
		 rightbghover: '6f6551',
		 tracker: 'dfdfdf',
		 loader: '6f6551'
     	}
	);
	
	$( 'p.audio-player' ).each( function ()
		{
			var id = $( this ).attr( 'id' );
			var src = $( this ).find( 'a' ).attr( 'href' );
			
			AudioPlayer.embed( id, { soundFile: src } );
		}
	);		 
};

$( document ).ready( function ()
	{
		var initStyle = parseInt( $.cookie( 'ps_selected_book' ) ) || 0;
		
		switchStyle( initStyle );
		setTabs( initStyle );	
		setAudio();
	}
);

