var ajaxServiceUrl = "/wcpa/servlet/org.oclc.lac.ui.ajax.ServiceServlet";        
        
jQuery(document).ready(makeBibPageLoadComplete());	// located in bib.jsp

function bibPageLoadComplete(abstractLength, summary, summaryTruncateLength, oclcNum, isbn, displaySyndeticsData, enableSyndetics, platformPage, localPage, performanceMetrics) {

	// setup show more/ less sections
    jQuery('#summary').showMoreLessDiv({
        expandedText:			'Read less',
        contractedText:			'Read more...',
        expandedControlStyle:	'',
        contractedControlStyle:	'',
        expandedContentStyle:	'',
        contractedContentStyle:	''
    });
        
    if (performanceMetrics)
    	jQuery('#browserLoadTimes table').append(jQuery('<tr><td>Bib section</td><td>' + ((new Date()).getTime() - bibSectionBeginTime) + '</td></tr>'));

	if (localPage && displaySyndeticsData && enableSyndetics) {
		getSyndetics(isbn, oclcNum);
	}

	    // fill in the ratings
    if (platformPage) {	
	jQuery.get(ajaxServiceUrl, {serviceCommand: 'ratingStars', itemId: oclcNum}, function(data) {
		var ratingInfo = YAHOO.lang.JSON.parse(data);
		var ratingSpan = jQuery("p.rating span");
		var reviewLink = jQuery("p.rating a");

		// # stars
		// temp till half star graphics are available
		var numberStars = '0';
		if ((ratingInfo.averageRating >= 0) && (ratingInfo.averageRating < .5)) numberStars = "0";
		else if ((ratingInfo.averageRating >= .5) && (ratingInfo.averageRating < 1)) numberStars = "1";
		else if ((ratingInfo.averageRating >= 1) && (ratingInfo.averageRating < 1.5)) numberStars = "1";
		else if ((ratingInfo.averageRating >= 1.5) && (ratingInfo.averageRating < 2)) numberStars = "2";
		else if ((ratingInfo.averageRating >= 2) && (ratingInfo.averageRating < 2.5)) numberStars = "2";
		else if ((ratingInfo.averageRating >= 2.5) && (ratingInfo.averageRating < 3)) numberStars = "3";
		else if ((ratingInfo.averageRating >= 3) && (ratingInfo.averageRating < 3.5)) numberStars = "3";
		else if ((ratingInfo.averageRating >= 3.5) && (ratingInfo.averageRating < 4)) numberStars = "4";
		else if ((ratingInfo.averageRating >= 4) && (ratingInfo.averageRating < 4.5)) numberStars = "4";
		else if (ratingInfo.averageRating >= 4.5) numberStars = "5";
		ratingSpan.addClass('star' + numberStars);
		// # ratings
		ratingSpan.html(ratingInfo.numRatings == 0 ? "(not yet rated)" : "based on " + ratingInfo.numRatings + " rating(s)" );
		// # reviews
		var reviewText = "";
		switch (ratingInfo.numWithReviews) {
			case 0:
				reviewText = ratingInfo.numWithReviews + " with reviews - Be the first.";
				break;
			case 1:
				reviewText = ratingInfo.numWithReviews + " with a review";
				break;
			default:
				reviewText = ratingInfo.numWithReviews + " with reviews";
				break;
		}
		reviewLink.html(reviewText);
	});
    }
	// todo: move out of scriptcalls.jsp
	//dropdowncontent.init("item-preview", "right-top", 100, "click")

}

	
function getSyndetics(isbn, oclcNum) {
	if ((isbn != null) && (isbn != ""))
	{
	//Summary
	jQuery.get(ajaxServiceUrl, {serviceCommand: 'getSyndetics', type:'summary',
		isbn:encodeURIComponent(isbn),
		oclcNum:oclcNum},
	    function(data) {
			if (data != "") {
				jQuery('#summary').html(data);
                
                jQuery('.showMoreLessReadmore').showMoreLessDiv({
                    expandedText:			'Read less',
                    contractedText:			'Read more...',
                    expandedControlStyle:	'expanded-control',
                    contractedControlStyle:	'contracted-control',
                    expandedContentStyle:	'expanded-content',
                    contractedContentStyle:	'contracted-content'
                });
			}
	});
	//Excerpt
	jQuery.get(ajaxServiceUrl, {serviceCommand: 'getSyndetics', type:'excerpt',
		isbn:encodeURIComponent(isbn),
		oclcNum:oclcNum},
	    function(data) {
			if (data != "") {
				jQuery('#syndeticsexcerpt').css('display', 'block');
				jQuery('#syndeticsexcerpt').html(data);
			}
	});
	}
}

jQuery.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
};

function log(msg) {
	if (window.console && window.console.log) {
		window.console.log('[OWC-BIB.JSP]- ' + msg);
	}
	
};

