d = document;
num = parseInt;
function tag(o, v) {
    return (v) ? (o.tagName.toLowerCase() == v.toLowerCase()) : o.tagName.toLowerCase();
}

function make_tabs(tabs, pads, opts) {
	
	
	var o1 = this, s = s || 0, $ = jQuery,
	
	def = {
		t:300,
		eff:function() {this.fadeIn(def.t)},
		click:function(e) {
			if (this.tagName.toLowerCase() == 'a') {
				e.preventDefault();
				e.stopPropagation();				
			}
			
			var o = $(this), _p = this._p;
			
			if (def.hide && _p.s[0] == this) {
				o.removeClass('s');
				this.pad.hide();
				_p.s = false;				
				return (false);
			}
			
			if (_p.s) {			
				_p.s.removeClass('s');
				_p.s[0].pad.hide();
			}
				
			o.addClass('s');
			
			_p.s = o;
			def.eff.apply(this.pad);			
		},
		hide:false
	};
	if (opts) $.extend(def, opts);
	
	if (def.hide) s = -1;
	
	tabs.each(function(i, o) {
		o.pad = $(pads[i]);
		o._p = o1;
		o.i = i;
		
		var o = $(o).click(def.click)
		
		if (o.hasClass('s') && !s) s = i;
		
	});
	
	
	o1.s = (def.hide) ? false : $(tabs[s]).addClass('s');
	o1.tabs = tabs;
	pads.filter(function(i) {return i != s}).hide();
	
	return o1;	
}

function scroll(o, opts) {
	var $ = jQuery, def = {items:3, controls:'<div class="arrl"/><div class="arrr"/>'}, h = 0, w = 0, w2 = 0;
	opts = $.extend(def, opts || {});
	o.index = 0;

	o.controls = o.find('img.arrl, img.arrr')
	if (!o.controls.length) o.controls = $(opts.controls).appendTo(o);
	o.controls.click(function() {
		o.itms.eq(o.index).removeClass('s');
		(this.className == 'arrr') ? o.index++ : o.index--;
		if (o.index > o.itms.length/2) {o.index = 1; o.hold.scrollLeft(0)}
		if (o.index < 0) {o.index = o.itms.length/2-1;  o.hold.scrollLeft(o.scr.width()/2) } 
		
		o.itms.removeClass('s').eq(o.index).addClass('s');
		
		o.hold.animate({'scrollLeft': o.index*w}, 300, 'swing');  return (false)
	});

	o.scr = o.find('ul');
	o.itms = o.find('li');
	o.hold = o.scr.parent();

	o.itms.each(function(i) {if (this.className == 's') o.index = i; this.pos = w2; w2 += this.offsetWidth});	

	w = o.itms.outerWidth()+num(o.itms.css('marginLeft'))+num(o.itms.css('marginRight'))+num(o.itms.css('borderLeftWidth'))+num(o.itms.css('borderRightWidth'));

	o.scr.width((o.itms.length*w));

	$(function() {
		o.hold.scrollLeft(0);
		if (o.scr.width()<= o.hold.width()) {
			o.controls.hide();

		} else {
			o.itms = o.itms.clone().appendTo(o.scr).parent().find('li')

		}

        o.scr.width((o.itms.length*w))
    })
	
	return (o);
}

function scroll2 (o) {
		var hold = o.find('div.hold'), 
			itms = hold.find('li'), 
			w = itms.outerWidth(), 
			s = 0,
			add = w/2,
			ul = hold.find('ul').width(w*(itms.length*2)).css('marginLeft', -add),
			flag = false,
		
	
	
		pages = o.find('.pages3 a').each(function(i) {this.i=i}).click(function() {
		
			if (flag) return (false);
		
			flag = true;
		
			s = this.i;
			
			pages.removeClass('s').eq(s).addClass('s');
			itms.removeClass('s').eq(s).addClass('s')
			
			ul.animate({marginLeft:-(s*w+add)}, 500, 'swing', function() {			
				flag = false;});
				
			return (false);
		});
	}
	
function scroll3(o, opts) {
	var $ = jQuery, def = {items:3, controls:'<div class="arrl"/><div class="arrr"/>'}, h = 0, w = 0, w2 = 0, flag = 0;
	opts = $.extend(def, opts || {});
	o.index = 0;

	o.controls = o.find('img.arrl, img.arrr')
	if (!o.controls.length) o.controls = $(opts.controls).appendTo(o);	
	o.controls.mousedown(function() {
		clearInterval(o.t1);
		flag = (this.className == 'arrr') ? 1 : -1;
		o.t1 = setInterval(function() {if (!flag) clearInterval(o.t1); o.hold[0].scrollLeft += 10*flag}, 10)
	}).mouseout(function() {flag = 0})

	o.scr = o.find('ul');
	o.itms = o.find('li');
	o.hold = o.scr.parent();

	o.itms.each(function(i) {if (this.className == 's') {o.index = i; } this.pos = w2; w2 += this.offsetWidth});

	w = o.itms.outerWidth()+num(o.itms.css('marginLeft'))+num(o.itms.css('marginRight'))+num(o.itms.css('borderLeftWidth'))+num(o.itms.css('borderRightWidth'));

	o.scr.width((o.itms.length*w));

	$(function() {
		o.hold.scrollLeft(0);
		if (o.scr.width()<= o.hold.width()) {
			o.controls.hide();

		} else {
			//o.itms = o.itms.clone().appendTo(o.scr).parent().find('li')
			//o.scr.width((o.itms.length*w))
		}})
	
	return (o);
}

function set_album_viewer() {
	var $ = jQuery, s = new scroll3($('#album_view1 .album')), pct = $('#pct1'),
	
	links = s.scr.find('a')
		.each(function(i) {this.i=i; this.img = this.getElementsByTagName('img')[0]; })
		.click(function(e) {
			e.preventDefault();
			s.index = this.i; 
			pct.css('backgroundImage','url('+this.href+')');
			s.itms.removeClass('s').eq(s.index).addClass('s');
            var ext = this.href.split('.').pop();
			$('#about1').html(this.img.alt+' &nbsp;&nbsp; <a href="'+$(this).data('link')+'?contentdisposition=attachment" class="down">Скачать фотографию</a> ('+((ext)?ext:'')+', '+$(this).data('size')+' Кб)');
			
			if (this.parentNode.offsetLeft<s.hold.scrollLeft() || this.parentNode.offsetLeft+this.parentNode.offsetWidth>s.hold.scrollLeft()+s.hold.width()) s.hold.animate({scrollLeft:this.parentNode.offsetLeft}, 300)
		});
	
	s.parent().find('.pct .arrl, .pct .arrr').click(function() {		
		s.index += (this.className == 'arrr') ? 1 : -1;
		if (s.index<0) s.index = s.itms.length-1;
		if (s.index>=s.itms.length) s.index = 0;
		links.eq(s.index).click()
	})
	
	links.eq(s.index).click();
}

function show_promo () {
			var t = 10000, o = jQuery('#promo'), flag = true, i = 1, scr = o.find('div.scr'), hold = o.find('div.hold'),
				act = function() {
					clearTimeout(t1);
					if (!flag) return (false);
					push.removeClass('play');
					
					if (i>=o.itms.length) {i=0; };
					 
					cntr.find('a').each(function(i2) {this.className = (i == i2 || !i2 && i > o.itms.length-2) ? 's' : ''});
					o.itms.hide().eq(i).fadeIn(3000, function() {if (i>=o.itms.length-1) {i=0; return (false)}; i++; });
					t1 = setTimeout(act, t);
					},
					
				t1 = setTimeout(act, t),
				cntr = o.find('div.control').on('click', 'a', function() {var new_i = parseInt(this.title)-1; flag = true; i = new_i; act();}),
				pages = o.find('span.pages'),
				push = o.find('span.sw').appendTo(cntr).click(function() {clearTimeout(t1);  if (flag) {this.className = 'sw play'; flag = false; this.clicked = true;} else {this.className = 'sw'; flag = true; this.clicked = false; act();}})
				
			
			o.itms = o.find('div.i'); 
			o.itms.each(function(i) {this.link = jQuery('<a title="'+(i+1)+'"'+((i) ? '' : ' class="s"')+'/>').appendTo(pages)});
			cntr.find('a').eq(0).click();
			
}

function set_player_param(id, elemId, width, height) {
  width = width != null ? width : 650;
  height = height != null ? height : 368;
  var flashHtml = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\"" +
            "width=\""+width+"\"" +
            "height=\""+height+"\" title=\"thumb\">" +
      "<param name=\"movie\" value=\"images/flash_video/sxplayer.swf\"/>" +
      "<param name=\"allowfullscreen\" value=\"true\"/>" +
      "<param name=\"quality\" value=\"high\"/>" +
      "<param name=\"flashvars\" value=\"id=" + id + "\"/>" +
      "<param name=\"wmode\" value=\"transparent\"/>" +

      "<embed src=\"images/flash_video/sxplayer.swf\" quality=\"high\"" +
             "pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\"" +
             "type=\"application/x-shockwave-flash\"" +
             "width=\""+width+"\" height=\""+height+"\"" +
             "allowfullscreen=\"true\" " +
             "flashvars=\"id=" + id + "\" " +
             "wmode=\"transparent\"></embed>" +
    "</object>";
  var video_pop_flash = document.getElementById(elemId != null ? elemId : "video_pop_flash");
  video_pop_flash.innerHTML = flashHtml;
}

function show_date() {
    var d = new Date();
    document.write(
      ["Воскресенье","Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"][d.getDay()] + ', ' +
        d.getDate() + " " +
        ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"] [d.getMonth()]  + " " +
        d.getFullYear()
    )
}


function show_pop(id, url) {
    var $ = jQuery, shade = $('#sh'), o = $('#' + id);
    if (!o.length) return (false);

    if (!shade.length) shade = $('<div id="sh"/>').click(function () {
        shade.add('div.popup').hide();
    }).appendTo(d.body)

    shade.fadeIn();

    if (url) {
        o.appendTo(d.body).show().empty().load(url, function () {
            o.data('loaded', 1).show().css('margin', (o.outerHeight() / -2) + 'px 0 0 ' + (o.outerWidth() / -2) + 'px')
        });
    } else {
        o.appendTo(d.body).show().css('margin', (-o.outerHeight() / 2) + 'px 0 0 ' + (-o.outerWidth() / 2) + 'px');
    }
}
function addToTitle(){}
function show_pop2(id, url) {
    var $ = jQuery, shade = $('#sh'), o = $('#' + id);
    if (!o.length) return (false);

    if (!shade.length) shade = $('<div id="sh"/>').click(function () {
        shade.add('div.popup').hide();
    }).appendTo(d.body);

    shade.fadeIn();

    if (url) {
        o.show();
        jQuery(".popup-contents", o).text('загрузка...').load(url, function () {
            o.show().css('margin', (o.outerHeight() / -2) + 'px 0 0 ' + (o.outerWidth() / -2) + 'px')
        });
    } else {
        o.show().css('margin', (-o.outerHeight() / 2) + 'px 0 0 ' + (-o.outerWidth() / 2) + 'px');
    }
}

function popup1(url) {
  show_pop('popup1', url);
}

function set_rate(hold) {
        var $ = jQuery;
      if (!hold) hold = $('body');

        hold.find('span.rate').each(function() {
              $(this).find('a').each(function(i) {this.i = i+1}).hover(function() {this.parentNode.className = 'rate rate'+this.i; }, function() {this.parentNode.className = 'rate'}).click(function() {this.parentNode.innerHTML = ''})
          })
}

function copyToClipboard(maintext)

 {

 maintext = String(maintext)

 if (window.clipboardData)  {

   window.clipboardData.setData("Text", maintext);
 }
  else if (window.netscape)

   {

    try

     {

     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

     var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].

      getService(Components.interfaces.nsIClipboardHelper);

      gClipboardHelper.copyString(maintext);

     }

   catch(err)

     {

      /*alert ("Clipboard copying error: " + err);*/ return false

     }

   } else {
     return (false)
 }

  return true;

 }


function copy_link(o) {
     if (!copyToClipboard(o.href)) {
         jQuery('<span class="clip r">'+ o.href+'</span>').insertBefore(o)
         o.parentNode.removeChild(o);
     }
}

jQuery.fn.Sel = function (s, opts) {
    var hide_sel = function () {
        jQuery('span.sel2').removeClass('sel2');
    };

    opts = jQuery.extend({refresh: 0}, opts || {})
    this.each(function () {
        if (this.init && !opts.refresh) return (true);

        if (opts.refresh) jQuery(this).prev().remove();

        var index = this.selectedIndex, o = this, s0 = jQuery(this),
            sel = jQuery('<span class="sel3 sel2"><i>' + this.options[index].text + '</i><b/></span>').css('width',s0.css('width')) ,
            open_sel = function (e) {
                hide_sel();
                sel.addClass('sel2');
                jQuery('body').one('click.sel', hide_sel);
                return (false)
            };
        s0.hide().before(sel).find('option')
            .each(function (i) {
                sel.find('b').append('<a' + ((i == index) ? ' class="s"' : '') + ' i="' + i + '">' + o.options[i].text + '</a>')
            })
            .change(function () {
                if (!sel.hasClass('sel2')) sel.find('i').text(o.options[o.selectedIndex].text)
            });

        sel
            .on('click', 'i', open_sel)
            .on('click', 'a',function () {
                sel.find('a').removeClass('s');
                this.className = 's';
                sel.find('i').html(this.innerHTML);
                sel.removeClass('sel2').next().prop('selectedIndex', this.getAttribute('i')).change();
            }).removeClass('sel2');


        if (this.id) {
            jQuery('label[for=' + this.id + ']').click(open_sel);
        } else if (tag(this.parentNode, 'label')) {
            sel.parent().click(open_sel);
            sel.click(false)
        }

        this.init = true;
    })
};

function setCheckBox(fromField, toField, value, frm, linkedField) {
  var form = (typeof(frm) == "string") ? $(frm) : frm;
  if (!form && typeof(frm) == "string") form = document.forms[frm];
  if (!form) form = document.forms[document.forms.length - 1];
  var from_field = form[fromField];
  if (from_field) {
    from_field.checked = value;
    if (value) from_field.setAttribute("checked", value);
    else from_field.removeAttribute("checked");
  }
  //alert(form[fromField].checked);
  var to_field = form[toField];
  if (to_field)
    to_field.value = value;
  if (linkedField != null) {
    if (value) form[linkedField].removeAttribute("disabled");
    else form[linkedField].setAttribute("disabled", "true");
    //	form[linkedField].disabled = !value;
  }
}

function getFalse(e) {
  var e = window.event ? window.event : (e == null) ? null : e;
  if (e != null) {
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
  }
  return false;
}

jQuery(function($) {
	$('form .label')
		.focus(function() {if (this.value == this.defaultValue) this.value = ''})
		.blur(function() {if (this.value == '') this.value = this.defaultValue})
		
	var m = $('#menu'), itms = $('#menu > li').hover(function() {s.removeClass('s'); this.className = 's'}, function() {this.className = ''; s.addClass('s');}), s = itms.filter('.s'), itms2 = m.find('ul.sm li').hover(function() {s2.removeClass('s2'); this.className = 'hov'}, function() {this.className = ''; s2.addClass('s2'); }), s2 = itms2.filter('.s2');
	
	$('ul.menu2 > li').filter(function() {var sm = this.getElementsByTagName('div'); return (sm.length && this.className != 'f' && this.className != 's') }).hover(function() {this.className = 'hov'}, function() {this.className = ''})

    set_rate();
    if (set_text_size != undefined) set_text_size();

    $('.new_select').Sel();	
});




// yandex.metrika
jQuery(function($) {
  var counterId = 324973;
  var yamVisitsToday = $("#yamVisitsToday");
  var yamVisitorsToday = $("#yamVisitorsToday");
  var yamViewsToday = $("#yamViewsToday");

  var yamVisitsMonth = $("#yamVisitsMonth");
  var yamVisitorsMonth = $("#yamVisitorsMonth");
  var yamViewsMonth = $("#yamViewsMonth");


    var apiUrl = $("base").attr("href") + "sys/yam.htm?service=stat/traffic/summary.json&id=" + counterId;

  function formatDate(d){
    function pad(n){return n<10 ? '0'+n : n}
    return d.getUTCFullYear().toString()
        + pad(d.getUTCMonth()+1).toString()
        + pad(d.getUTCDate()).toString()
  }

  function daysBefore(days) {
    var today = new Date();
    if (days != 0) {
      today.setDate(today.getDate() - days);
    }
    return formatDate(today);
  }

  var today = daysBefore(0);
  var monthBefore = daysBefore(30);
  var queryForDay = apiUrl + "&group=month&date1=" + today + "&date2=" + today;
  var queryForMonth = apiUrl + "&group=month&date1=" + monthBefore + "&date2=" + today;

  $.ajax({dataType: "json", url: queryForDay}).done(function(data){
    try {
      yamVisitsToday.text(data.totals.visits);
      yamVisitorsToday.text(data.totals.visitors);
      yamViewsToday.text(data.totals.page_views);
    } catch (e) {}
  });

  $.ajax({dataType: "json", url: queryForMonth}).done(function(data){
    try {
      yamVisitsMonth.text(data.totals.visits);
      yamVisitorsMonth.text(data.totals.visitors);
      yamViewsMonth.text(data.totals.page_views);
    } catch (e) {}
  });
});



var subClassificationsOf = {}; // заполняется на странице поиска

function createClassificationsSelect(parentClassificationId, list, container, selectById) {
    var $ = jQuery;
    var subClassifications = subClassificationsOf[parentClassificationId];
    if (subClassifications == null) return null;

    var $select = $("<select></select>");
    var usedCodes = {};
    for (var i = 0; i < subClassifications.length; i++) {
        var subClassification = subClassifications[i];
        if (usedCodes[subClassification.code] === true) continue;

        var $option = $("<option data-code='"+ subClassification.code + "'></option>");
        $option.val(selectById ? subClassification.sxid : subClassification.code);
        $option.text(subClassification.text);
        $option.appendTo($select);

        usedCodes[subClassification.code] = true;
    }

    $select.appendTo(container).hide().fadeIn(500);

    $select.change(function(){
        var $this = $(this);
        $this.nextAll('select').remove();
        createClassificationsSelect(selectById ? this.options[this.selectedIndex].getAttribute('data-code') : $this.val(), list, container, selectById);
    });

    $select.change();

    return $select;
}

function appendClassificationFilter(button) {
    var $ = jQuery;
    var $button = $(button);
    var $tr = $button.parent().parent();
    var $selected = $(".selected", $tr);
    var $select = $("select", $tr).last();
    var val = $select.val();
    var text = $('option[value="' + val + '"]').text();
   var attrName = $button.attr("name");
    if (!attrName) {
      attrName = 'classification';
    }

    $("a[value='"+val+"']", $selected).remove();
    $("<a class='s search-selected-item'></a>")
        .attr('value', val)
        .text(text)

        .click(function(){
            $(this).remove();
            updateClassificationFilter(attrName);
        }).appendTo($selected);
    updateClassificationFilter(attrName)
}

function updateClassificationFilter(attrName) {
    var selected = [];
    if (!attrName) {
      attrName = 'classification';
    }
    $(".form a.s").map(function(){
        selected.push($(this).prop("value"));
    });
    var curName = 'value('+attrName+')';
    $("input[name='"+ curName + "']").val(
        selected.join(',')
    );
}

function manageSpoiler(obj, picOff, picOn) {
    var $ = jQuery;
  if (!obj) return;
//	var pObj=obj.parentNode;
//	if (!pObj) return;
  var ddTextBody = getNextSiblingTag(obj);
  if (!ddTextBody) return;

  if (typeof(picOff) == "undefined" || picOff == null || picOff == "") picOff = "images/ogv_to12/ico/login-a.gif";
  if (typeof(picOn) == "undefined" || picOn == null || picOn == "") picOn = "images/ogv_to12/ico/login-a2.gif";
  var isClosed = (ddTextBody.style.display == "none");
  if (isClosed) {
    //obj.style.background = "transparent url(" + picOn + ") no-repeat right center";
    $(obj).parent().addClass('open')
    ddTextBody.style.display = "block";
  }
  else {
    //obj.style.background = "transparent url(" + picOff + ") no-repeat right center";
    $(obj).parent().removeClass('open')
    ddTextBody.style.display = "none";
  }
}

function getPrevSiblingTag(obj, depth) {
    return getSiblingTag(obj, depth, false);
}
function getNextSiblingTag(obj, depth) {
    return getSiblingTag(obj, depth, true);
}
function getSiblingTag(obj, depth, mode) { // depth -  show the number of object to find in hierarchy
  var d = (depth != null && typeof(depth) != "undefined") ? parseInt(depth) : 0;
  if (isNaN(d)) d = 0;
  if (d < 0) d = 0;
  var tmpObj = obj;
  while (tmpObj) {
    tmpObj = (mode)?tmpObj.nextSibling:tmpObj.previousSibling;
    if (tmpObj && tmpObj.tagName) {
      if (d == 0) {
        return tmpObj;
      }
      d = d - 1;
    }
  }
  return null;
}

function url2(url, target) {
    if (target == '_self') {
         document.location.href = url
    }  else {
         if (!target) target = '_blank'
         window.open(url, target)
    }
}

function recaptcha(img) {
  var d = new Date();
  img.src = "jcaptcha?" + d.getTime();
}