jQuery(document).ready(function() {
    

// Transform the search box into a dynamic component
$( '#searchDept select' ).selectbox();



// Register change listener on the currency select
$('#currencyForm').attr("action", window.location.href);

$('#currencypicker_currencyname').bind('change', function(){
   $('#currencyForm').submit();
});


// Deal with truncated texts

$(".booktitle").ThreeDots({ max_rows:3, alt_text_e: true, alt_text_t: true });
$(".author").ThreeDots({ max_rows:1, alt_text_e: true, alt_text_t: true });


// Generate tabs
$( ".productTabs" ).tabs({select: function(event, ui){


$('#bList' + ui.panel.id).jcarousel({
itemVisibleInCallback: {
            onBeforeAnimation: carouselItemVisible
        }
});




}});



// Preload any images we require for the 
// Visible carousels.
 $(".jcarousel-skin-gb.first ul").each(function(){

loadCarouselImages($(this).find("li:lt(3)"));

});    


 

// Carousel the first one in each section.
$(".jcarousel-skin-gb.first").jcarousel({
itemVisibleInCallback: {
            onBeforeAnimation: carouselItemVisible
        }
});




// Show the product tabs
$(".productTabs").css("visibility", "visible");


});




// Load all images for a passed selector of li's
function loadCarouselImages(jqueryLISet){


    jqueryLISet.each(function(i){
   var image = $(this).find(".thumb:first");
   
if (image.attr("src") == "/images/noimagefound.jpg"){

       var splitAlt = image.attr("alt").split("-");

       image.attr("src", "/ProductImage?isbn=" + splitAlt[1] +   "&width=94&sourceCountry=" + splitAlt[0]);
}

       image.attr("alt", image.attr("title"));


});


}


function carouselItemVisible(carousel, item, idx, state){
    loadCarouselImages($(item));


}



