function browser(field_name, current_url, type, win) {
	tinyMCE.selectedInstance.windowManager.open({
		file : "../../files/browser.php?R=" + type + "&X=" + field_name,
		width : 600,
		height : 400,
		inline : 0
	}, {
		dialog : win
	});
}

function preview(what, w, h, s) {
	if (!what) return;
	if (typeof(what) === "object" && what.href) what = what.href;
	if (!w) w = 600;
	if (!h) h = 400;
	s = s ? 1 : 0;
	scr_w = screen.width;
	scr_h = screen.height;
	l = (scr_w - w) / 2;
	t = (scr_h - h) / 2;
	popup = window.open(what, "window_id", "width=" + w + "px,height=" + h + "px,left=" + l + "px,top=" + t + "px,scrollbars=" + s + ",location=0,toolbar=0,resizable=1,menubar=0,status=0,dependent=1");
	popup.focus();
	return false;
}

function load_TinyMCE(id) {
	if (!id) id = "html";
	if (!window.mce) {
		tinyMCE.init({
			plugins : "safari,advimage,advlink,media,table,save,contextmenu,paste,fullscreen,autosave,searchreplace,style",
			theme_advanced_buttons1 : "save,fullscreen,code,|,undo,redo,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,image,media,|,bold,italic,underline,strikethrough,sub,sup,|,forecolor,backcolor,removeformat",
			theme_advanced_buttons2 : "formatselect,fontsizeselect,styleprops,|,table,|,row_before,row_after,delete_row,|,col_before,col_after,delete_col,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,blockquote,hr",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			accessibility_warnings : false,
			relative_urls : false,
			valid_elements : "*[*],noindex,script[src|type]",
			mode : "textareas",
			theme : "advanced",
			editor_selector: "TinyMCE",
			language : "ru",
			file_browser_callback : "browser",
			content_css : "/SiteNN/TinyMCE/content.css",
			fix_table_elements : 0,
			custom_elements : "noindex,script[src|type]"
		});
		window.mce = id;
	}
}

function load_Calendar(id, time) {
	Calendar.setup({ inputField: id, ifFormat: time ? "%d.%m.%Y %H:%M" : "%d.%m.%Y", showsTime: time ? true : false, button: id + "_control", singleClick: true, step: 1 });
}

function _m_a_i_l_t_o(u, d, e, t) {
	if (!e) return;
	if (!t) return;
	var m = "m" + "a" + "i" + "l" + "t" + "o";
	switch (e.type) {
		case "mouseover":
			window.status = m  + ":" + u + "@" + d;
			t.href		= m  + ":" + u + "@" + d;
			return true;
			break;
		case "mouseout":
			window.status = "";
			t.href		= "";
			return true;
			break;
		case "click":
			top.location.href = m  + ":" + u + "@" + d;
			return false;
			break;
	}
}

function move_up(i) {
	var f = document.getElementById("theForm");
	if (!f) return;
	var t1 = f['xtitle[' + (i - 0) + ']'];
	var t2 = f['xtitle[' + (i - 1) + ']'];
	var n1 = f['xorder[' + (i - 0) + ']'];
	var n2 = f['xorder[' + (i - 1) + ']'];
	if (!t1 || !t2 || !n1 || !n2) return;
	var t;
	t = t1.value;
	t1.value = t2.value;
	t2.value = t;
	var n;
	n = n1.value;
	n1.value = n2.value;
	n2.value = n;
}

function move_down(i) {
	var f = document.getElementById("theForm");
	if (!f) return;
	var t1 = f['title[' + (i + 0) + ']'];
	var t2 = f['title[' + (i + 1) + ']'];
	var n1 = f['order[' + (i + 0) + ']'];
	var n2 = f['order[' + (i + 1) + ']'];
	if (!t1 || !t2 || !n1 || !n2) return;
	var t;
	t = t1.value;
	t1.value = t2.value;
	t2.value = t;
	var n;
	n = n1.value;
	n1.value = n2.value;
	n2.value = n;
}

function loginFormSubmit() {
	document.getElementById("loginForm").submit();
}

function searchFormSubmit() {
	document.getElementById("searchForm").submit();
}

function display_flash(src, width, height, a) {
	if (!window.flash_id) window.flash_id = 1;
	var isIE  = !!(navigator.appVersion.indexOf("MSIE") != -1);
	var isWin = !!(navigator.appVersion.toLowerCase().indexOf("win") != -1);
	var isOpera = !!(navigator.userAgent.indexOf("Opera") != -1);
	var id = window.flash_id ++;
	var r = "";
	if (!a) a = {};
	if (!a.id) a.id = "flash_" + id;
	if (!a.version) a.version = 9;
	if (!a.align) a.align = "middle";
	if (!a.access) a.access = "sameDomain";
	if (!a.quality) a.quality = "high";
	if (!a.background) a.background = "#ffffff";
	if (!a.wmode) a.wmode = "transparent";
	if (!a.scale) a.scale = "noscale";
	if (!a.play) a.play = "true";
	if (!a.loop) a.loop = "true";
	if (!a.menu) a.menu = "true";
	if (!a.salign) a.salign = "";
	if (!a.devicefont) a.devicefont = "false";
	if (!a.fullscreen) a.fullscreen = "false";
	if (isIE && isWin && !isOpera) {
		r += ""
		 + "<object"
		 + " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\""
		 + " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + a.version + ",0,0,0\""
		 + " width=\"" + width + "\""
		 + " height=\"" + height + "\""
		 + " align=\"" + a.align + "\""
		 + " id=\"" + a.id + "\""
		 + " name=\"" + a.id + "\""
		 + ">"
		 + "<param name=\"movie\" value=\"" + src + "\" />"
		 + "<param name=\"quality\" value=\"" + a.quality + "\" />"
		 + "<param name=\"bgcolor\" value=\"" + a.background + "\" />"
		 + "<param name=\"allowScriptAccess\" value=\"" + a.access + "\" />"
		 + "<param name=\"wmode\" value=\"" + a.wmode + "\" />"
		 + "<param name=\"scale\" value=\"" + a.scale + "\" />"
		 + "<param name=\"play\" value=\"" + a.play + "\" />"
		 + "<param name=\"loop\" value=\"" + a.loop + "\" />"
		 + "<param name=\"menu\" value=\"" + a.menu + "\" />"
		 + "<param name=\"salign\" value=\"" + a.salign + "\" />"
		 + "<param name=\"devicefont\" value=\"" + a.devicefont + "\" />"
		 + "<param name=\"allowFullScreen\" value=\"" + a.fullscreen + "\" />"
		 + (a.flashvars ? "<param name=\"flashvars\" value=\"" + a.flashvars + "\" />" : "")
		 + "</object>"
		;
	} else {
		r += "<embed"
		 + " src=\"" + src + "\""
		 + " width=\"" + width + "\""
		 + " height=\"" + height + "\""
		 + " align=\"" + a.align + "\""
		 + " name=\"" + a.id + "\""
		 + " quality=\"" + a.quality + "\""
		 + " bgcolor=\"" + a.background + "\""
		 + " allowScriptAccess=\"" + a.access + "\""
		 + " wmode=\"" + a.wmode + "\""
		 + " scale=\"" + a.scale + "\""
		 + " play=\"" + a.play + "\""
		 + " loop=\"" + a.loop + "\""
		 + " menu=\"" + a.menu + "\""
		 + " salign=\"" + a.salign + "\""
		 + " devicefont=\"" + a.devicefont + "\""
		 + " allowFullScreen=\"" + a.fullscreen + "\""
		 + " type=\"application/x-shockwave-flash\""
		 + " pluginspage=\"http://www.macromedia.com/go/getflashplayer\""
		 + (a.flashvars ? " flashvars=\"" + a.flashvars + "\"" : "")
		 + "/>"
		;
	}
	return r;
}

function flash_version() {
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins['Shockwave Flash 2.0']) {
			return parseInt(navigator.plugins['Shockwave Flash 2.0'].description.split(" ")[2]);
		} else if (navigator.plugins['Shockwave Flash']) {
			return parseInt(navigator.plugins['Shockwave Flash'].description.split(" ")[2]);
		}
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) {
		return 4;
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) {
		return 3;
	} else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) {
		return 2;
	} else if ((navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.toLowerCase().indexOf("win") != -1) && !(navigator.userAgent.indexOf("Opera") != -1)) {
		try {
			return parseInt(((new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")).GetVariable("$version")).split(" ")[1]);
		} catch (e) { }
		try {
			return (new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6")) ? 6 : 0;
		} catch (e) { }
		try {
			return parseInt(((new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3")).GetVariable("$version")).split(" ")[1]);
		} catch (e) { }
		try {
			return (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) ? 2 : 0;
		} catch (e) { }
	}
	return 0;
}

function write_flash(src, width, height, a) {
	document.write(display_flash(src, width, height, a));
}

function display_banner(src, width, height, href, param) {
	document.write(display_flash("/SiteNN/images/flash/place-03.swf?path=" + escape(src) + "&href=" + escape(href) + "&width=" + width + "&height=" + height + (param.scale ? "&scale=" + escape(param.scale) : ""), width, height, param));
}

function menu_show(o, n) {
    if (o) {
        var d = menu_find(o, n);
        if (!d) return;
        if (window._menu_object) {
            if (window._menu_object != d) {
                window._menu_object.className = window._menu_object.className.replace("show", "hide");
				if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
					if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
					else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
				}
                window._menu_object = null;
            }
        }
        if (window._menu_status) {
            window.clearTimeout(window._menu_status);
            window._menu_status = null;
        }
        d.className = d.className.replace("hide", "show");
		if (n) {
			if (d.parentNode.className && d.parentNode.className.indexOf("active") < 0) d.parentNode.className += " active";
			else if (!d.parentNode.className) d.parentNode.className = "active";
		}
        window._menu_object = d;
    }
}

function menu_hide(o, n) {
    if (o) {
        var d = menu_find(o, n);
        if (!d) return;
        if (window._menu_object) {
            if (window._menu_object != d) {
                window._menu_object.className = window._menu_object.className.replace("show", "hide");
				if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
					if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
					else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
				}
                window._menu_object = null;
            }
        }
        window._menu_status = window.setTimeout("menu_hide(" + (n ? "null, true" : "") + ")", 1000);
        window._menu_object = d;
    } else {
        if (window._menu_object) {
            window._menu_object.className = window._menu_object.className.replace("show", "hide");
			if (n) if (window._menu_object.parentNode.className && window._menu_object.parentNode.className.indexOf("active") >= 0) {
				if (window._menu_object.parentNode.className == "active") window._menu_object.parentNode.className = "";
				else window._menu_object.parentNode.className = window._menu_object.parentNode.className.replace(" active", "");
			}
            window._menu_object = null;
        }
        if (window._menu_status) {
            window.clearTimeout(window._menu_status);
            window._menu_status = null;
        }
    }
}

function menu_find(o, n) {
	if (n) {
		var d = o.firstChild;
		while (d) {
			if (d.tagName && d.className && (d.className.indexOf("show") >= 0 || d.className.indexOf("hide") >= 0)) {
				return d;
			}
			d = d.nextSibling;
		}
	} else {
	    var d = null;
	    if (o.tagName == "A") {
			if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) {
				d = o.firstChild;
				while (d && !d.tagName) d = d.nextSibling;
			}
			if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) {
				d = o.nextSibling;
				while (d && !d.tagName) {
					d = d.nextSibling;
				}
			}
	    } else {
    	    d = o;
	    }
		if (!d || !d.tagName || (d.tagName != "DIV" && d.tagName != "TABLE" && d.tagName != "P")) return;
		else return d;
	}
}

function flash_show() {
	if (window.movies && window.movies.length) {
		for (var i = 0; i < window.movies.length; i ++) window.movies[i].style.display = "inline";
	}
}

function flash_hide() {
	if (!window.movies) {
		window.movies = [];
		var list;
		list = document.getElementsByTagName("embed");
		if (list) for (var i = 0; i < list.length; i ++) if (list[i] && list[i].style && list[i].style.display != "none") window.movies[window.movies.length] = list[i];
		list = document.getElementsByTagName("object");
		if (list) for (var i = 0; i < list.length; i ++) if (list[i] && list[i].style && list[i].style.display != "none") window.movies[window.movies.length] = list[i];
	}
	if (window.movies && window.movies.length) {
		for (var i = 0; i < window.movies.length; i ++) window.movies[i].style.display = "none";
	}
}

function deleteCart(n) {
	if (!confirm("Удалить товар из корзины?")) return;
	var form = document.getElementById('theForm');
	form['qq[' + n + ']'].value = 0;
	form.submit();
}

function vote(href, o) {
    var v = "";
    if (typeof(o) === "object") {
        if (o.value) v = o.value;
        if (o.attributes && o.attributes['x-value']) v = o.attributes['x-value'].value;
    } else if (o) {
        v = o;
    }
    if (!v) return false;
    v = encodeURIComponent(v);
    if (typeof(jQuery) !== "undefined") {
        jQuery.post(
            href.indexOf("?") < 0 ? href + "?t=jquery&vote=" + v : href + "&t=jquery&vote=" + v,
            { },
            function (result) {
                var x = document.getElementById("poll");
                if (x) {
                    x.innerHTML = result.HTML;
                } else {
                    location.href = href.indexOf("?") < 0 ? href + "?vote=" + v : href + "&vote=" + v;
                }
            }, "json"
        );
    } else {
        location.href = href.indexOf("?") < 0 ? href + "?vote=" + v : href + "&vote=" + v;
    }
    return false;
}

function myInitFancy() {
	if (typeof($) === "undefined") return;
	if (typeof($.fancybox) === "undefined") return;
	if (typeof(window._myInitFancy) !== "undefined") return;
	window._myInitFancy = true;
	$(function() {
		$("a.fancy").attr("rel", "fancy").fancybox({
			onStart: flash_hide,
			onClosed: flash_show
		});
	});
}

var num=1;
function pryaniki(type, avto)
{
  if(type=="next")
  {
    if(num<8)
      num++;
    else
      num=2;
  }
  else
  {
    if(num>2)
      num--;
    else
      num=8;
  }
  jQuery(".pryaniki").attr({"src":"/images/"+num+".png"});
  if(avto)
    setTimeout("pryaniki('next', true)",5000);
  return false;
}
jQuery(document).ready(function()
{
  pryaniki("next", true);
});
