$(document).ready(function()
{
	var url = document.location.toString();

	var urlbits = url.split('#');

	$('#header').bind
	(
		'click',
		function(e)
		{
			location.href = "http://www.amazon.com/gp/product/1439116830?ie=UTF8&tag=wefeelfine-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1439116830";
		}
	);

	$('#more-info ul').hide();

	$('#more-info').siblings('ul').hide();

	$('#more-info').mouseenter
	(
		function(e)
		{
			$('ul',this).fadeIn();
		}
	);

	$('#more-info').mouseleave
	(
		function(e)
		{
			$('ul',this).fadeOut();
		}
	);

	$('#back-cover-link').mouseenter
	(
		function(e)
		{
			$('#back-cover-reveal').width(820).animate
			(
				{
					opacity: 1
				}
			);
			$('#back-cover-backing').width(940).animate
			(
				{
					opacity: .9
				}
			);
		}
	);

	$('#back-cover-link').click
	(
		function(e)
		{
			e.preventDefault();
		}
	);

	$('body').bind
	(
		'click',
		function(e)
		{
			if ($('#back-cover-reveal').css('opacity') == 1)
			{
				$('#back-cover-backing').animate
				(
					{
						opacity: 0
					},
					'normal',
					'linear',
					function()
					{
						$('#back-cover-backing').width(0);
					}
				);

				$('#back-cover-reveal').animate
				(
					{
						opacity: 0
					},
					'normal',
					'linear',
					function()
					{
						$('#back-cover-reveal').width(0);
					}
				);
			}
		}
	);

	$('*:not(#page *, #back-cover-reveal, #back-cover-backing, .container_12, #page-menu)').bind
	(
		'mouseenter',
		function(e)
		{
			if ($('#back-cover-reveal').css('opacity') == 1)
			{
				$('#back-cover-backing').animate
				(
					{
						opacity: 0
					},
					'normal',
					'linear',
					function()
					{
						$('#back-cover-backing').width(0);
					}
				);

				$('#back-cover-reveal').animate
				(
					{
						opacity: 0
					},
					'normal',
					'linear',
					function()
					{
						$('#back-cover-reveal').width(0);
					}
				);
			}
		}
	);

	if ( ! $.iPhone.present && urlbits.length == 1)
	{
		$("img").lazyload
		(
			{
				placeholder : "assets/images/blank.gif",
				effect : "fadeIn"
			}
		);
	}

	$('#page-menu a').lightBox({fixedNavigation:false});

	$('#page-menu a').bind
	(
		'mouseup',
		function(e)
		{
			href = $(this).attr('href');

			hrefbits = href.split('.');

			fragment = '#';

			if (hrefbits.length > 1)
			{
				fragment += hrefbits[0];

				window.location.replace(urlbits[0]+fragment);
			}
		}
	);

	if (urlbits.length > 1)
	{

		$('#page-menu a[href="'+urlbits[1]+'.jpg"]').click();
	}

	$.getScript
	(
		"http://www.wefeelfine.org/book/assets/js/jquery.ga.js",
		function()
		{
			$.ga.load('UA-286275-4');

			$('.amazon-link, .indiebound-link, .barnesnoble-link').live
			(
				'click',
				function(e)
				{
					$.ga.trackEvent('book', 'more info', 'buy from '+$(this).attr('class')+' clicked');
				}
			);

		}
	);

});