var gallery = function(id) {
    $(id).ready(function() {
        var $images = $("ul.gallery-images li", id);
        var index = 0;
        if ($images.length > 0) {
            $(id).append("<div class=\"current-image\">" +
                         "<div class=\"gallery-image\">" +
                         $(".gallery-image", $($images[0])).html() +
                         "</div>"+
                         "<table cellpadding=\"0\" cellspacing=\"0\" class=\"image-panel\">" +
                         "<!--tr><td colspan=\"3\"></td></tr>"+
                         "<tr-->" +
                         "<td style=\"text-align: left\"><a href=\"javascript:void(0)\" class=\"previous disabled\"><img src=\"images/blank.gif\" width=\"28\" height=\"15\" alt=\"\" class=\"previous\"></a></td>" +
                         "<td>" +
                         "<div class=\"image-title\">" +
                         $(".image-title", $($images[0])).html() +
                         "</div>" +
                         "</td>" +
                         "<td style=\"text-align: right\"><a href=\"javascript:void(0)\" class=\"next\"><img src=\"images/blank.gif\" width=\"28\" height=\"15\" alt=\"\" class=\"next\"></a></td>" +
                         "</tr>" +
                         "</table>");
            var previous = function() {
                if (index > 0) {
                    $(".current-image .gallery-image", id).html($(".gallery-image", $($images[--index])).html());

                    $(".current-image .image-title", id).html($(".image-title", $($images[index])).html());

                    if (index < $images.length - 1)
                        $(".next", id).removeClass("disabled");
                }
                if (index <= 0 && !$(this).hasClass("disabled")) {
                    $(this).addClass("disabled");
                }
            };
            var next = function() {
                if (index < $images.length - 1) {
                    $(".current-image .gallery-image", id).html($(".gallery-image", $($images[++index])).html());

                    $(".current-image .image-title", id).html($(".image-title", $($images[index])).html());
                    if (index > 0) {
                        $(".previous", id).removeClass("disabled");
                    }
                }
                if (index >= $images.length - 1 && !$(this).hasClass("disabled"))
                    $(this).addClass("disabled");
            };

            $("a.previous", id).click(previous);

            $("a.next", id).click(next);
        }
    });
};
/*var gallery = function(id) {
 $(id).ready(function() {
 var $images = $("ul.gallery-images li", id);
 var index = 0;
 if ($images.length > 0) {
 $(id).append("<div class=\"current-image\">" + $images[0].innerHTML +
 "</div>\n<div class=\"gallery-navigation\">\n" +
 "<a href=\"javascript:void(0)\" class=\"previous disabled\">&larr;</a> " +
 "<a href=\"javascript:void(0)\" class=\"next\">&rarr;</a></div>\n");
 var previous = function() {
 if (index > 0) {
 $(this).parent().prev(".current-image").html($images[--index].innerHTML);
 if (index < $images.length - 1)
 $(".next", $(this).offsetParent(".gallery-navigation")).removeClass("disabled");
 }
 if (index <= 0 && !$(this).hasClass("disabled")) {
 $(this).addClass("disabled");
 }
 };
 var next = function() {
 if (index < $images.length - 1) {
 $(this).parent().prev(".current-image").html($images[++index].innerHTML);
 if (index > 0) {
 $(".previous", $(this).offsetParent(".gallery-navigation")).removeClass("disabled");
 }
 }
 if (index >= $images.length - 1 && !$(this).hasClass("disabled"))
 $(this).addClass("disabled");
 };

 $(".gallery-navigation .previous", id).click(previous);

 $(".gallery-navigation .next", id).click(next);
 }
 });
 };*/