/*  
Originally created by Juxtaprose, (c) copyright 2009
http://juxtaprose.com/
*/

$(document).ready(function() {

/* rotating quotes on home page */
	$('.rotating').cycle({timeout: 3000, speed: 3000}); 

/* scrolling book jacket carousel on home page */	
	$.each($('#scrollzone'), function() {
		$(this).append('<a href="#" id="prev" class="arrow"></a><a href="#" id="next" class="arrow"></a>');
		$('#prev').addClass('arrowoff');
		$('#prev,#next').click(function(e) {
			e.preventDefault();
		});
		$('.scrollable').scrollable({
			size: 5,
			prev: '#prev',
			next: '#next',
			clickable: false,
			disabledClass: 'arrowoff'
		 });
		 $(this).css('visibility','visible');
	});

/* subscribe button and videos overlay-popup */	
	$('body').append('<div class="overlay" id="signup"><div class="owrap"></div></div><div class="overlay" id="video"><div class="owrap"></div></div>');

	$('a[rel="#signup"],a[rel="#video"]').overlay({
		expose: '#575757',
		onBeforeLoad: function() {
			var owrap = this.getContent().find('div.owrap');
			owrap.empty();
		},	
		onLoad: function() {
			var owrap = this.getContent().find('div.owrap');
			$(owrap).append('<iframe src="'+this.getTrigger().attr("href")+'" frameborder="0" scrolling="no" />');
			try { /* intentionally fails on all except IE6 */
				supersleight.limitTo(false);
				supersleight.run();
			} catch (r) {}		
		},
	   finish: {
	    	top: 10,
			left: 'center',
			absolute: false
		} 
	});	

/* book page buy buttons */
	$('a[href="#buy"]').click(function(e) {
		e.preventDefault();		
		$.scrollTo('#buy',1000, {axis: 'y',onAfter: function() {
			if (window.location.href.indexOf('#buy')==-1) {
				window.location.href = window.location.href+'#buy';
			}			
			$('#buy').stop();			
			$('#buy').animate(
				{backgroundColor: '#f6e0d4', 
				borderTopColor: '#c7c7c7', 
				borderRightColor: '#c7c7c7', 
				borderBottomColor: '#c7c7c7', 
				borderLeftColor: '#c7c7c7'				
				}, 500, 'swing', function(){
					$('#buy').animate(
						{backgroundColor: '#fff', 
						borderTopColor: '#fff', 
						borderRightColor: '#fff', 
						borderBottomColor: '#fff', 
						borderLeftColor: '#fff'
						}, 1000, 'swing');
			});
		}});			
	});

	var RNPavplayer = 'scripts/flowplayer-3.1.2.swf';	
/* audio players */
	$.each($('.audio'), function() {
		var lnk = this;
		var h = $(lnk).attr('href');
		var t = $(lnk).text();
		$(lnk).text('');
		$(lnk).after(' '+t);
		$f(lnk, 
			{src: RNPavplayer,
			onFail: function() { /* for the no-Flash case */
				$(lnk).empty();			
				$(lnk).html('<span>play</span>');
				$(lnk).click(function(e) {
					e.preventDefault();
					window.location.href = h;
				});	
			}},
			{clip: {
				url: h,
				autoPlay: false,
				autoBuffer: true				
			},			
			plugins: {
				controls: {
					play: true,
					time: false,
					volume: false,
					mute: false,
					stop: false,
					playlist: false,
					scrubber: false,
					fullscreen: false,
					height: 25,
					backgroundColor: '#ffffff',
					backgroundGradient: [0,0,0],
					fontColor: '#ffffff',      
					buttonColor: '#575757',
					buttonOverColor: '#8a3d27'
				}
			},
			canvas: { 
				backgroundColor: '#ffffff', 
				backgroundGradient: [0,0,0]		
			}}
		); 		
	});	
	
/* video players */
	$.each($('#player'), function() {	
		var h = $(this).attr('href');
		$(this).text('');
		$f(this, RNPavplayer,
			{clip: {
				url: h,
				scaling: 'fit',
				time: '00:00',
				autoPlay: true,
				autoBuffer: true
			},
			plugins: { 
				controls: { 
					playlist: true,
					fullscreen: false, 					
					height: 25,
					backgroundColor: '#575757',
					backgroundGradient: [0,0,0],
					fontColor: '#ffffff',      
					timeColor: '#ffffff',
					buttonColor: '#111111',
					buttonOverColor: '#8a3d27',        		
					bufferColor: '#8a3d27',
					bufferGradient: 0,
					progressColor: '#dddddd'
				} 
			},
			canvas: { 
				backgroundColor: '#dddddd', 
				backgroundGradient: [0,0,0]		
			}}
		);
	});
});

