﻿var tb_pathToImage = "loading.gif";
$(document).ready(function() {
   tb_init("a.thickbox, area.thickbox, input.thickbox"); imgLoader = new Image(); imgLoader.src = tb_pathToImage}
);
function tb_init(A) {
   $(A).click(function() {
      var C = this.title || this.name || null; var B = this.href || this.alt; var D = this.rel || false; var F = this.name || ""; var E = this.getAttribute("desc") || ""; tb_show(C, B, D, F, E); this.blur(); return false}
   )}
function tb_show(M, C, J, I, K) {
   try {
      if(typeof document.body.style.maxHeight === "undefined") {
         $("body", "html").css( {
            height : "100%", width : "100%"}
         );
         $("html").css("overflow", "hidden");
         if(document.getElementById("TB_HideSelect") === null) {
            $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
            $("#TB_overlay").click(tb_remove)}
         }
      else {
         if(document.getElementById("TB_overlay") === null) {
            $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
            $("#TB_overlay").click(tb_remove)}
         }
      if(tb_detectMacXFF()) {
         $("#TB_overlay").addClass("TB_overlayMacFFBGHack")}
      else {
         $("#TB_overlay").addClass("TB_overlayBG")}
      $("#TB_overlay").css( {
         height : $(document).height() + "px", width : $(document).width()}
      );
      if(M === null) {
         M = ""}
      $("body").append("<div id='TB_load'><img src='" + imgLoader.src + "' /></div>");
      $("#TB_load").show();
      var B = C.replace(/^[^\?]+\??/,"");
      var H = tb_parseQuery(B);
      var D = (C.indexOf("?") !==- 1) ? C.substr(0, C.indexOf("?")) : C;
      var G = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
      var N = D.toLowerCase().match(G);
      if(N == ".jpg" || N == ".jpeg" || N == ".png" || N == ".gif" || N == ".bmp") {
         prevCaption = "";
         prevURL = "";
         prev = false;
         nextCaption = "";
         nextURL = "";
         next = false;
         imageCount = "";
         foundURL = false;
         if(J) {
            var A = $("a[rel=" + J + "]").get();
            for(TB_Counter = 0; ((TB_Counter < A.length) && (!next)); TB_Counter++) {
               var F = A[TB_Counter].href.toLowerCase().match(G);
               if(!(A[TB_Counter].href == C)) {
                  if(foundURL) {
                     nextAuthor = A[TB_Counter].name;
                     nextDesc = A[TB_Counter].getAttribute("desc") || "";
                     nextCaption = A[TB_Counter].title;
                     nextURL = A[TB_Counter].href;
                     next = true}
                  else {
                     prevAuthor = A[TB_Counter].name;
                     prevDesc = A[TB_Counter].getAttribute("desc") || "";
                     prevCaption = A[TB_Counter].title;
                     prevURL = A[TB_Counter].href;
                     prev = true}
                  }
               else {
                  foundURL = true;
                  imageCount = (TB_Counter + 1) + "/" + (A.length)}
               }
            }
         imgPreloader = new Image();
         imgPreloader.onload = function() {
            imgPreloader.onload = null;
            var O = tb_getPageSize();
            var W = O[0] - 50;
            var U = O[1] - 100;
            var T = imgPreloader.width;
            var P = imgPreloader.height;
            if(T > W) {
               P = P * (W / T);
               T = W;
               if(P > U) {
                  T = T * (U / P);
                  P = U}
               }
            else {
               if(P > U) {
                  T = T * (U / P);
                  P = U;
                  if(T > W) {
                     P = P * (W / T);
                     T = W}
                  }
               }
            TB_WIDTH = T + 20;
            TB_HEIGHT = P + 60;
			if(TB_WIDTH < 200) {
				TB_WIDTH = 200;
			}
			
            var X = $("#TB_window");
            //X.append("<table id='TB_wc' width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td class='left_top' height='28' width='28'></td><td class='top'></td><td class='right_top' height='28' width='28'></td></tr><tr><td class='left'></td><td class='center'><div id='TB_imgTitle'><div id='TB_closeAjaxWindow' ><a href='#' id='TB_closeWindowButton' title='uždaryti'>uždaryti</a></div><div id='TB_ajaxWindowTitle'>" + M + "</div><span id='TB_description'>" + K + "</span></div><a href='' id='TB_ImageOff'><img id='TB_Image' src='" + C + "' width='" + T + "' height='" + P + "' /></a><div id='TB_secondLine'><span id='TB_imgCounter'>" + imageCount + "</span>" + I + "</div></td><td class='right'></td></tr><tr><td class='left_bottom'></td><td class='bottom'></td><td class='right_bottom'></td></tr></table>");
			X.append("<div id='TB_imgTitle'><div id='TB_closeAjaxWindow' ><a href='#' id='TB_closeWindowButton' title='uždaryti'>uždaryti</a></div><span id='TB_description'>" + K + "</span></div><a href='' id='TB_ImageOff'><img id='TB_Image' src='" + C + "' width='" + T + "' height='" + P + "' /></a><div id='TB_secondLine'><span id='TB_imgTitleTxt'>" + M + "</span><span id='TB_imgCounter'>" + imageCount + "</span>" + I + "</div>");
            var S = $("#TB_ImageOff");
            tb_position();
            $("#TB_load").remove();
            S.click(tb_remove);
            X.fadeIn("normal");
            var Q = $("#TB_Image").position();
            S.after("<div id='TB_navlinks' style='height:" + P + "px;top:" + (Q.top + 1) + "px;width:" + TB_WIDTH + "px;'></div>");
            $("#TB_closeWindowButton").click(tb_remove);
            if(prev) {
               function R() {
                  if($(document).unbind("click", R)) {
                     $(document).unbind("click", R)}
                  $("#TB_window").remove();
                  $("body").append("<div id='TB_window'></div>");
                  tb_show(prevCaption, prevURL, J, prevAuthor, prevDesc);
                  return false}
               $("#TB_navlinks").append("<a href='#' id='TB_prev' style='height:" + P + "px;'></a>");
               $("#TB_prev").click(R)}
            if(next) {
               function V() {
                  $("#TB_window").remove();
                  $("body").append("<div id='TB_window'></div>");
                  tb_show(nextCaption, nextURL, J, nextAuthor, nextDesc);
                  return false}
               $("#TB_navlinks").append("<a href='#' id='TB_next' style='height:" + P + "px;'></a>");
               $("#TB_next").click(V)}
            $("#TB_navlinks").click(tb_remove);
            document.onkeydown = function(Y) {
               if(Y == null) {
                  keycode = event.keyCode}
               else {
                  keycode = Y.which}
               if(keycode == 27) {
                  tb_remove()}
               else {
                  if(keycode == 190) {
                     if(next) {
                        document.onkeydown = "";
                        V()}
                     }
                  else {
                     if(keycode == 188) {
                        if(prev) {
                           document.onkeydown = "";
                           R()}
                        }
                     }
                  }
               }
            };
         imgPreloader.src = C}
      else {
         var E = tb_getPageSize();
         TB_WIDTH = (H.width * 1) + 30 || 630;
         TB_HEIGHT = (H.height * 1) + 40 || zz440;
         ajaxContentW = TB_WIDTH - 30;
         ajaxContentH = TB_HEIGHT - 45;
         if(C.indexOf("TB_iframe") !=- 1) {
            urlNoQuery = C.split("TB_");
            $("#TB_iframeContent").remove();
            if(H.modal != "true") {
               $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + M + "</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='uždaryti'>uždaryti</a></div></div><iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;' > </iframe>")}
            else {
               $("#TB_overlay").unbind();
               $("#TB_window").append("<iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "' id='TB_iframeContent' name='TB_iframeContent" + Math.round(Math.random() * 1000) + "' onload='tb_showIframe()' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;'> </iframe>")}
            }
         else {
            if($("#TB_window").css("display") != "block") {
               if(H.modal != "true") {
                  $("#TB_window").append("<table id='TB_wc' width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td class='left_top' height='28' width='28'></td><td class='top'></td><td class='right_top' height='28' width='28'></td></tr><tr><td class='left'></td><td class='center'><div id='TB_title'><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='uždaryti'>uždaryti</a></div><div id='TB_ajaxWindowTitle'>" + M + "</div></div><div id='TB_ajaxContent'></div></td><td class='right'></td></tr><tr><td class='left_bottom'></td><td class='bottom'></td><td class='right_bottom'></td></tr></table>")}
               else {
                  $("#TB_overlay").unbind();
                  $("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal'></div>")}
               }
            else {
               if(H.width) {
                  $("#TB_ajaxContent")[0].style.width = ajaxContentW + "px"}
               if(H.height) {
                  $("#TB_ajaxContent")[0].style.height = ajaxContentH + "px"}
               $("#TB_ajaxContent")[0].scrollTop = 0;
               $("#TB_ajaxWindowTitle").html(M)}
            }
         $("#TB_closeWindowButton").click(tb_remove);
         if(C.indexOf("TB_inline") !=- 1) {
            $("#TB_ajaxContent").append($("#" + H.inlineId).children());
            $("#TB_window").unload(function() {
               $("#" + H.inlineId).append($("#TB_ajaxContent").children())}
            );
            tb_position();
            $("#TB_load").remove();
            $("#TB_window").fadeIn("normal")}
         else {
            if(C.indexOf("TB_iframe") !=- 1) {
               tb_position();
               if($.browser.safari) {
                  $("#TB_load").remove();
                  $("#TB_window").css( {
                     display : "block"}
                  )}
               }
            else {
               $("#TB_ajaxContent").load(C += "&random=" + (new Date().getTime()), function() {
                  tb_position(); $("#TB_load").remove(); tb_init("#TB_ajaxContent a.thickbox"); $("#TB_window").fadeIn("normal"); var O = $("#TB_ajaxContent"); var P = O.children()[0]; TB_WIDTH = P.clientWidth + 56; TB_HEIGHT = P.clientHeight; tb_position()}
               )}
            }
         }
      if(!H.modal) {
         document.onkeyup = function(O) {
            if(O == null) {
               keycode = event.keyCode}
            else {
               keycode = O.which}
            if(keycode == 27) {
               tb_remove()}
            }
         }
      }
   catch(L) {
      }
   }
function tb_showIframe() {
   $("#TB_load").remove();
   $("#TB_window").css( {
      display : "block"}
   )}
function tb_remove() {
   $("#TB_imageOff").unbind("click");
   $("#TB_closeWindowButton").unbind("click");
   $("#TB_window").fadeOut("normal", function() {
      $("#TB_window,#TB_overlay,#TB_HideSelect").trigger("unload").unbind().remove()}
   );
   $("#TB_load").remove();
   if(typeof document.body.style.maxHeight == "undefined") {
      $("body", "html").css( {
         height : "auto", width : "auto"}
      );
      $("html").css("overflow", "")}
   document.onkeydown = "";
   document.onkeyup = "";
   return false}
function tb_position() {
   var B = $("#TB_window");
   var A = $(window);
   B.css( {
      marginLeft : parseInt(((A.width() - TB_WIDTH) / 2), 10) + "px", width : TB_WIDTH + "px", marginTop : ( ( parseInt(((A.height() - B.height()) / 2 + A.scrollTop()), 10) > 0 ) ? parseInt(((A.height() - B.height()) / 2 + A.scrollTop()), 10) : 10) + "px"}
   )}
function tb_parseQuery(D) {
   var E = {
      };
   if(!D) {
      return E}
   var A = D.split(/[;&]/);
   for(var C = 0; C < A.length; C++) {
      var G = A[C].split("=");
      if(!G || G.length != 2) {
         continue}
      var B = unescape(G[0]);
      var F = unescape(G[1]);
      F = F.replace(/\+/g," ");
      E[B] = F}
   return E}
function tb_getPageSize() {
   var C = document.documentElement;
   var A = window.innerWidth || self.innerWidth || (C && C.clientWidth) || document.body.clientWidth;
   var B = window.innerHeight || self.innerHeight || (C && C.clientHeight) || document.body.clientHeight;
   arrayPageSize = [A, B];
   return arrayPageSize}
function tb_detectMacXFF() {
   var A = navigator.userAgent.toLowerCase();
   if(A.indexOf("mac") !=- 1 && A.indexOf("firefox") !=- 1) {
      return true}
   }; 
