/**
* JQuery javascript to perform on page load
*/
jQuery(document).ready(function () {


	// Add class to <body> to indicate JS is enabled
	jQuery('body').addClass('js-enabled');


	// Inserts a clearing div to the bottom of #pageContent
	// Required to give #pageContent a height when all child elements are floated
	jQuery('#pageContent').append('<div class="clear"></div>');


	// Inject a link under the My Account login form
  jQuery('#borrowerServices').parent().append('<p class="join-now"><a rel="external" href="http://www.gloucestershire.gov.uk/libraries/index.cfm?articleid=12901">Check hire charges</a></p>');
	jQuery('#borrowerServices').parent().append('<p class="join-now">Not a member? <a rel="external" href="http://www.gloucestershire.gov.uk/libraries/jointhelibrary">Join now</a></p>');

  jQuery('#availability ul.availabilityActions').after($('<div>').attr('id', 'check-charges').html('<a rel="external" href="http://www.gloucestershire.gov.uk/libraries/index.cfm?articleid=12901">Check hire charges</a>'));

  jQuery('a[rel="external"]').attr('target','_blank');

	// Load Juice extensions
/*
  juice.loadJs("/assets/-/scripts/juice/extensions/Carousel3D.js",prismTenancy());

  juice.loadJs("/assets/-/scripts/juice/extensions/JuiceSimpleInsert.js",prismTenancy());
  juice.loadJs("/assets/-/scripts/juice/panels/juiceBasicPanel.js",prismTenancy());
  juice.loadJs("/assets/-/scripts/juice/panels/juiceListPanel.js",prismTenancy());
*/

	juice.loadJs("/assets/-/scripts/juice/metadefs/talis_prism_metadef.js",prismTenancy())
	juice.onAllLoaded(runExtensions);
});










/**
* Retrieve the correct path for JS files
*/
function prismTenancy(){

	var prism = "";
	var urlParts = window.location.href.split('/');

	if(urlParts[2] == "prism.talis.com"){

		prism = urlParts[3];

		if(prism == 'demo') {
			prism += '/' + urlParts[4]; }
	}

	return prism;
}



/**
* Builds the book carousel on the homepage
*/
function buildCarousel() {
	var opts = {
    height: 130,
    width: 550,
    loadingImage: 'assets/-/images/gloucestershire/ajax-loader.gif',
    customInfoElement: 'carousel-caption',
    items: [
	{
		title: 'Full House',
		author: 'Maeve Binchy',
		href: 'items/935268',
		src: 'items/935268/image-medium'
	},
{
	title: 'The Cleverness Of Ladies',
	author: 'Alexander McCall Smith',
	href: 'items/935266',
	src: 'items/935266/image-medium'
},
{
	title: 'The Little One',
	author: 'Lynda La Plante',
	href: 'items/935267',
	src: 'items/935267/image-medium'
},
{
	title: 'Amy\'s Diary',
	author: 'Maureen Lee',
	href: 'items/935269',
	src: 'items/935269/image-medium'
},
{
	title: 'Beyond The Bounty',
	author: 'Tony Parsons',
	href: 'items/935263',
	src: 'items/935263/image-medium'
},
{
	title: 'Quantum Of Tweed',
	author: 'Conn Iggulden',
	href: 'items/935264',
	src: 'items/935264/image-medium'
},
{
	title: 'Get The Life You Really Want',
	author: 'James Caan',
	href: 'items/935265',
	src: 'items/935265/image-medium'
},
{
	title: 'Magic Of The Angels',
	author: 'Jacqueline Rayner',
	href: 'items/935270',
	src: 'items/935270/image-medium'
}
    	]
	}
	new Carousel (juice, null, 'carousel', opts);
}


/**
* Run Juice extensions
*/
function runExtensions(){
	talis_prism_metadef();

	switch(jQuery("body").attr("id")){
		case "index":
      frontPage();
      break;
	}
}


/**
* Front Page functionality
*/
function frontPage(){
	buildCarousel();
}

