// api_json_reviews_widget.js

if (!LibraryThing)
	{
	var LibraryThing = {};
	}

if (!LibraryThing.LTFLreviewsWidget)
	{
	LibraryThing.LTFLreviewsWidget = {};
	}

if (!LibraryThing.LTFLreviewsWidget.settings)
	{
	LibraryThing.LTFLreviewsWidget.settings = {};
	}

	
/// GLOBALS

LibraryThing.LTFLreviewsWidget.dochead = document.getElementsByTagName('head')[0];

/// FUNCTIONS

// Make a title and author link
LibraryThing.LTFLreviewsWidget.makeTitleandauthorlink = function(book)
{
var titleandauthorlink = document.createElement("div");
titleandauthorlink.setAttribute('class','LTFL_titleandauthor');

if(book.title == '')
	{
	book.title = 'No title';
	}
	
if (book.title.length > 100)
	{
	book.title = book.title.replace(/^(.{100,125}[a-z] )(.*)/, "$1 ...");
	}

if(book.opac_link)
	{
	var titlelink = document.createElement("a");
	titlelink.setAttribute('class','LTFL_title');

	if( LibraryThing.LTFLreviewsWidget.settings.newwindow )
	{
		titlelink.setAttribute('target', '_blank');
	}
	if( LibraryThing.LTFLreviewsWidget.settings.server )
	{
		href = LibraryThing.LTFLreviewsWidget.settings.server + book.opac_link;
	}
	else 
	{
		href = book.opac_link;
	}
	titlelink.setAttribute('href', href);
	titlelink.innerHTML = book.title;
	titleandauthorlink.appendChild(titlelink);
	}
return titleandauthorlink;
}

LibraryThing.LTFLreviewsWidget.loadStylesheet = function(url)
{
var CSS = document.createElement('link');
CSS.type = "text/css";
CSS.rel = "stylesheet";
CSS.href = url;
LibraryThing.LTFLreviewsWidget.dochead.appendChild(CSS);
};

LibraryThing.LTFLreviewsWidget.showmore = function(uniqid)
{
document.getElementById(uniqid).className = 'LTFL_showall';
}

LibraryThing.LTFLreviewsWidget.hidepartofstring = function(book)
{
var booktext = book.text;

var hidespan_start = '<span id="' + book.uniqid + '"><span class="LTFL_more">&hellip; (<a href="javascript:LibraryThing.LTFLreviewsWidget.showmore(\'' + book.uniqid + '\')">show more</a>)</span><span class="LTFL_hidden">';
var hidespan_end = '</span>';

if (booktext.length > 270)
	{
	booktext = booktext.replace(/^(.{240,270}[a-z] )(.*)/, "$1 " + hidespan_start + "$2" + hidespan_end);
	}
return booktext;
}

LibraryThing.LTFLreviewsWidget.makeBookreview = function(book)
{
if (book.text)
	{
	var bookreview = document.createElement('div');
	bookreview.setAttribute('class','LTFL_bookreview');

	if (book.text.length > 270)
		{
		book.text = LibraryThing.LTFLreviewsWidget.hidepartofstring(book);
		}
	bookreview.innerHTML = book.text;

	return bookreview;
	}
else
	{
	return null;
	}
}

LibraryThing.LTFLreviewsWidget.makeUserid = function(book)
{
if (book.userid)
	{
	var useridsection = document.createElement('div');
	useridsection.setAttribute('class','LTFL_userid');

	var useridURL = 'http://www.librarything.com/forlibraries/user/' + book.userid;
	// replace @ with %40 to make IE happy: it was showing the href for the text of the link
	// if there was an '@' in the useridURL.  Somehow related to the issue reported here:
	// http://www.hedgerwow.com/360/bugs/ie-anchor-bug.html.  Adding *just* the space before the href
	// didn't seem to be enough
	useridURL = useridURL.replace('@', '%40');
	var useridlink = document.createElement('a');
	useridlink.appendChild(document.createTextNode(book.userid));
	useridlink.setAttribute('href', ' '+useridURL );

	useridsection.appendChild(document.createTextNode('Review by '));
	useridsection.appendChild(useridlink);

	return useridsection;
	}
else
	{
	return null;
	}
}

LibraryThing.LTFLreviewsWidget.makeRatingimage = function(book)
{
if (book.rating)
	{
	var ratingimage = document.createElement("img");
	ratingimage.setAttribute('class','LTFL_rating');
	var url = 'http://www.librarything.com/pics/ss' + (book.rating) + '.gif';
	ratingimage.setAttribute('src', url);
	var num_stars = book.rating / 2;
	ratingimage.setAttribute('title', num_stars + ' stars');
	return ratingimage;
	}
else
	{
	return null;
	}
}

// The main callback
LibraryThing.LTFLreviewsWidget.makeBasicwidget = function(settings, ltdata)
{
if(settings.usernum)
	{
	var widgetdivname = 'LTFL_reviewwidget_' + settings.usernum;
	}
else
	{
	var widgetdivname = 'LTFL_reviewwidget_library_' + settings.library;	
	}
	
var LTFL_reviewwidget = document.getElementById(widgetdivname);

// Load the stylesheet
if (ltdata.css != '')
	{
	LibraryThing.LTFLreviewsWidget.loadStylesheet(ltdata.css);
	}
	
for (i in ltdata.reviews)
	{
	var book = ltdata.reviews[i];

	if (book.text != '')
		{
		// create item div
		var itemdiv = document.createElement("div");
		itemdiv.setAttribute('class', 'LTFL_item');
	
		if(book.rating > 0)
			{
			itemdiv.appendChild(LibraryThing.LTFLreviewsWidget.makeRatingimage(book));
			}

		// create title and author
		var titleandauthor = LibraryThing.LTFLreviewsWidget.makeTitleandauthorlink(book);
		titleandauthor.id = book.lsr_id;
		itemdiv.appendChild(titleandauthor);
		
		if(typeof book.userid != 'undefined')
			{
			itemdiv.appendChild(LibraryThing.LTFLreviewsWidget.makeUserid(book));
			}

		if(book.text)
			{
			itemdiv.appendChild(LibraryThing.LTFLreviewsWidget.makeBookreview(book));
			}

		LTFL_reviewwidget.appendChild(itemdiv);
		}		
	}

if (ltdata.reviews.length == 0)
	{
	var itemdiv = document.createElement("div");
	itemdiv.setAttribute('class', 'LTFL_item');
	itemdiv.innerHTML = 'No reviews.';
	LTFL_reviewwidget.appendChild(itemdiv);
	}

}


var widgetResults = {"reviews":{"923329":{"lsr_id":"923329","editedstamp":"1265135609","stamp":"1265135609","title":"Eat your peas, Louise! \/ by Pegeen Snow ; illustrations by Mike Venezia ; prepared under the direction of Robert Hillerich.","userid":"Brooks","opac_link":"http:\/\/ipac.librarypoint.org\/ipac20\/ipac.jsp?index=ISBNE&term=0516020676","text":"In this book, a mother begs her little girl to eat her peas. Rhyming words are used throughout the story. The little girl refuses to eat her peas until her mother says, \"please.\" The illustrations show the little girl as smug and defiant and the mother as frustrated. <br><br>I'm not aware of too many parents who are okay with begging their children to do what they've been asked to do. After hearing this book, your children may insist on YOU saying please to them before they choose to obey. We had to nip that one in the bud really quickly, explaining that it's actually not cute or funny to disobey.<br><br>Plenty of other high-quality rhyming books exist without conveying approval of and humor in disobedience.","rating":"2","uniqid":"4b725b5cd1d44"},"911095":{"lsr_id":"911095","editedstamp":"1263760466","stamp":"1263760466","title":"Wheel away! \/ by Dayle Ann Dodds ; illustrations by Thacher Hurd.","userid":"Brooks","opac_link":"http:\/\/ipac.librarypoint.org\/ipac20\/ipac.jsp?index=ISBNE&term=0060216883","text":"My 4 1\/2 and 3 year old were mesmerized by this book! Additionally, I loved reading it to them! At the beginning of the story, you will see a picture of a boy working on his bike at the top of a hill. When you turn the page, Oh no! A wheel rolls away! The story continues with the funny sounds the wheel makes as it bounces, splashes, and rolls through various parts of the town. Eventually, the wheel climbs the top of another hill and slows so much that it heads backward right through the town again! So, the children get to hear it go all the way back to the beginning, where the boy finally catches it. The final picture shows the boy riding his fixed bike down the hill.<br><br>The pictures are so fun to see and the words used to describe the wheel sounds are quite entertaining to speak to your children and for the children to hear.<br><br>I really enjoy reading books to my children that all of us can enjoy, and this is one of those books. It's simple, fun and entertaining.","rating":"10","uniqid":"4b725b5cdd8c9"},"911094":{"lsr_id":"911094","editedstamp":"1263760031","stamp":"1263760031","title":"Benny's pennies \/ by Pat Brisson ; illustrated by Bob Barner.","userid":"Brooks","opac_link":"http:\/\/ipac.librarypoint.org\/ipac20\/ipac.jsp?index=ISBNE&term=0385416024","text":"Oh, this book is so cute! My 4 and 3 yr. old enjoyed having this book read to them. They enjoyed the rhymes, the repetition, and how thoughtful it was of Benny to use all of his new pennies to give presents to other people, while his simple pleasure was in the purchasing and the giving. I personally enjoyed the artwork. I think my kids did, too :)<br><br>Learning points:<br>-Counting to five<br>-Concept of money and it's use<br>-Addition: If you have the child study two particular pictures, when Benny is holding the pennies in two hands, your child will observe that 2 (pennies in one hand) + 3 (pennies in the other hand) = 5 and 1 (penny in one hand) + 4 (pennies in the other hand) = 5.<br>-Rhyming<br>-Verse repetition<br>-Story recall (The mother asks for something beautiful. At the end of the story Benny gives her a rose. You can ask your child, \"Why did Benny give her a rose? Let's see, what did she ask for?\" ... \"Oh! Something beautiful! That's right!\")<br>-Unselfish giving<br><br>For as short and interesting as the story is, you can really glean a lot out of it, educationally! PERFECT when you want to make learning fun :)","rating":"10","uniqid":"4b725b5ce2eaf"},"911093":{"lsr_id":"911093","editedstamp":"1263759370","stamp":"1263759370","title":"Cat up a tree \/ written and illustrated by John and Ann Hassett.","userid":"Brooks","opac_link":"http:\/\/ipac.librarypoint.org\/ipac20\/ipac.jsp?index=ISBNE&term=0395884152","text":"In this book, Nany Quimby notices cats in a tree and calls to various departments in her town to help. The numbers increase and she tries different departments (library, fire department, etc.) However, each department says that they don't handle that sort of thing and to call back if she ever needs [whatever it is they DO aid in]. In the end Nana Quimby keeps the cats in her apartment and when a mouse problem transpires in the town, she is called for help since she has the cats. Her reply is that her cats don't handle that sort of thing.<br><br>Pros:<br>-The book is useful for teaching a child how to count by 5's as each cat grouping increases by fives. I've already returned the book so can't remember if it went up to 20, 25 or 30, but it at least goes up to 20.<br>-Children can use their counting skills to count the cats<br>-Children can get a sense for the use of different community departments (library, fire department, etc.) if you take the time to explain the responsibilities of each department.<br><br>Cons:<br>-While I believe that we do reap what we sow, I also believe that we are to do unto others as we would have them do unto us, NOT that we are to \"treat others only as well as they have treated us.\" \"Treat others only as well as they have treated us\" is exactly what Nana Quimby did when she would not offer her help when the town needed it. So if this poses a problem, then avoid the book. There are plenty of other ways to teach counting, counting by 5's, and community awareness :)","rating":"4","uniqid":"4b725b5cf384f"},"872700":{"lsr_id":"872700","editedstamp":"1258348177","stamp":"1258348177","title":"The secret of the mansion \/ by Julie Campbell ; illustrated by Mary Stevens ; cover illustration by Michael Koelsch.","userid":"momof6","opac_link":"http:\/\/ipac.librarypoint.org\/ipac20\/ipac.jsp?index=ISBNE&term=037582412X","text":"Very sweet.  Great for young girls - Trixie gets frustrated with her brothers, wants a horse, and is dying to have a best friend live close!  This particular book probably wouldn't be published as is today: I can't imagine anyone being happy about 2 young girls keeping secret the fact that an abused child is hiding in the abandoned house next door.  Especially since he's a teen-aged boy, just a little older than they are.  But then, this is a story from a much less troubled time.  Nice to read!","rating":"8","uniqid":"4b725b5d04fe7"}},"css":"http:\/\/ltfl.librarything.com\/\/forlibraries\/widgetcss\/style01.css"};
LibraryThing.LTFLreviewsWidget.settings.usernum = 0;
LibraryThing.LTFLreviewsWidget.settings.library = 171;
LibraryThing.LTFLreviewsWidget.settings.limit = 5;
LibraryThing.LTFLreviewsWidget.settings.category = "Kids";
LibraryThing.LTFLreviewsWidget.settings.newwindow = 0;
LibraryThing.LTFLreviewsWidget.settings.server = "";

LibraryThing.LTFLreviewsWidget.makeBasicwidget(LibraryThing.LTFLreviewsWidget.settings, widgetResults);


/*
	Array
(
    [reviews] => Array
        (
            [923329] => Array
                (
                    [lsr_id] => 923329
                    [editedstamp] => 1265135609
                    [stamp] => 1265135609
                    [title] => Eat your peas, Louise! / by Pegeen Snow ; illustrations by Mike Venezia ; prepared under the direction of Robert Hillerich.
                    [userid] => Brooks
                    [opac_link] => http://ipac.librarypoint.org/ipac20/ipac.jsp?index=ISBNE&term=0516020676
                    [text] => In this book, a mother begs her little girl to eat her peas. Rhyming words are used throughout the story. The little girl refuses to eat her peas until her mother says, "please." The illustrations show the little girl as smug and defiant and the mother as frustrated. <br><br>I'm not aware of too many parents who are okay with begging their children to do what they've been asked to do. After hearing this book, your children may insist on YOU saying please to them before they choose to obey. We had to nip that one in the bud really quickly, explaining that it's actually not cute or funny to disobey.<br><br>Plenty of other high-quality rhyming books exist without conveying approval of and humor in disobedience.
                    [rating] => 2
                    [uniqid] => 4b725b5cd1d44
                )

            [911095] => Array
                (
                    [lsr_id] => 911095
                    [editedstamp] => 1263760466
                    [stamp] => 1263760466
                    [title] => Wheel away! / by Dayle Ann Dodds ; illustrations by Thacher Hurd.
                    [userid] => Brooks
                    [opac_link] => http://ipac.librarypoint.org/ipac20/ipac.jsp?index=ISBNE&term=0060216883
                    [text] => My 4 1/2 and 3 year old were mesmerized by this book! Additionally, I loved reading it to them! At the beginning of the story, you will see a picture of a boy working on his bike at the top of a hill. When you turn the page, Oh no! A wheel rolls away! The story continues with the funny sounds the wheel makes as it bounces, splashes, and rolls through various parts of the town. Eventually, the wheel climbs the top of another hill and slows so much that it heads backward right through the town again! So, the children get to hear it go all the way back to the beginning, where the boy finally catches it. The final picture shows the boy riding his fixed bike down the hill.<br><br>The pictures are so fun to see and the words used to describe the wheel sounds are quite entertaining to speak to your children and for the children to hear.<br><br>I really enjoy reading books to my children that all of us can enjoy, and this is one of those books. It's simple, fun and entertaining.
                    [rating] => 10
                    [uniqid] => 4b725b5cdd8c9
                )

            [911094] => Array
                (
                    [lsr_id] => 911094
                    [editedstamp] => 1263760031
                    [stamp] => 1263760031
                    [title] => Benny's pennies / by Pat Brisson ; illustrated by Bob Barner.
                    [userid] => Brooks
                    [opac_link] => http://ipac.librarypoint.org/ipac20/ipac.jsp?index=ISBNE&term=0385416024
                    [text] => Oh, this book is so cute! My 4 and 3 yr. old enjoyed having this book read to them. They enjoyed the rhymes, the repetition, and how thoughtful it was of Benny to use all of his new pennies to give presents to other people, while his simple pleasure was in the purchasing and the giving. I personally enjoyed the artwork. I think my kids did, too :)<br><br>Learning points:<br>-Counting to five<br>-Concept of money and it's use<br>-Addition: If you have the child study two particular pictures, when Benny is holding the pennies in two hands, your child will observe that 2 (pennies in one hand) + 3 (pennies in the other hand) = 5 and 1 (penny in one hand) + 4 (pennies in the other hand) = 5.<br>-Rhyming<br>-Verse repetition<br>-Story recall (The mother asks for something beautiful. At the end of the story Benny gives her a rose. You can ask your child, "Why did Benny give her a rose? Let's see, what did she ask for?" ... "Oh! Something beautiful! That's right!")<br>-Unselfish giving<br><br>For as short and interesting as the story is, you can really glean a lot out of it, educationally! PERFECT when you want to make learning fun :)
                    [rating] => 10
                    [uniqid] => 4b725b5ce2eaf
                )

            [911093] => Array
                (
                    [lsr_id] => 911093
                    [editedstamp] => 1263759370
                    [stamp] => 1263759370
                    [title] => Cat up a tree / written and illustrated by John and Ann Hassett.
                    [userid] => Brooks
                    [opac_link] => http://ipac.librarypoint.org/ipac20/ipac.jsp?index=ISBNE&term=0395884152
                    [text] => In this book, Nany Quimby notices cats in a tree and calls to various departments in her town to help. The numbers increase and she tries different departments (library, fire department, etc.) However, each department says that they don't handle that sort of thing and to call back if she ever needs [whatever it is they DO aid in]. In the end Nana Quimby keeps the cats in her apartment and when a mouse problem transpires in the town, she is called for help since she has the cats. Her reply is that her cats don't handle that sort of thing.<br><br>Pros:<br>-The book is useful for teaching a child how to count by 5's as each cat grouping increases by fives. I've already returned the book so can't remember if it went up to 20, 25 or 30, but it at least goes up to 20.<br>-Children can use their counting skills to count the cats<br>-Children can get a sense for the use of different community departments (library, fire department, etc.) if you take the time to explain the responsibilities of each department.<br><br>Cons:<br>-While I believe that we do reap what we sow, I also believe that we are to do unto others as we would have them do unto us, NOT that we are to "treat others only as well as they have treated us." "Treat others only as well as they have treated us" is exactly what Nana Quimby did when she would not offer her help when the town needed it. So if this poses a problem, then avoid the book. There are plenty of other ways to teach counting, counting by 5's, and community awareness :)
                    [rating] => 4
                    [uniqid] => 4b725b5cf384f
                )

            [872700] => Array
                (
                    [lsr_id] => 872700
                    [editedstamp] => 1258348177
                    [stamp] => 1258348177
                    [title] => The secret of the mansion / by Julie Campbell ; illustrated by Mary Stevens ; cover illustration by Michael Koelsch.
                    [userid] => momof6
                    [opac_link] => http://ipac.librarypoint.org/ipac20/ipac.jsp?index=ISBNE&term=037582412X
                    [text] => Very sweet.  Great for young girls - Trixie gets frustrated with her brothers, wants a horse, and is dying to have a best friend live close!  This particular book probably wouldn't be published as is today: I can't imagine anyone being happy about 2 young girls keeping secret the fact that an abused child is hiding in the abandoned house next door.  Especially since he's a teen-aged boy, just a little older than they are.  But then, this is a story from a much less troubled time.  Nice to read!
                    [rating] => 8
                    [uniqid] => 4b725b5d04fe7
                )

        )

    [css] => http://ltfl.librarything.com//forlibraries/widgetcss/style01.css
)

*/
	