
hs.graphicsDir = '/usr/system/plugins/highslide-html/graphics/';
hs.showCredits = false;
var lang="ru";
var total=0;
var curpage=1;
var cid="";
var loading=0;
var pdone=1;

var speed_fadeout_pages=500;
var speed_show_nav=1000;

hs.outlineType = 'custom';
hs.captionEval = 'this.a.title';

hs.lang = {
	cssDirection: 'ltr',
	loadingText: 'Загружается...',
	loadingTitle: 'Нажмите для отмены',
	focusTitle: 'Нажмите чтобы поместить на передний план',
	fullExpandTitle: 'Развернуть до оригинального размера',
	creditsText: 'Использует <i>Highslide JS</i>',
	creditsTitle: 'Перейти на домашнюю страницу Highslide JS',
	previousText: 'Предыдущее',
	nextText: 'Следующее',
	moveText: 'Переместить',
	closeText: 'Закрыть',
	closeTitle: 'Закрыть (esc)',
	resizeTitle: 'Изменить размер',
	playText: 'Слайдшоу',
	playTitle: 'Начать слайдшоу (пробел)',
	pauseText: 'Пауза',
	pauseTitle: 'Приостановить слайдшоу (пробел)',
	previousTitle: 'Предыдущее (стрелка влево)',
	nextTitle: 'Следующее (стрелка вправо)',
	moveTitle: 'Переместить',
	fullExpandText: 'Оригинальный размер',
	number: 'Изображение %1 из %2',
	restoreTitle: 'Нажмите чтобы закрыть изображение, нажмите и перетащите для изменения местоположения. Для просмотра изображений используйте стрелки.'
};

hs.align='center';

function nav(p) {
   if (tpl=="stamps_2.tpl") {
      if (!pdone) return;
      pdone=0;
      curpage+=p;
      //if ((curpage-1)*12>total) curpage=1;
      //if (curpage<=0) curpage=Math.ceil(total/12);
      //alert("page="+curpage);
      var prev_html;
      loading=1;
      prev_html="";
      $("#rightPage").fadeOut(speed_fadeout_pages-1);
      $("#leftPage").fadeOut(speed_fadeout_pages, function () {
         if (!loading) return;
         loading=0;
         $(".pages").html('<div class="loading"><img src="/usr/system/loading.gif"></div>').show();
         $.ajax({
            url: "/stamps/stamps_2/",
            type: "GET",
            data: "ajax=1&page="+curpage+"&cid="+cid,
            success : function (v) {
               $("#container").html(v).hide().fadeIn(speed_fadeout_pages, function () {
                  if ($.browser.msie) this.style.removeAttribute('filter');
               });
               pdone=1;
               upd();
            },
            error: function () {
               //alert("err");
            }
         });

      });
   }
   else if (tpl=="stamps_1.tpl" || tpl=="teen.tpl") {
      if (!pdone) return;
      pdone=0;
      curpage+=p;
      //if ((curpage-1)*12-6>total) curpage=1;
      //if (curpage<=0) curpage=Math.ceil(total/12);
      //alert("page="+curpage);
      var prev_html;
      loading=1;
      prev_html="";
      $("#rightPage").fadeOut(speed_fadeout_pages-1);
      $("#leftPage").fadeOut(speed_fadeout_pages, function () {
         if (!loading) return;
         loading=0;
         $(".pages").html('<div class="loading"><img src="/usr/system/loading.gif"></div>').show();
         $.ajax({
            url: "/stamps/stamps_1/",
            type: "GET",
            data: "ajax=1&page="+curpage+"&cid="+cid,
            success : function (v) {
               //alert("pp1="+curpage);
               //alert(v);
               $("#container").html(v).hide().fadeIn(speed_fadeout_pages, function () {
                  if ($.browser.msie) this.style.removeAttribute('filter');
               });
               pdone=1;
               //alert("pp="+curpage);
               upd();
            },
            error: function () {
               //alert("err");
            }
         });

      });
   }
   else if (tpl=="stamps_0.tpl") {
      if (!pdone) return;
      pdone=0;
      curpage+=p;
      //if ((curpage-1)*12-12>total) curpage=1;
      //if (curpage<=0) curpage=Math.ceil(total/12);
      //alert("page="+curpage);
      var prev_html;
      loading=1;
      prev_html="";
      $("#rightPage").fadeOut(speed_fadeout_pages-1);
      $("#leftPage").fadeOut(speed_fadeout_pages, function () {
         if (!loading) return;
         loading=0;
         $(".pages").html('<div class="loading"><img src="/usr/system/loading.gif"></div>').show();
         //alert("ajax=1&page="+curpage+"&cid="+cid);
         $.ajax({
            url: "/stamps/stamps_0/",
            type: "GET",
            data: "ajax=1&page="+curpage+"&cid="+cid,
            success : function (v) {
               //alert(v);
               $("#container").html(v).hide().fadeIn(speed_fadeout_pages, function () {
                  if ($.browser.msie) this.style.removeAttribute('filter');
               });
               pdone=1;
               upd();
            },
            error: function () {
               //alert("err");
            }
         });

      });
   }
   else {
      if (!pdone) return;
      pdone=0;
      curpage+=p;
      if ((curpage-1)*6>total) curpage=1;
      if (curpage<=0) curpage=Math.ceil(total/6);
      //alert("page="+curpage);
      var prev_html;
      loading=1;
      prev_html=$("#rightPage").html();
      $("#rightPage").fadeOut(speed_fadeout_pages-1);
      $("#leftPage").fadeOut(speed_fadeout_pages, function () {
         if (!loading) return;
         loading=0;
         $(".pages").html('<div class="loading"><img src="/usr/system/loading.gif"></div>').show();
         $.ajax({
            url: "/stamps/stamps/",
            type: "GET",
            data: "ajax=1&page="+curpage+"&cid="+cid,
            success : function (v) {
               $("#rightPage").html(v).hide().fadeIn(speed_fadeout_pages, function () {
                  if ($.browser.msie) this.style.removeAttribute('filter');
               });
               $("#leftPage").html(prev_html).hide().fadeIn(speed_fadeout_pages, function () {
                  if ($.browser.msie) this.style.removeAttribute('filter');
               });
               pdone=1;
               upd();
            },
            error: function () {
               //alert("err");
            }
         });

      });
   }
}

function upd() {
   $(".ico").parent().unbind("click");
   $(".ico").parent().click(function () {
      return hs.htmlExpand(null, {
         objectType: 'iframe',
         width: (tpl=="teen.tpl" ? 660 : 640),
         height: (tpl=="teen.tpl" ? 465 : 370),
         align: 'center',
         src: $(this).attr('href'),
         headingText: $(this).find("img").attr('alt'),
         wrapperClassName: 'titlebar'
      });
   });
   $(".more").unbind("click");
   $(".more").click(function () {
      var e;
      return hs.htmlExpand(null, {
         objectType: 'iframe',
         width: 400,
         align: 'center',
         headingText: "",
         src: $(this).attr('href'),
         wrapperClassName: 'titlebar'
      });
   });
   $(".main").unbind("click");
   $(".main").click(function () {
      var e;
      return hs.htmlExpand(null, {
         width: 400,
         align: 'center',
         headingText: "",
         contentId: 'main-content',
         wrapperClassName: 'titlebar'
      });
   });
   if (tpl=="stamps_2.tpl") {
      if ((curpage)*12>=total) $("#page_arrow_right").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_right").fadeIn(speed_fadeout_pages);
      if (curpage-1<=0) $("#page_arrow_left").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_left").fadeIn(speed_fadeout_pages);  
   }
   else if (tpl=="stamps_1.tpl" || tpl=="teen.tpl") {
      if ((curpage)*12-6>=total) $("#page_arrow_right").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_right").fadeIn(speed_fadeout_pages);
      if (curpage-1<=0) $("#page_arrow_left").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_left").fadeIn(speed_fadeout_pages);  
      //alert(curpage);
   }
   else if (tpl=="stamps_0.tpl") {
      if ((curpage)*12-12>=total) $("#page_arrow_right").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_right").fadeIn(speed_fadeout_pages);
      if (curpage-1<=0) $("#page_arrow_left").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_left").fadeIn(speed_fadeout_pages);  
   }
   else {
      if ((curpage)*6>total) $("#page_arrow_right").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_right").fadeIn(speed_fadeout_pages);
      if (curpage-1<=0) $("#page_arrow_left").fadeOut(speed_fadeout_pages);
      else $("#page_arrow_left").fadeIn(speed_fadeout_pages);  
   }
}

$(document).ready(function() {
   $("#page_arrow_left").click(function () {
      nav(-1);
      return false;
   });
   $("#page_arrow_right").click(function () {
      nav(1);
      return false;
   });
   upd();
});


// contacts

$(document).ready(function () {
   $("a.highslide").click(function() {
      if ($(this).hasClass('img_ico_b')) {
         return;
      }
      return (parent ? parent.hs : hs).expand(this);
   });
   $("input[type=button]").each(function () {
      if ($(this).attr('href')) {
        $(this).click(function () {
           window.location.href=$(this).attr('href');
        });
      }
   });
   if ($.validationEngine) {
      $(".valForm").validationEngine({
         ajaxSubmit: true,
         ajaxSubmitFile: $(".valForm").attr('action')
      });
   }
});

