function $A(a){var r=[];for(var i=0,len=a.length;i<len;++i){r.push(a[i]);}return r;}Function.prototype.bind=function(){var _8=this,args=$A(arguments),object=args.shift();return function(){return _8.apply(object,args.concat($A(arguments)));};};function strcmp(a,b){if(a==b){return 0;}if(a==null){return -1;}if(b==null){return 1;}return a<b?-1:1;}
//function gV(z){var a=location.href.split('/');var a1="";var i;for(i=0;i<a.length;i++){if(a[i].split('=')[0]==z){if(a[i].split('=').length>1){a1=a[i].split('=')[1];}return a1;}}return "";}
//function gV2(z){var a=location.href.replace('&lan=ru', '').replace('&lan=en', '').replace('&lan=', '').replace('/lan/ru/', '').replace('/lan/en/', '').replace('/lan//', '');this.location.href=a+'&'+z;rf();}
//function gV2(z){var a=location.search.substring(1).replace('&lan=ru', '').replace('&lan=en', '').replace('&lan=', '');var b=gp(2).replace('/lan/ru/', '').replace('/lan/en/', '').replace('/lan//', '');this.location.href=gp(1)+b+'?'+a+'&'+z;rf();}
function ge(z){return document.getElementById(z);}
function gE(z,y){return z.getElementsByTagName(y);}
function ce(z){return document.createElement(z);}
function de(z){z.parentNode.removeChild(z);}
function ae(z,y){return z.appendChild(y);}
function ct(z){return document.createTextNode(z);}
function rf(){return false;}
function tb(){this.blur();}
function ac(z){var a=0,b=0;while(z){a+=z.offsetLeft;b+=z.offsetTop;z=z.offsetParent;}return [a,b];}
function aE(z,y,x){if(Browser.ie){z.attachEvent("on"+y,x);}else{z.addEventListener(y,x,false);}}
function sp(z){if(!z){z=event;}if(Browser.ie){z.cancelBubble=true;}else{z.stopPropagation();}}
function sc(z,y,x,w,v){var a=new Date();var b=z+"="+escape(x)+"; ";a.setDate(a.getDate()+y);b+="expires="+a.toUTCString()+"; ";if(w){b+="path="+w+"; ";}if(v){b+="domain="+v+"; ";}document.cookie=b;}
function dc(z){sc(z,-1);}
function gc(z){var b,c;if(!z){var a=[];c=document.cookie.split("; ");for(var i=0;i<c.length;++i){b=c[i].split("=");a[b[0]]=unescape(b[1]);}return a;}else{b=document.cookie.indexOf(z+"=");if(b!=-1){if(b==0||document.cookie.substring(b-2,b)=="; "){b+=z.length+1;c=document.cookie.indexOf("; ",b);if(c==-1){c=document.cookie.length;}return unescape(document.cookie.substring(b,c));}}}return null;}
function ns(n){n.onmousedown=n.onselectstart=n.ondragstart=rf;}
function cO(d,s){for(var p in s){d[p]=s[p];}}var Browser={ie:!!(window.attachEvent&&!window.opera),opera:!!window.opera,safari:navigator.userAgent.indexOf("Safari")!=-1,gecko:navigator.userAgent.indexOf("Gecko")!=-1&&navigator.userAgent.indexOf("KHTML")==-1};Browser.ie6=Browser.ie&&navigator.userAgent.indexOf("MSIE 6.0")!=-1;navigator.userAgent.match(/Gecko\/([0-9]+)/);Browser.geckoVersion=parseInt(RegExp.$1)|0;function pgetWindowSize(){var _41=0,height=0;if(typeof window.innerWidth=="number"){_41=window.innerWidth;height=window.innerHeight;}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){_41=document.documentElement.clientWidth;height=document.documentElement.clientHeight;}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){_41=document.body.clientWidth;height=document.body.clientHeight;}}}return [_41,height];}
function pgetScroll(){var x=0,y=0;if(typeof (window.pageYOffset)=="number"){x=window.pageXOffset;y=window.pageYOffset;}else{if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){x=document.body.scrollLeft;y=document.body.scrollTop;}else{if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){x=document.documentElement.scrollLeft;y=document.documentElement.scrollTop;}}}return [x,y];}
function pscrollTo(n,p){var _,windowSize=pgetWindowSize(),scroll=pgetScroll(),bcw=windowSize[0],bch=windowSize[1],bsl=scroll[0],bst=scroll[1];n=$(n);if(p==null){p=[];}else{if(typeof p=="number"){p=[p];}}_=p.length;if(_==0){p[0]=p[1]=p[2]=p[3]=0;}else{if(_==1){p[1]=p[2]=p[3]=p[0];}else{if(_==2){p[2]=p[0];p[3]=p[1];}else{if(_==3){p[3]=p[1];}}}}_=ac(n);var nl=_[0]-p[3];var nt=_[1]-p[0];var nr=_[0]+n.offsetWidth+p[1];var nb=_[1]+n.offsetHeight+p[2];if(nr-nl>bcw||nl<bsl){bsl=nl;}else{if(nr-bcw>bsl){bsl=nr-bcw;}}if(nb-nt>bch||nt<bst){bst=nt;}else{if(nb-bch>bst){bst=nb-bch;}}scrollTo(bsl,bst);}
function ptb(){pbm(ge("menu_placer"));}
function pbm(d){for(var i=0,len=mbr.length;i<len;++i){var a=ce("a"),span=ce("span");if(mbr[i][2]){a.href="?a="+mbr[i][2];}else{a.href="javascript:;";ns(a);}ae(span,ct(mbr[i][1]));ae(a,span);span.style.cursor="pointer";if(mbr[i][3]){span.className="menuarrowd";a.menu=mbr[i][3];a.onmouseover=Menu.show;a.onmouseout=Menu.hide;}else{span.className="menuarrowx";}ae(d,a);}}
function gp(z){var a=location.href.split('index');if(z==0)return a[0]+"/";if(z==1) return a[0]+"index.php";if(z==2) { if (a[1] != null) return a[1].replace('.php', ''); else return '';}}
gp();
var Menu={
 divs:[],selection:[],iframes:[],
 show:function(){
  try{
   clearTimeout(Menu.timer);
   if(Menu.currentLink){
    Menu._show(this);
   }
   else{
    this.className="open";
    Menu.timer=setTimeout(Menu._show.bind(0,this),100);
   }
  }
  catch(e){}
 },
 _show:function(_79){
  if(Menu.currentLink!=_79){
   var c=ac(_79);
   Menu._hide();
   Menu.selection=[-1];
   Menu.currentLink=_79;
   Menu.showDepth(0,_79.menu,c[0],c[1]+_79.offsetHeight-0,_79.offsetHeight+8,0,c[1]);
   _79.className="open";
  }
  else{
   Menu.truncate(0);
   Menu.clean(0);
  }
 },
 showAtCursor:function(e){
  e=$E(e);
  clearTimeout(Menu.timer);
  Menu._hide();
  Menu.selection=[-1];
  Menu.currentLink=null;
  var _7c=pgetScroll();
  Menu.showDepth(0,this.menu,e.clientX+_7c[0],e.clientY+_7c[1],0,0,0);},
 hide:function(){try{clearTimeout(Menu.timer);if(Menu.currentLink){Menu.timer=setTimeout(Menu._hide,333);}else{this.className="";}}catch(e){}},
 _hide:function(){for(var i=0,len=Menu.selection.length;i<len;++i){Menu.divs[i].style.display="none";Menu.divs[i].style.visibility="hidden";if(Browser.ie6) {
 Menu.iframes[i].style.display="none";
 }}Menu.selection=[];if(Menu.currentLink){Menu.currentLink.className="";}Menu.currentLink=null;},
 sepOver:function(){var d=this.d;var _7f=d.i;Menu.clean(_7f);Menu.selection[_7f]=-1;},
 elemOver:function(){var d=this.d;var _81=d.i;var i=this.i;var _83=this.firstChild.className=="menusub";Menu.truncate(_81+_83);if(_83&&i!=Menu.selection[_81]){var c=ac(this);Menu.selection[_81+1]=-1;Menu.showDepth(_81+1,d.menuArray[i][3],c[0],c[1]-0,this.offsetHeight,this.offsetWidth,0);}Menu.clean(_81);Menu.selection[_81]=i;if(this.className.length){this.className+=" open";}else{this.className="open";}},
 getIframe:
function(i) {
 var d;
 if(Menu.iframes[i]==null) {
 d=ce("iframe");
 d.src="javascript:0;";
 d.frameBorder=0;
 ae(ge("layers"),d);
 Menu.iframes[i]=d;
 }
 else {
 d=Menu.iframes[i];
 }
 return d;
 }
 ,getDiv:function(i,_88){var d;if(Menu.divs[i]==null){d=ce("div");d.className="menu";ae(ge("layers"),d);Menu.divs[i]=d;}else{d=Menu.divs[i];}d.i=i;d.menuArray=_88;return d;},
 showDepth:function(i,_8b,x,y,h,w,_90){
  var _,d=Menu.getDiv(i,_8b);
  while(d.firstChild){de(d.firstChild);}
  var _92=ce("table"),tbody=ce("tbody"),tr=ce("tr"),td=ce("td"),div=ce("div"),div2=ce("div");
  var m=999;
  var _94=pgetWindowSize(),scroll=pgetScroll(),bcw=_94[0],bch=_94[1],bsl=scroll[0],bst=scroll[1];

  if((h>0)&&(h<29)){
   if((h+1)*_8b.length>bch-25-_90){
    for(var j=2;j<4;++j){
     if(h/j*_8b.length+30<bch-_90){break;}
    }
    m=Math.floor(_8b.length/j);
   }
  }
  var row=0;
  var k=0;
  for(var j in _8b){
   if(_8b[j][0]==null){
    var sp=ce("span");
    sp.className="separator";
    ns(sp);ae(sp,ct(_8b[j][1]));sp.d=d;sp.onmouseover=Menu.sepOver;ae(div2,sp);}else{var a=ce("a");a.d=d;a.i=k++;if(_8b[j][2]){if(Menu.currentLink&&Menu.currentLink.menuappend){a.href="?a="+Menu.currentLink.menuappend;}else{if(typeof _8b[j][2]=="function"){a.href="javascript:;";a.onclick=_8b[j][2];ns(a);}else{a.href="?a="+_8b[j][2];}}}else{a.href="javascript:;";a.style.cursor="default";ns(a);}a.onmouseover=Menu.elemOver;var s=ce("span"),s2=ce("span");if(_8b[j][3]){s.className="menusub";}if(_8b[j][4]){s2.className="menucheck";}ae(s2,ct(_8b[j][1]));ae(s,s2);ae(a,s);ae(div2,a);}if(row++==m){div.onmouseover=Menu.divOver;div.onmouseout=Menu.divOut;ae(div,div2);if(!Browser.ie6){var p=ce("p");ae(p,ce("em"));ae(p,ce("var"));ae(p,ce("strong"));ae(p,div);ae(td,p);}else{ae(td,div);}ae(tr,td);td=ce("td");p=ce("p");div=ce("div");div2=ce("div");row=0;}}div.onmouseover=Menu.divOver;div.onmouseout=Menu.divOut;ae(div,div2);if(!Browser.ie6){if(m!=999){var p=ce("p");ae(p,ce("em"));ae(p,ce("var"));ae(p,ce("strong"));ae(p,div);ae(td,p);}else{ae(d,ce("em"));ae(d,ce("var"));ae(d,ce("strong"));ae(td,div);}}else{ae(td,div);}ae(tr,td);ae(tbody,tr);ae(_92,tbody);ae(d,_92);
 d.style.left=d.style.top="-2323px";d.style.display="";var tow=_92.offsetWidth,toh=_92.offsetHeight;if(x+w+tow+15>bcw){x=Math.max(0,x-tow-3);}else{x+=w;}if(y+toh>bch+bst){y=Math.max(bst+5,bch+bst-toh-10);}d.style.left=x+"px";d.style.top=y+"px";
  if(Browser.ie6) {
 _=Menu.getIframe(i);
 _.style['position']="absolute";
 _.style['background']="#e2ca87";
 _.style.left=x+"px";
 _.style.top=y+"px";
 _.style.width=tow+"px";
 _.style.height=toh+"px";
 _.style.display="";
 _.style.visibility="visible";
 }

 d.style.visibility="visible";if(Browser.opera){d.style.display="none";d.style.display="";}},
 divOver:function(){clearTimeout(Menu.timer);},
 divOut:function(){clearTimeout(Menu.timer);Menu.timer=setTimeout(Menu._hide,333);},
 truncate:function(a){var _;while(Menu.selection.length-1>a){_=Menu.selection.length-1;Menu.divs[_].style.display="none";if(Browser.ie6) {Menu.iframes[_].style.display="none";}Menu.divs[_].style.visibility="hidden";Menu.selection.pop();}},
 clean:function(a){for(var j=a;j<Menu.selection.length;++j){if(Menu.selection[j]!=-1){d=gE(Menu.divs[j],"a")[Menu.selection[j]];if(d.className.indexOf("sub")!=-1){d.className="sub";}else{d.className="";}Menu.selection[j]=-1;}}},
 append:function(a,t){a[2]+=t;if(a[3]!=null){Menu._append(a[3],t);}},
 _append:function(a,t){for(var i=0;i<a.length;++i){a[i][2]+=t;if(a[i][3]){Menu._append(a[i][3],t);}}},
fix:function(a,d,u){for(var i=0,len=a.length;i<len;++i){if(d){a[i][2]=u+a[i][0];if(a[i][3]){Menu.fix(a[i][3],d+1,u+a[i][0]+".");}}else{if(a[i][3]){Menu.fix(a[i][3],1,a[i][2]+"=");}}}}
};

    function showtipatcursor(e)
    {
      var obj = document.getElementById('tooltipcontainer');
      obj.style.display = "block";

            wHeight = document.body.clientHeight+document.body.scrollTop;
      lHeight = obj.offsetHeight;

      if (document.all&&!window.opera) {
        y = event.clientY + 10 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        x = event.clientX + 10 + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);

      } else {
        y = e.pageY + 10;
        x = e.pageX - 100;
      }

      fHeight = y + lHeight;

      if(fHeight > wHeight)
      {
        tmpvar = fHeight - wHeight;
        obj.style.top = (y - tmpvar) +"px";
        obj.style.left = x +"px";
      }
      else
      {
        obj.style.top = y +"px";
        obj.style.left = x +"px";
      }
    }

    function hidetip()
    {
      var obj = document.getElementById('tooltipcontainer');
      obj.style.display = "none";
    }

    function mtc(e, div)
    {
      var obj = document.getElementById(div);

      wHeight = document.body.clientHeight+document.body.scrollTop;
      lHeight = obj.offsetHeight;

      if (document.all&&!window.opera) {
        y = event.clientY + 10 + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
        x = event.clientX + 10 + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);

      } else {
        y = e.pageY + 10;
        x = e.pageX - 10;
      }

      fHeight = y + lHeight;

      if(fHeight > wHeight)
      {
        tmpvar = fHeight - wHeight;
        obj.style.top = (y - tmpvar) +"px";
        obj.style.left = x +"px";
      }
      else
      {
        obj.style.top = y +"px";
        obj.style.left = x +"px";
      }
    }
function idea_send() {
  if ($("#idea-input").val() == '') { alert('Не забудьте указать текст предложения!'); return; }
  if ($("#idea-input").val() == 'Ваше предложение') { alert('Не забудьте указать текст предложения!'); return; }
  $.ajax({url: window.location.href, type: 'POST', dataType: 'json', data: ({ 'name': 'idea', 'value': $("#idea-input").val() }), timeout: 15000});    
  $('#idea-offer').parent().hide();
  $('#idea-thanks').parent().show();
}

function zapros_send() {
  if ($("#zapros-input").val() == '') { alert('Не забудьте указать текст запроса!'); return; }
  if ($("#zapros-input").val() == 'Какова стоимость данного проекта?') { alert('Не забудьте указать текст запроса!'); return; }
  $.ajax({url: window.location.href, type: 'POST', dataType: 'json', data: ({ 'name': 'zapros', 'value': $("#zapros-input").val(), 'contact': $("#zapros-contact").val() }), timeout: 15000});
  $('#zapros-offer').parent().hide();
  $('#zapros-thanks').parent().show();
}

function ad_remove() {
  var ads = $('#informer');
  if (ads.css('display') == 'none') {
    setCookie('ads', 'show', 3600*24*30, '/');
    $('#noads_a').attr('n', '1');
    ads.show();
  }
  else {
    setCookie('ads', 'hide', 3600*24*30, '/');
    $('#noads_a').attr('n', '2');
    ads.hide();       
  }

}

function ad_check() {
  if (getCookie('ads') == 'hide') {
    $('#informer').hide();
    $('#noads_a').attr('n', '2');
    $('#noads_a img').attr('src', 'images/no-ads2.png');
  }
}

function getCookie (name) {
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0) {
      offset = cookie.indexOf(search);
      if (offset != -1) {
          offset += search.length;
          end = cookie.indexOf(";", offset)
          if (end == -1) {
              end = cookie.length;
          }
          setStr = unescape(cookie.substring(offset, end));
      }
  }
  return(setStr);
}

function setCookie(name, value, expires, path, domain, secure) {    // Send a cookie
    expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString());
    var r = [name + "=" + escape(value)], s, i;
    for(i in s = {expires: expires, path: path, domain: domain}){
        s[i] && r.push(i + "=" + s[i]);
    }
    return secure && r.push("secure"), document.cookie = r.join(";"), true;
}

function setCookie2 (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function prLayer2(className) {
  this.className = className;
  this.zIndex = 10008;
  this.opacity = '0.5';
  this.backgroundColor = '#000';
}

prLayer2.prototype.layerScroll = function() {
  var xScroll, yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
    xScroll = self.pageXOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop) {
    yScroll = document.documentElement.scrollTop;
    xScroll = document.documentElement.scrollLeft;
  }
  else if (document.body) {
    yScroll = document.body.scrollTop;
    xScroll = document.body.scrollLeft;
  }
  arrayPageScroll = [xScroll, yScroll];
  return arrayPageScroll;
}

prLayer2.prototype.layerSize = function() {
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {
    xScroll = window.innerWidth + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  }
  else if (document.body.scrollHeight > document.body.offsetHeight) {
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  }
  else {
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }
  var windowWidth, windowHeight;
  if (self.innerHeight) {
    if (document.documentElement.clientHeight) windowWidth = document.documentElement.clientWidth;
    else windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  }
  else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  if (yScroll < windowHeight) pageHeight = windowHeight;
  else pageHeight = yScroll;
  if (xScroll < windowWidth) pageWidth = xScroll;
  else pageWidth = windowWidth;
  arrayPageSize = [pageWidth, pageHeight, windowWidth, windowHeight];
  return arrayPageSize;
}

prLayer2.prototype.layerShow = function(obj) {
  // prep objects
  this.obj = obj;
  var objOverlay = document.getElementById('__'+this.className+'-overlay');
  if (!objOverlay) {
    if (!document.getElementsByTagName) { return; }
    var objBody = document.getElementsByTagName("body")[0];
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id', '__'+this.className+'-overlay');
    objOverlay.style.zIndex = this.zIndex;
    objOverlay.style.position = 'absolute';
    objOverlay.style.top = '0px';
    objOverlay.style.left = '0px';
    objOverlay.style.width = '100%';
    objOverlay.style.opacity = this.opacity;
    objOverlay.style.backgroundColor = this.backgroundColor;
    objBody.insertBefore(objOverlay, objBody.firstChild);
  }
  objOverlay.style.display = 'none';
  var arrayPageSize = this.layerSize();
  var arrayPageScroll = this.layerScroll();
  
  objOverlay.style.height = (arrayPageSize[1] + 'px');
  objOverlay.style.display = 'block';

  selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    if (selects[i].style.display != "none") {
      selects[i].style.visibility = "hidden";
    }
  }
  embed = document.getElementsByTagName("embed");
  for (i = 0; i != embed.length; i++) {
    if (embed[i].style.display != "none") {
      embed[i].style.visibility = "hidden";
    }
  }
  objects = document.getElementsByTagName("object");
  for (i = 0; i != objects.length; i++) {
    if (objects[i].style.display != "none") {
      objects[i].style.visibility = "hidden";
    }
  }
  arrayPageSize = this.layerSize();
  objOverlay.style.height = (arrayPageSize[1] + 'px');
  obj.style.display = 'block';
  obj.style.left = ((arrayPageSize[2]-obj.offsetWidth)/2+arrayPageScroll[0])+'px';
  obj.style.top = ((arrayPageSize[3]-obj.offsetHeight)/2+arrayPageScroll[1])+'px';
}

prLayer2.prototype.layerHide = function(obj) {
  if (!obj) obj = this.obj;
  objOverlay = document.getElementById('__'+this.className+'-overlay');
  objOverlay.style.display = 'none';
  obj.style.display = 'none';
  selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    if (selects[i].style.display != "none") {
      selects[i].style.visibility = "visible";
    }
  }
  embed = document.getElementsByTagName("embed");
  for (i = 0; i != embed.length; i++) {
    if (embed[i].style.display != "none") {
      embed[i].style.visibility = "visible";
    }
  }
  objects = document.getElementsByTagName("object");
  for (i = 0; i != objects.length; i++) {
    if (objects[i].style.display != "none") {
      objects[i].style.visibility = "visible";
    }
  }
}

function prPreview(id) {
  if ($('#preview-project').length < 1) {
    $('body').append('<div id="preview-project"></div>');
  }
  $.ajax({url: window.location.href, type: 'POST', dataType: 'html', data: ({ 'name': 'preview', 'value': id }), 
  success: function(reply){
    if (!__this.layer) {
      __this.layer = new prLayer2('project');
    }
    $('#preview-project').html(reply);
    $('#preview-project').append('<div id="preview-project-close" onclick="__this.layer.layerHide();">Закрыть</div>');
    __this.layer.layerShow($('#preview-project').get(0));
  },
  timeout: 15000});
}

function prPreview_events() {
  $('.project-view').live('mouseover', function() {
      $(this).addClass('hover');
  }).live('mouseout', function() {
      $(this).removeClass('hover');
  });

  $('.project-view .button').live('mouseover', function() {
      $(this).addClass('hover');
    }).live('mouseout', function() {
      $(this).removeClass('hover');
    }).live('click', function() {
      prPreview($(this).attr('pr'));
      return false;
  });
  
}

function initDiscount() {
  setInterval(discountTick, 1000);
}

function discountTick() {
  __discount.now += 1;
    var _ = __discount.end - __discount.now;
    var days = Math.floor(_/86400);
    _ = _ - days*86400;
    var hours = Math.floor(_/3600);
    _ = _ - hours*3600;
    var minutes = Math.floor(_/60);
    var seconds = _ - minutes*60;
    if (hours < 10) hours = '0'+hours;
    if (minutes < 10) minutes = '0'+minutes;
    if (seconds < 10) seconds = '0'+seconds;
    var __ = '';
    if (days > 0) __ += days+'дн. ';
    __ += hours+':'+minutes+':'+seconds;
  $('#discount-left').html(__);
}

function sz_opros() {
  if (getCookie('opros_finished') == '1') return;
  //if (window.sz_ready) sz_opros_start();
  // else window.sz_opros = 1;
  sz_opros_start();
}

function sz_opros_start() {
  var a = $('<a style="display: none;" href="#opros"></a>'); a.fancybox({
    'titlePosition': 'inside',
    'transitionIn': 'none',
    'transitionOut': 'none',
    'showCloseButton': false,
    'overlayColor': '#8d0000',
    'overlayOpacity': 0.7,
    'padding': 0
  });
  var _ = '<div style="display: none;"><div id="opros">'+
    '<div id="opros-1"><div class="yes" onclick="sz_opros_step(1);"></div><div class="no" onclick="sz_opros_finish();"></div></div>'+
    '<div id="opros-2"><textarea id="opros-2-t"></textarea><div class="send" onclick="sz_opros_step(2);"></div></div>'+
    '<div id="opros-3"><textarea id="opros-3-t"></textarea><div class="send" onclick="sz_opros_step(3);"></div></div>'+
    '<div id="opros-4"><textarea id="opros-4-t"></textarea><div class="send" onclick="sz_opros_step(4);"></div></div>'+
    '<div id="opros-5"></div>'+
    '<div class="close" onmouseover="$(this).addClass(\'close-active\');" onmouseout="$(this).removeClass(\'close-active\');" onclick="sz_opros_finish();"></div>'+
  '</div></div>';
  $('body').append(_);
  $('body').append(a);
  setTimeout(function() { a.trigger('click'); }, 1000);
}

function sz_opros_step(step) {
  if (!window.sz_opros_res) window.sz_opros_res = {};
  if (step == 1) { $('#opros-1').hide(); $('#opros-2').show(); }
  if (step == 2) {
    window.sz_opros_res[1] = $('#opros-2-t').val(); 
    $('#opros-2').hide(); $('#opros-3').show(); 
  }
  if (step == 3) {
    window.sz_opros_res[2] = $('#opros-3-t').val(); 
    $('#opros-3').hide(); $('#opros-4').show(); 
  }
  if (step == 4) { 
    window.sz_opros_res[3] = $('#opros-4-t').val();
    $.ajax({url: window.location.href, type: 'POST', dataType: 'json', data: ({ 'name': 'opros', 'val1': sz_opros_res[1], 'val2': sz_opros_res[2], 'val3': sz_opros_res[3] }), timeout: 15000});
    $('#opros-4').hide(); $('#opros-5').show(); 
  }
}

function iota(el) {
  var _ = $(el).parents('form');
  $.ajax({url: window.location.href, type: 'POST', dataType: 'json', data: _.serializeJSON(), timeout: 15000});
  _.html('Большое спасибо!<br />Ваше мнение очень важно для нас, оно обязательно будет учтено нашим отделом по контролю за качеством!');
}

function sz_opros_finish() {
  $.fancybox.close();
  $('#opros').remove();
  setCookie('opros_finished', '1', 3600*24*30, '/');
}

function fav_init() {
  var __ = false, found = false, r = '';
  var _ = getCookie('sz_fav'); if (!_) _ = ''; _ = _.split('|');
  if (window.location.search.indexOf('b=view') > -1) {
    __ = window.location.search.split('&c=');
    if (!__ || !__[1]) return;
    __ = __[1];
  }
  for (var i in _) {
    if (_[i].length < 2) continue;
    if (_[i] == __) found = true;
    r += '<a class="project-view" href="?b=view&c='+_[i]+'"><div pr="'+_[i]+'" class="button">Мини просмотр</div><img height="90px" width="120px" src="image.php/n1/'+_[i]+'/n/1/picture.jpg" style="padding-top:0px;padding-bottom:0px;border: 1px solid #383838;"></a>';
  }
  if (!found && __.length > 1) _.push(__);
  setCookie('sz_fav', _.join('|'), 3600*24*30, '/');
  if (r.length > 1) {
    r = '<div id="fav"><div class="recent"></div><div class="list">'+r+'</div></div>';
    $('body').append(r);
    $('#fav .recent').click(function() {
      $('#fav .list').toggle();
    });
  }
}


$(document).ready(function() {
  ad_check();
  fav_init();
  if ($(window).width() > 1500) $('#discs-page').addClass('discs-1600');
  else if ($(window).width() > 1100) $('#discs-page').addClass('discs-1280');
  else $('#discs-page').addClass('discs-1024');
  prPreview_events();
  //window.sz_ready = 1;
  //if (window.sz_opros) sz_opros_start();
});

jQuery.fn.serializeJSON=function() {
  var json = {};
  jQuery.map(jQuery(this).serializeArray(), function(n, i){
    var _ = n.name.indexOf('[');
    if (_ > -1) {
      var _cat = n.name.substr(0, _);
      var _name = n.name.substr(_+1).replace(']', '');
      if (!json[_cat]) json[_cat] = {};
      json[_cat][_name] = n['value'];
    }
    else json[n['name']] = n['value'];
  });
  return json;
};

var __this = { };


