$(document).ready(function() {
	
	// Compare options
	$('a.compare').each(function() {
		
		var url = $(this).attr('href');


		$(this).click(function() {
			
			// Add loading bar
			var img = $('<img src="images/ajax-loader.gif" alt="Loading..." />');
			$(this).after(img);
			$(this).remove();

			$.get(url, null, function(data) {
				var html = $(data);
				$(img).after(html);
				$(img).remove();
			}, 'html');
			return false;
		})
	})


	// Find reviews
	$('p.review').each(function(i, p) {

  	// Hide this
  	$(p).hide();
  	
  	// Place a shortened version
  	var t = $('<p class="review">' + $(p).text().substr(0,100) + '...' + '</p>');
  	$(p).after(t);
  	
  	// 'Read more' link
  	var a = $('<a href="#" class="more">read full review</a>');
  	$(t).after(a);

  	$(a).click(function() {
			$(this).remove();
			$(t).remove();
			$(p).slideDown();
			return false;
		})
	})
	
	
	// Add 'more buying' options
	$('.priceOptions').each(function() {
		var optionsDiv = this;
		// See if there are more than 3 buying options
		if($(optionsDiv).children().size() > 3) {
			// Add a hidden div
			var moreOptions = $('<div></div>');
			$(moreOptions).hide();
			$(optionsDiv).after(moreOptions);

			// Place the extra buying options in the hidden div
			$(optionsDiv).children().each(function(i, optionP) {
				if(i > 2) {
					$(moreOptions).append(optionP);
				}
			})
			
			// Add a 'more option'
			var more = $('<a href="#" style="font-size: 80%">More buying options...</a>');
			$(optionsDiv).after(more);
			$(more).click(function() {
				$(this).hide();
				$(moreOptions).slideDown();
				return false;
			})
		}
	})
})