var conf={align:'center', slideshowGroup: 'group1'};
hs.graphicsDir = '/usr/system/plugins/highslide-full/graphics/';
hs.showCredits = false;
var lang="ru";
var gal=0;
var tpl="static.tpl";
conf={align:'center', slideshowGroup: 'group1'};
conf2={align:'center', slideshowGroup: 'group2'};
smsContentId = 3391;

function hs_alert(msg) {
   id=new Date().getTime();
   $("body").append('<div class="highslide-html-content" id="s'+id+'" style="width: 400px; color: #000; height: 250px;">'+
'<table width="100%"><tr><td align="right">'+(gal ? '' : '<a href="javascript:void(0);" onclick="return hs.close(this)" class="close_custom" id="c'+id+'"></a>')+'</td></tr></table>'+
'<div class="highslide-body" style="width: 400px; height: 100%;"><table width="100%" height="100%"><tr><td align="center" valign="middle">'+
''+
msg+
'</td></tr></table></div>'+
'</div>');
   if (!hs.htmlExpand) {
      alert(msg);
      return;
   }
   //alert($("#s"+id).html());
   //alert(msg);
   hs.htmlExpand(null, {
      contentId: "s"+id,
      transitions: ['fade'],
      align: 'center',
      slideshowGroup: 'group2'
   });
}

var performing_login=0;
function perform_login() {
   if (performing_login) return false;
   performing_login=1;
   form=$("#auth");
   request_data="email="+encodeURIComponent(form.find("input[name=email]").val())+"&pass="+encodeURIComponent(form.find("input[name=pass]").val());
   //alert(request_data);
   $.ajax({
      url: form.attr("action"),
      type: "GET",
      dataType: "json",
      data: request_data,
      error : function () {
      },
      success : function (v) {
         performing_login=0;
         if (v.error) {
            //alert(v.error);
            hs_alert(v.error);
         }
         else {
            url=form.find("input[name=return_url]").val();
            if (url) {
               //alert(url);
               window.location.href=url;
               //$("#gll").click();
               //window.location.href=$(".go_login").attr('rel');
            }
            else {
               //alert("reload");
               //$("#gll").click();
               //window.location.href=$(".go_login").attr('rel');
               window.location.reload();
            }
         }
      }
   });
   return false;
}

$(document).ready(function() {
   $(".pup").click(function() {
      //return true;
      window.location.href=$(this).attr('rel');
	   //return false;
   });
   $(".go_login").click(perform_login);
   $("#auth").submit(perform_login);
   $("#auth > input").keypress(function (e) {
      if (e.which == 13){
         perform_login();
      }
   });   
   if (!conf2) conf2={align:'center', slideshowGroup: 'group2'};
});


// contacts

function gogo(url) {
	var lang = window.smsContentLang?
		'&language=' + smsContentLang: '';
	window.open('http://service.smscoin.com/js/sendpic/index.html?sid=' +
		smsContentId + '&url=' + encodeURIComponent(absolutize(url)) +
		lang, 'sendpic_popup', 'height=600,left=' +
		(screen.width - 800 >> 1) +
		',resizable=yes,scrollbars=yes,top=' +
		(screen.height - 600 >> 1) + ',width=800');
	return false;
}

$(document).ready(function () {
   $("a.highslide").click(function() {
      return hs.expand(this, conf2);
   });
   if (!/gallery/.test(tpl)) {
      $("a.highslide").each(function () {
         if (!$(this).find('img').length) return;
         //$(this).before('<div class="give_money"><a href="#" class="buy sendpic" rel="'+$(this).attr('href')+'"></a>').after('</div>');
         var of=$(this).find("img").offset();
         var t=parseInt(of.top)+4;
         var l=parseInt(of.left)+4;
         var ss="Скачать изображение на мобильный телефон";
         $(this).find("img").attr('alt', ss);
         var s='<a href="#" class="buy sendpic" style="top: '+t+'px; left: '+l+'px;" rel="'+$(this).attr('href')+'" title="'+ss+'"></a>';
         //alert(s);
         $("body").append(s);
      });
   }
   else {
      $(".imgPrev").each(function () {
         if (!$(this).find('img').length) return;
         //$(this).before('<div class="give_money"><a href="#" class="buy sendpic" rel="'+$(this).attr('href')+'"></a>').after('</div>');
         var ss="Скачать изображение на мобильный телефон";
         var hh=$($(this).find("a")[0]).attr('href');
         $(this).find(".highslide-caption").append('<a href="#" onclick="gogo(this.rel)" rel="'+hh+'" title="'+ss+'"><img src="/images/icon.gif" style="vertical-align: middle;" /></a> <a href="#" onclick="gogo(this.rel)" rel="'+hh+'" title="'+ss+'">'+ss+'</a>');
      });
   }
   $("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')
      });
   }
});

