/******************************************************************************
 * Jelen programkód tulajdonosa: FotoMarket Kft.                              *
 *                                                                            *
 * A kód részének vagy egészének felhasználása a tulajdonos írásos engedélye  *
 * nélkül SZIGORÚAN TILOS!                                                    *
 *                                                                            *
 * Copyright (c) FotoMarket Kft. 2006-2008. Minden jog fenntartva.            *
 ******************************************************************************/
String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
        return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
        return this.replace(/\s+$/,"");
}

function displayPicture(pictureid) {
  $("a#gallery_thumbnails_link_" + pictureid).click();
}

$(document).ready(function() {
  $("div.gallery_thumbnails").hover(function() {
    $(this).addClass("gallery_thumbnails_hover");
  }, function() {
    $(this).removeClass("gallery_thumbnails_hover");
  });

  $("img#previewpicture").load(function() {
    $(this).show();
  });

  $("div.gallery_thumbnails a, a#gallery_navigation_prior, a#gallery_navigation_next").click(function() {
    $("#previewpicture").hide();
    $("#gallery_adtext").remove();

    $.get(this.href, {}, function(updatedata) {
      $("pictureinfos/picturedatas/picturedata", updatedata).each(function(){
        var currentnode = $(this);
        if (currentnode.attr("id") == "size") {
          $("#picturedata_" + currentnode.attr("id")).html(currentnode.text() + " KB");
        } else {
          $("#picturedata_" + currentnode.attr("id")).html(currentnode.text().trim());
        }
      });

      $("pictureinfos/exifdatas/exifdata", updatedata).each(function(){
        var currentnode = $(this);
        $("#exifdata_" + currentnode.attr("id")).html(currentnode.text().trim());
      });

      var imagesize = $("span#imagesize").text();
      $("a#gallery_currentpicture_link").attr("href", "/?get=/viewlarge/pictureid/" + $("picturedata[@id=id]", updatedata).text().trim());
      $("a#gallery_navigation_prior").attr("href", "/?get=/viewpicture/previewsize/" + imagesize + "/pictureid/" + $("pictureinfos/updatecontent/priorpictureid", updatedata).text().trim());
      $("a#gallery_navigation_next").attr("href", "/?get=/viewpicture/previewsize/" + imagesize + "/pictureid/" + $("pictureinfos/updatecontent/nextpictureid", updatedata).text().trim());
      $("#gallery_navigation_currentpicture").html($("pictureinfos/updatecontent/imageindex", updatedata).text()).show();

      var adtextdata = $("pictureinfos/adcontent", updatedata).text().trim();
      if (adtextdata != '') {
        adtextdata = '<div id="gallery_adtext">' + adtextdata + '</div>';
        $("#gallery_preview_table td").append(adtextdata);
      } else {
        $("img#previewpicture").attr("src", $("pictureinfos/updatecontent/picturepath", updatedata).text().trim());
      }
    });

    return false;
  });

  $("div.gallery_thumbnails a:first").click();
  if ($("div.gallery_thumbnails_body").css("float") == "left") {
    $("div.gallery_thumbnails_body").css("float", "none");
    $("div.gallery_thumbnails_body").width($("div.gallery_thumbnails a").length * 80);
  }
});
