//<![CDATA[
var FAST_DELAY_1 = "fast";
var FAST_DELAY_2 = 100;
/*
* Prepare the preloadres
*/
($.prepareLoaders = function (color) {
  var divId = ["spinnerLoading_", color, "_UNIQUE"].join("");
  var $div = $(["<div id='", divId, "' />"].join(""));
  var $img = $(["<img alt='' src='/Content/Shared/Images/spinner_", color, ".gif' />"].join(""));
  $div.css({
    display: "none",
    border: "solid 1px #F09821",
    position: "fixed",
    width: "200px",
    height: "15px",
    "z-index": "1000",
    "background-color": "#EAE9DD",
    opacity: ".6",
    margin: "0px",
    "margin-left": "-100px",
    padding: "0px",
    top: "46px",
    left: "50%"
  });
  $img.css({
    position: "absolute",
    width: "16px",
    height: "11px",
    "margin-top": "-5px",
    "margin-left": "-8px",
    top: "50%",
    left: "50%"
  });
  $div.append($img);
  //-
  $(document.body).append($div);
  $div.ajaxStart(function () { $(this).show("drop", { direction: "left" }, "fast"); });
  $div.ajaxSuccess(function () { $(this).hide("drop", { direction: "right" }, "normal"); });
  //-
});
$(document).ready(function () {
  $.prepareLoaders("orange");
});
/*
* Load's the albums
*/
function loadAlbum(url, fbLink, lastIdx, sizeIndex, asSpecial) {
  //-
  if (sizeIndex === "undefined") sizeIndex = 1;
  if (asSpecial === "undefined") asSpecial = false;
  //-
  hideComments();
  //-
  var selector = "#album > #details";
  if ($(selector).size() <= 0) selector = "#album";
  $(selector).fadeTo(FAST_DELAY_1, .1, function () {
    $.post(url, { "fbLink": fbLink, "lastIdx": lastIdx, "sizeIndex": sizeIndex }, function (returnData) {
      $(selector).html(returnData);
      //-
      if (asSpecial) {
        relocateComments();
      }
      //-
      $(selector).fadeTo(FAST_DELAY_1, 1, function () {
        showComments();
      });
    });
  });
  //-
};
/*
* Show the selected photo...
*/
function showPhoto(id) {
  var _url = "/canino/razas/imageUrl";
  $.post(_url, { "pid": id }, function (returnData) {
    //-
    var $div = $("<div />");
    var $img = $("<img />");
    //-
    $div.attr("title", "Visor de im&aacute;genes");
    $div.css("display", "none");
    $img.attr("alt", "");
    $img.attr("src", returnData.src);
    $img.css({
      "max-width": "629px",
      "max-height": "472px"
    });
    $img.one("load", function () { $div.dialog("open"); });
    $div.append($img);
    //-
    $(document.body).append($div);
    $div.dialog({
      autoOpen: false,
      modal: true,
      resizable: false,
      width: "auto",
      minWidth: (returnData.width > 629) ? 629 : returnData.width,
      height: "auto",
      minHeight: (returnData.height > 472) ? 472 : returnData.height,
      buttons: {
        "Cerrar": function () { $(this).dialog("close"); }
      },
      close: function () { $(this).remove(); }
    });
    //-
  });
};
/*
* Hidding the comments...
*/
function hideComments() {
  $("#comments > .comment:eq(0)").fadeOut(FAST_DELAY_2, function () {
    $(this).next().fadeOut(FAST_DELAY_2, arguments.callee);
  });
};
/*
* Move/Relocate the comments..
*/
function relocateComments() {
  var $comments = $("#album > #comments").clone();
  $("#album > #comments").remove();
  $("#album").after($comments);
  //-
  var $p = $("#album > .picture > p").clone();
  $("#album > .picture > p").remove();
  $("#album > .picture").after($p);
};
/*
* Show the comments...
*/
function showComments() {
  //-
  //- Show the comments...
  $("#comments > .comment:eq(0)").show("slide", { direction: "left" }, FAST_DELAY_2, function () {
    $(this).find("span.message").autoEllipsis();
    $(this).next().show("slide", { direction: "left" }, FAST_DELAY_2, arguments.callee);
  });
  //-
};
//]]>
