$(document).ready(function(){
	
	$.fn.search = function() 
	{
		return this.focus(function() 
		{
			if( this.value == this.defaultValue ) 
			{
				this.value = "";
			}
		}).blur(function() 
		{
			if( !this.value.length ) 
			{
				this.value = this.defaultValue;
			}
		});
	};
	$(".search input[name=s]").search();
	$(".feature input[name=emma_member_email]").search();
	
	$('.bigger').fontResize({
		defaultLabels :'<a href="" class="increaseFont fontresize">Bigger</a> | <a href="" class="normalizeFont fontresize">Normal</a> | <a href="" class="decreaseFont fontresize">Smaller</a>'
	});
	
	
	$("#home-recommended").jCarouselLite({
		btnNext: '.recommend .next',
		btnPrev: '.recommend .prev',
		circular: true,
		visible: 6
	});
	$("#book-detail-consider").jCarouselLite({
		btnNext: '.recommend .next',
		btnPrev: '.recommend .prev',
		circular: true,
		visible: 6
	});
	
	$('#flip').jcoverflip({
		beforeCss: function( el, container, offset ){
			if (offset == 0)
			{
				return [
					$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 285 - 150*offset + 20*offset )+'px', bottom: '20px' }, { } ),
					$.jcoverflip.animationElement( el.find( 'img' ), { width: '146px', height: '216px' }, {} )
				];
			}
			if (offset == 1)
			{
				return [
					$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 285 - 150*offset + 20*offset )+'px', bottom: '40px' }, { } ),
					$.jcoverflip.animationElement( el.find( 'img' ), { width: '112px', height: '166px' }, {} )
				];
			}
			return [
				$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 270 - 150*offset + 20*offset )+'px', bottom: '20px' }, { } ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: '112px', height: '166px' }, {} )
			];
		},
		afterCss: function( el, container, offset ){
			if (offset == 0)
			{
				return [
					$.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 115 + 150*offset )+'px', bottom: '20px' }, { } ),
					$.jcoverflip.animationElement( el.find( 'img' ), { width: '146px', height: '216px' }, {} )
				];
			}
			if (offset == 1)
			{
				return [
					$.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 127 + 150*offset )+'px', bottom: '40px' }, { } ),
					$.jcoverflip.animationElement( el.find( 'img' ), { width: '112px', height: '166px' }, {} )
				];
			}
			
			return [
				$.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 120 + 150*offset )+'px', bottom: '20px' }, { } ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: Math.max(10,146-20*offset*offset) + 'px' }, {} )
			];
		},
		currentCss: function( el, container ){
			return [
				$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 110 )+'px', bottom: 0 }, { } ),
				$.jcoverflip.animationElement( el.find( 'img' ), { width: '202px', height:'300px' }, { } )
			];
		},
		current:2
	});
	
	$('.test-next').click(function(){
		var current = $("#flip").jcoverflip('current');
		var total = $("#flip").jcoverflip('length');
		if (current < (total - 3))
		{
			$("#flip").jcoverflip('next','1',false);
		}
	});
	$('.test-prev').click(function(){
		var current = $("#flip").jcoverflip('current');
		if (current > 2)
		{
			$("#flip").jcoverflip('previous','1',false);
		}
	});

	$('.hide-comments').click(function(){
		$('.hide-comments').hide();
		$('.show-comments').show();
		$("#comment-form").hide('slow');
		return false;
	});
	
	$('.show-comments').click(function(){
		$('.show-comments').hide();
		$('.hide-comments').show();
		$("#comment-form").show('slow');
		return false;
	});

});
