$(document).ready(function () {

	// Banner click sends the user home
	$('#headerimage').click(function(){
		window.location.hash = "#home";
	});

	$('.collage').click(function(){
		window.location.hash = "#bios";
	});


    /* See http://jquery.malsup.com/cycle/ */
    $('.slideshow').cycle({
        fx: 'fade',
        delay: -2000,
        speedIn: 5000,
        speedOut: 5000,
        timeout: 7000,
        random: true
    });
    /* Hash navigation */
    blankHashFix();
    loadToResultDiv(window.location.hash);
    $(window).hashchange(function () { loadToResultDiv(window.location.hash) });
    /* Collage names */
    $("div.author-name").hover(
        function () {
        	// August 10th, Requested name bars not to show on home page. 
    		if(window.location.hash !== "#home"){
	            $(this).addClass("show");
	            $(this).find("span").addClass("show");
    		}
        },
        function () {
        	// August 10th, Requested name bars not to show on home page. 
    		if(window.location.hash !== "#home"){
	            $(this).removeClass("show");
	            $(this).find("span").removeClass("show");
    		}
        }
    );
});
function blankHashFix() {
    if (window.location.hash === '') {
        window.location.hash = 'home';
    }
}
function loadToResultDiv(contentID) {
    blankHashFix();
    $('#text-content').load('text-content-35.htm ' + contentID);
    if (contentID === '#authors' || window.location.hash === '#home') {
        // Show collage
        $('.bookcover').css('display', 'none');
        $('.slideshow').css('display', 'none');
        $('.collage').css('display', 'block');
    }
    else {
        if (contentID === '#purchase') {
            // Show bookcover
            $('.bookcover').css('display', 'block');
            $('.slideshow').css('display', 'none');
            $('.collage').css('display', 'none');
        } else if(contentID === '#bios') {
	        $('.bookcover').css('display', 'none');
	        $('.slideshow').css('display', 'none');
            $('.collage').css('display', 'none');
	        
        }
        else {
            // Show slideshow 
            $('.bookcover').css('display', 'none');
            $('.slideshow').css('display', 'inline');
            $('.collage').css('display', 'none');
        }
    }
}
