function right_most_loved_looks_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    $.get(
        '/all-the-looks/allthelooks/photos/most_loved',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            right_rail_photo_block_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
function right_most_hated_looks_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    $.get(
        '/all-the-looks/allthelooks/photos/most_hated',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            right_rail_photo_block_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function right_rail_photo_block_itemAddCallback(carousel, first, last, xml)
{

    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));
   $(xml).find('item').each (function(i){
    var name = $(this).find ('image').attr('name');
    var image_url = $(this).find ('image').text();
    var rate_class = $(this).find ('rate').attr('class');
    var rate = $(this).find ('rate').text();
    var url = $(this).find ('url').text();
    carousel.add(first + i, right_rail_photo_block_getItemHTML(name, image_url, rate_class, rate, url));
   });

};

/**
 * Item html creation helper.
 */
function right_rail_photo_block_getItemHTML(name, img, rate_class, rate, url)
{
  var ret_html  = '';
  ret_html += '<div class="most_love_item" >';
  ret_html += '<div class="item_img" >';
  ret_html += '<a href="' + url + '">';
  //ret_html += '<img src="' + img + '" width="85" height="100" alt="" />';
  ret_html += img ;
  ret_html += '</a>';
  ret_html += '<div class="item_name" ><a href="' + url + '">' + name + '</a></div>';
  ret_html += '</div>';
  ret_html += '<div class="item_rate ' + rate_class+ '"><div class="rate_icon"></div> <div class="rate_val">' + rate + '%</div><div class="rating-vote"><a href="' + url + '"><img src="/all-the-looks/sites/mylifetime.com.all-the-looks/themes/allthelooks/images/x.gif" height="20" width="50" /></a></div></div>';
  ret_html += '<div class="clear"></div>';
  ret_html += '</div>';
  return ret_html;
};
$(document).ready(function() {
    $('#right_most_loved_looks').jcarousel({
	visible:2,
	scroll:2,
	size:12,
	start: 1,
	animation:"slow",
	wrap:null,
        itemLoadCallback: right_most_loved_looks_itemLoadCallback
    });
    $('#right_most_hated_looks').jcarousel({
	visible:2,
	scroll:2,
	size:12,
	start: 1,
	animation:"slow",
	wrap:null,
        itemLoadCallback: right_most_hated_looks_itemLoadCallback
    });
});
