var show_e;
var show_img;

var flag=0;

var contentid;

function guestflash(name) {
	if(!contentid) {
		var img = document.getElementById('dummyflashimg' + name);
		var span = document.getElementById('dummyflashspan' + name);

		if(img && span) {
			var flashname = img.getAttribute('flashname');
			var width = img.getAttribute('width');
			var height = img.getAttribute('height');

			if(!width) width = img.getAttribute('flashwidth');
			if(!height) height = img.getAttribute('flashheight');

			AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width',width,'height',height,'src',flashname,'quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie',flashname );
		}
	}
}

function setflag(cur, flagname) {
	var status = cur.checked;

	var e = null;

	for(i=1;i<=1000;i++) {
		e = document.getElementById(flagname + i);
		if(!e) break;
		e.checked = status;
	}
}

function setRadio(radio, value) {
	for(var i=0;i<radio.length;i++) {
		if(radio[i].value == value) radio[i].checked = true;
	}
	return 0;
}

function itemTestForm(form) {
	var e = null;
	var res = '';
	var require;
	var mincount;
	var fieldname;

	if(form)
	for(var i=0;i<form.childNodes.length;i++) {
		e = form.childNodes[i];

		if(e.getAttribute) {
			require = e.getAttribute('require');
			mincount = e.getAttribute('mincount');
			fieldname = e.getAttribute('fieldname');

			if(require) {
				if((e.value==0)||(e.value=='')) {
					res = res + 'не заполнено поле ' + require + '\n';
				}
			}

			if(mincount) {
				if((e.value.length<mincount)) {
					res = res + 'неверное количество символов в поле ' + fieldname + '\n';
				}
			}

			res = res + itemTestForm(e);
		}
	}

	return res;
}

function testForm(form) {
	var e = null;
	var res = '';
	var require;
	var mincount;
	var fieldname;

	res = itemTestForm(form);

	if(res) {
		res = 'Не верно заполнены поля:\n' + res;
		alert(res);
		return false;
	}

	return true;
}

function confirmQuery(text, url) {
	if(confirm(text)) location.replace(url);
}

function setSelect(name, value) {
	e = document.getElementById(name);
	for(var i=0;i<e.length;i++) {
		if(e.options[i].value==value) e.selectedIndex = i;
	}
}

function writeFlash(w, h, url) {
	document.write('<object id="flash_obj" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + w + '" height="' + h + '" id="final" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="' + url + '" />');
	document.write('<param name="loop" value="true" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="quality" value="best" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="bgcolor" value="#000000" />');
	document.write('<embed src="' + url + '" loop="true" menu="false" quality="best" scale="noscale" wmode="transparent" bgcolor="#000000" width="' + w + '" height="' + h + '" name="final" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function showFlashWin(x,y,flash,title) {
	if (flag == 1) {
		sw.close();
		flag=0;
	}

	//x = x + 20;
	//y = y + 20;


	eval("sw=window.open('',title,'top=20,left=220,width='+x+',height='+y+',scrollbars=no,resizable=no')");

	sw.document.write("<html><head><title>"+title);
	sw.document.write("</title></head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
	sw.document.write("<center><table width='100%' height='100%' cellspacing=0 cellpadding=0 border=0><tr><td align=center>");
	sw.document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+x+"' height='"+y+"'><param name='movie' value='"+flash+"'><param name='quality' value='high'><embed src='"+flash+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='400' height='240'></embed></object>");
	sw.document.write("</td></tr></table>");
	sw.document.write("</center>");
	sw.document.write("</body></html>");
	sw.document.close();

	sw.focus();
	flag = 1;
}

function showwin(x,y,url) {
	showfoto(x, y, url);
}

var showing_image;
var showing_overlay;
var showing_closebtn;
var showing_image_alpha = 0;
var showing_preloader;
var showing_preloader_div;
var preloaderImagePosition = 0;
var preloaderIntervalID = 0;
var showing_isIE = (navigator.appVersion.indexOf('MSIE') > 0) ? true : false;

function showfoto(x, y, url) {

	if (window.editor && editor.element) return;

	var isIE = (navigator.appVersion.indexOf('MSIE') > 0) ? true : false;
	
	var pagesize = getPageSize();
	
	
	var onclick = function () {
		var i;
		if (window.showing_overlay) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_overlay)	
				document.body.removeChild(showing_overlay);
			}
			showing_overlay = null;
		}
		if (window.showing_preloader_div) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_preloader_div)	
				document.body.removeChild(showing_preloader_div);
			}
			showing_preloader_div = null;
		}
		if (window.showing_closebtn) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_closebtn)	
				document.body.removeChild(showing_closebtn);
			}
			showing_closebtn = null;
		}
		if (window.showing_image) {
			for (i in document.body.childNodes) {
				if (document.body.childNodes.item(i) == showing_image)	
				document.body.removeChild(showing_image);
			}
			
			showing_image = null;
		}
		if (preloaderIntervalID) {
			clearInterval(preloaderIntervalID);
			preloaderIntervalID = 0;
		}
	}
	
	showing_overlay = document.createElement('div');
	showing_overlay.id = 'showfoto-overlay';
	showing_overlay.className = 'fixed';
	showing_overlay.style.width = '100%';
	showing_overlay.style.height = '100%';
	showing_overlay.style.top = '0px';
	showing_overlay.style.left = '0px';
	showing_overlay.style.backgroundColor = '#000000';
	showing_overlay.style.zIndex = '1000';
	showing_overlay.onclick = onclick;
	document.body.appendChild(showing_overlay);
	
	showing_preloader = document.createElement('img');
	showing_preloader.style.display = 'block';
	showing_preloader_div = document.createElement('div');
	showing_preloader_div.className = 'fixed';
	showing_preloader_div.style.zIndex = '1001';
	showing_preloader_div.style.overflow = 'hidden';
	showing_preloader_div.onclick = onclick;
	showing_preloader_div.appendChild(showing_preloader);
	document.body.appendChild(showing_preloader_div);
	
	showing_preloader.onload = function () {
		showing_preloader.onload = null;
		showing_preloader.style.width = showing_preloader.width + 'px';
		showing_preloader.style.height = showing_preloader.height + 'px';
		showing_preloader_div.style.width = showing_preloader.width + 'px';
		showing_preloader_div.style.height = showing_preloader.width + 'px';
		showing_preloader_div.style.top = ((pagesize[3] - showing_preloader.width) / 2) + 'px';
		showing_preloader_div.style.left = ((pagesize[2] - showing_preloader.width) / 2) + 'px';
		
		if (isIE6()) {
			showing_preloader.src = '/img/spacer.gif';
			showing_preloader.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/preloader.png', sizingMethod='scale')";
		}
		
		
		preloaderIntervalID = setInterval('showPreloaderOnTimer('+showing_preloader.width+', '+showing_preloader.height+')', 60);
	}
	showing_preloader.src = 'img/preloader.png';
	
	
	
	if (isIE) {
		showing_overlay.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
	} else {
		showing_overlay.style.opacity = '0.5';
	}
	
	showing_image = document.createElement('img');
	showing_image.onload = function () {
		var imgwidth = showing_image.width;
		var imgheight = showing_image.height;
		
		if (pagesize[2] < showing_image.width + 30 || pagesize[3] < showing_image.height + 30) {
			imgwidth = pagesize[2] - 30;
			imgheight = showing_image.height * imgwidth / showing_image.width;
			if (imgheight > pagesize[3] - 30) {
				imgheight = pagesize[3] - 30;
				imgwidth = showing_image.width * imgheight / showing_image.height;
			}
			showing_image.style.width = Math.round(imgwidth) + 'px';
			showing_image.style.height = Math.round(imgheight) + 'px';
			//alert(showing_image.style.width + ' x ' + showing_image.style.height)
		}
	
		
		showing_image.className = 'fixed';
		showing_image.style.left = (pagesize[2] - imgwidth) / 2 + 'px';
		showing_image.style.top = (pagesize[3] - imgheight) / 2 + 'px';
		showing_image.style.border = '5px solid #FFF';
		showing_image.style.backgroundColor = "#FFF";
		showing_image.style.zIndex = '1001';
		showing_image_alpha = 0;
		document.body.appendChild(showing_image);
		
		
		showing_closebtn = document.createElement('img');
		showing_closebtn.style.width = '30px';
		showing_closebtn.style.height = '30px';
		if (isIE6()) {
			showing_closebtn.src = '/img/spacer.gif';
			showing_closebtn.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/close.png', sizingMethod='scale')";
		} else {
			showing_closebtn.src = '/img/close.png';
		}
		showing_closebtn.className = 'fixed';
		showing_closebtn.style.left = ((pagesize[2] + imgwidth) / 2 - 5) + 'px';
		showing_closebtn.style.top = ((pagesize[3] - imgheight) / 2 - 15) + 'px';
		showing_closebtn.style.cursor = 'pointer';
		showing_closebtn.style.zIndex = '1002';
		document.body.appendChild(showing_closebtn);
		
		
		showing_image.onclick = onclick;
		showing_closebtn.onclick = onclick;
		
		myscroll();
		
		if (isIE) {
			showing_image.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
		} else {
			showing_image.style.opacity = '0';
			showing_closebtn.style.opacity = '0';
		}
		
		showfotoontimer();
		showing_preloader_div.style.display = 'none';
		if (preloaderIntervalID) {
			clearInterval(preloaderIntervalID);
			preloaderIntervalID = 0;
		}
	}
	
	showing_image.src = url;
}

function showPreloaderOnTimer(width, height) {
	preloaderImagePosition += width;
	if (preloaderImagePosition >= height) preloaderImagePosition = 0;
	if (showing_preloader) showing_preloader.style.marginTop = '-' + preloaderImagePosition + 'px';
	
}

function showfotoontimer() {
	showing_image_alpha = showing_image_alpha + 5;
	
	if (showing_isIE) {
		showing_image.style.filter ="progid:DXImageTransform.Microsoft.Alpha(opacity="+showing_image_alpha+")";
	} else {
		showing_image.style.opacity = showing_image_alpha / 100;
		showing_closebtn.style.opacity = showing_image_alpha / 100;
	}
	
	if (showing_image_alpha < 100) {
		setTimeout('showfotoontimer()', 30);
	}
}

function getPageSize() {
	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){ // all but Explorer Mac
	    xScroll = document.body.scrollWidth;
	    yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	    xScroll = document.body.offsetWidth;
	    yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {     // all except Explorer
	    if(document.documentElement.clientWidth){
	         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;
	}     
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
	    pageHeight = windowHeight;
	} else { 
	    pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){     
	    pageWidth = xScroll;          
	} else {
	    pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

var g_isie6 = 0;

function isIE6() {
	if(g_isie6) {
	 	if(g_isie6 == 1) return true;
	 	else if(g_isie6 == 2) return false;
	}
	
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	
	var re = new RegExp('; MSIE 6\.*;', "gim");

	if(b_version.search(re) != -1) {
		g_isie6 = 1;
		return true;
	} else {
		g_isie6 = 2;
		return false;
	}
}

function myscroll() {
	if(isIE6()) {
		var top = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		var left = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
		var m_fixed_elements = getElementsByClass('fixed');
		for(i=0;i<m_fixed_elements.length;i++) {
			var fixedtop = m_fixed_elements[i].getAttribute('fixedtop');
			if(!fixedtop) {
				fixedtop = parseInt(m_fixed_elements[i].style.top);
				if (!fixedtop) fixedtop = 0;
				if (fixedtop == 0) fixedtop = 'zero';
				m_fixed_elements[i].setAttribute('fixedtop', fixedtop);
			}
			if (!fixedtop) fixedtop = 0;
			if (fixedtop == 'zero') fixedtop = 0;
			m_fixed_elements[i].style.top = (fixedtop + top) + 'px';
			
			
			var fixedleft = m_fixed_elements[i].getAttribute('fixedleft');
			if(!fixedleft) {
				fixedleft = parseInt(m_fixed_elements[i].style.left);
				if (!fixedleft) fixedleft = 0;
				if (fixedleft == 0) fixedleft = 'zero';
				m_fixed_elements[i].setAttribute('fixedleft', fixedleft);
			}
			if (!fixedleft) fixedleft = 0;
			if (fixedleft == 'zero') fixedleft = 0;
			m_fixed_elements[i].style.left = (fixedleft + left) + 'px';
		}

	}
}

window.onscroll = myscroll;

function showflash(page,x,y)
{
	eval("sf=window.open(Name=\""+page+"\",\"FLASH\",\"top=20,left=220,width="+x+",height="+y+",scrollbars=no,resizable=no\")")
}

function domenu(id,e,img) {
	if(id == pageid) {
		e = document.getElementById(e);
		img = document.getElementById(img);
		if(e&&img) {
			//show(e,img);
			show_e = e;
			show_img = img;
		} else alert("Ошибка");
	}
	return 0;
}

function showmenu() {
	if(show_e && show_img) show(show_e, show_img);
}

function catalog_bask(zena,count) {
	if(document.getElementById('catalog_count')) catalog_count.innerText = count;
	if(document.getElementById('catalog_zena')) catalog_zena.innerText = zena;
}

var ArrayBaskId = new Array();

function parce_baskinfo() {
	var s = document.getElementById('baskinfo').innerHTML;
	listID = s.split(';');
	for (var i = 0; i < listID.length; i++) {
		if(listID[i] != "") {
			m = listID[i].split(':');
			ArrayBaskId[m[0]] = m[1];
		}
	}
}

function catalog_check(id,e) {
	if(ArrayBaskId[id]!=null) {
		e = document.getElementById(e);
		/*if(e) e.checked = "true";
		else e.checked = "false";*/
		if(e) e.value = ArrayBaskId[id];
	}
}

function catalog_buy(cost,id,e) {
	e = document.getElementById(e);
	//ordertype = document.getElementById(ordertype);

	if(e==null) alert("Ошибка скрипта");

	//check = e.checked;
	colbuy = e.value;
	if(colbuy=="") colbuy = 0;

	location.href='./buy.php?id=' + id + '&colbuy=' + colbuy;
	return;

	if(window.showModalDialog==null) {
		location.href='./?act=buy&page=' + id + '&colbuy=' + colbuy;
		return;
	}

	/*if(document.frames('doframe')) document.frames('doframe').location.href='./?act=buy&frame=1&id=' + id;
	else location.href='./?act=buy&id=' + id;*/

	if(document.getElementById('catalog_count')) count = catalog_count.innerText;
	if(document.getElementById('catalog_zena')) oldzena = catalog_zena.innerText;

	if(zena==null) zena = 0;
	if(count==null) count = 0;

	oldcol = 0;
	if((ArrayBaskId[id]!=null)&&(ArrayBaskId[id]!=0)) {
		oldcol = ArrayBaskId[id];
		if(colbuy==0) {
			count--;
		}
	} else {
		if(colbuy>0) count++;
	}
	ArrayBaskId[id] = colbuy;

	cost = parseInt(zena) * colbuy + parseInt(oldzena) - parseInt(zena) * oldcol;

	catalog_bask(cost,count);

	window.showModalDialog('./?act=buy&frame=1&page=' + id + '&colbuy=' + colbuy, '', 'menubar=no,directories=no,location=no,toolbar=no,scrollbars=no,status=no,resizable=no,height=15,width=350,dialogWidth:350px; dialogHeight:15px');
}

function catalog_col_keypres(id,onewcol,zena,ocol,ordertype) {
	if(event.keyCode==13) catalog_modify(id,onewcol,zena,ocol,ordertype);
	if((event.keyCode<48)||(event.keyCode>57)) event.keyCode = 0;
}

function catalog_newcol_keypres(zena,id,text_buy,ordertype) {
	if(event.keyCode==13) catalog_buy(zena,id,text_buy,ordertype);
	if((event.keyCode<48)||(event.keyCode>57)) event.keyCode = 0;
}

function catalog_modify(id,onewcol,zena,ocol,ordertype) {
	onewcol = document.getElementById(onewcol);
	ocol = document.getElementById(ocol);
	ordertype = document.getElementById(ordertype);

	if((onewcol==null)||(ocol==null)||(ordertype==null)) alert('Ошибка определения ID. \n Ваш браузер не поддрердивает JavaScript');

	if(ordertype.checked) ot = 1;
	else ot = 0;

	newcol = onewcol.value;
	if(newcol=="") newcol = 0;
	oldcol = ocol.value;
	ocol.value = newcol;

	/*var sum = document.all.catalog_sum.innerText;
	var nalcurs = document.all.catalog_nalcurs.innerText;
	var beznalcurs = document.all.catalog_beznalcurs.innerText;
	var nalitogo = document.all.catalog_nalitogo.innerText;
	var beznalitogo = document.all.catalog_beznalitogo.innerText;

	sum = parseInt(sum,10) + zena*(newcol-oldcol);
	nalitogo = parseInt(nalitogo,10) + zena*(newcol-oldcol)*nalcurs;
	beznalitogo = parseInt(beznalitogo,10) + zena*(newcol-oldcol)*beznalcurs;

	document.all.catalog_sum.innerText = sum;
	document.all.catalog_nalitogo.innerText = nalitogo;
	document.all.catalog_beznalitogo.innerText = beznalitogo;

	onewcol.select();

	if(document.all.doframe) document.all.doframe.src='./?act=modify&fast=1&id=' + id + '&center=buy&newcol='+newcol;
	else location.href='./?act=modify&id=' + id + '&center=buy&newcol='+newcol;*/

	location.href='./?act=modify&id=' + id + '&center=buy&newcol='+newcol+'&ordertype='+ot;
}

// Создание массива для хранения ссылок на дочерние окна.
/* Каждый член данного массива будет окном объекта, созданного
ниже с использованием метода createWindow. */
var windows = new Array();

function newWindow(url, wname) {
// Конструктор для окна
/* Данная функция может быть вызвана только функцией
   createWindow, которая приведена ниже. */
var features = "";
if (null != arguments[2])
   features = arguments[2];
return window.open(url, wname, features);
}

function createWindow(url, wname) {
// Добавление окна в семейство окон.
var features = arguments[2] == null ? "" : arguments[2];
windows[wname] = new newWindow(url, wname, features);
windows[wname].focus();
}

function closeWindows() {
// Закрытие всех окон, открытых методом addWindow.
/* Для закрытия окна вызывается его метод close. */
/* Данная функция может быть вызвана в ходе события onunload
   для автоматического закрытия всех открытых окон.  */
for (w in windows)
   if (!windows[w].closed)
	  windows[w].close();
}

window.onunload=closeWindows;

var cur_scrollY=0;

function scrollDown(index) {
	cur = index + 23.67;
	//alert(cur);
	if (cur<=(360)) {
		window.scroll(0,cur);
		y =Math.round(cur);
		var timer = setTimeout('scrollDown('+y+')',20);	
	} else  {
		clearTimeout(timer);
		cur_scrollY = 0;
	}
}

var mHistory = new Array();
mHistory.push('/');
var historyPos = 0;
var is_history = false;

function backHistory() {
	historyPos--;
	is_history = true;
	ajaxgo(mHistory[historyPos]);
}

var splitWidth = 674;
var cur_splitWidth = splitWidth;
function animateSplit() {
	cur_splitWidth = cur_splitWidth+20;
	if (cur_splitWidth>splitWidth) cur_splitWidth = splitWidth;
	document.getElementById('name-split').style.width = cur_splitWidth+'px';
	if (cur_splitWidth != splitWidth) {
		var splitAnimateTimer = setTimeout('animateSplit()',20)	;
	} else {
		clearTimeout(splitAnimateTimer);
	}
}

function startAnimateSplit() {
	/*cur_splitWidth = 0;
	document.getElementById('name-split').style.width = cur_splitWidth+'px';
	animateSplit();*/
}

var etime = 705;

	
var newHeight;
var oldHeight;
var anim_runing = false;
var responseJSText = '';
var cur_index = -1;


function showNewContent(index,newText) {
	if (!anim_runing && cur_index!= index) {
		cur_index = index;
		anim_runing = true;
		$('#nem-cont1').css('margin-left','0px');
		$('#nem-cont2').css('margin-left','0px');
		$('#nem-cont2').html(newText);
		$('#nem-meter2').html(newText);
		
	
		newHeight = $('#nem-meter2').innerHeight();
		
		oldHeight = $('#nem-meter1').innerHeight();
		$("#nem-cont2").animate({height: newHeight+'px'}, etime );
		$("#nem-cont1").animate({height: newHeight+'px'}, etime );
		animateContent();
	} else if (cur_index == index) {
		$('#nem-cont1').fadeOut("fast", function () {
			$('#nem-cont1').fadeIn("fast");
		});
	}
} 
	
	
var cur1X=-670;// = -containerWidth;

var curH = 0;
	
function animateContent() {
	
	cur1X +=Math.round((800/containerWidth)*22500/etime);
	//document.getElementById('name-split').style.width = cur1X+'px';
	if (!cur1X) cur1X = -containerWidth;
	if (cur1X<0) {
		$('#nem-cont').css('margin-left',cur1X+'px');
		x1 = -(cur1X+containerWidth);
		x2 = -(cur1X);
		$('#nem-cont1').css('margin-left',x1+'px');
		$('#nem-cont2').css('margin-left',x2+'px');
		$('#nem-cont2').css('width',containerWidth+'px');
		ns_width = x1;//-Math.round((800/containerWidth)*22500/etime);
		$('#name-split').css('width',-(ns_width)+'px');
		var timer = setTimeout('animateContent()',1);
	} else {
		clearTimeout(timer);
		$('#nem-cont1').html($('#nem-cont2').html());
		$('#nem-cont').css('margin-left','-'+containerWidth+'px');
		$('#nem-cont1').css('margin-left','0px');
		$('#nem-cont2').css('margin-left','0px');
		$('#name-split').css('width','674px');
		cur1X = -containerWidth;
		anim_runing = false;
		jquerySet();
		
	}
}
var currentPageId;
function goto(id) {
	if (id=='scroll') {
		scrollDown(0);
	} else {
		showLoading();
		
		/*var url2 = url;
		for(var i=0;i<10;i++) {
			url2 = url2.replace('_', '.');
			if(url2.search('_')==-1) break;
		}*/
		
		current_loc = '#?pid=' + id;
		location.href = '#?pid=' + id;
		
		
		JsHttpRequest.query(
			'index.php?JsHttpRequest&pid='+id,
			{},
			function(responseJS, responseText) {
				if (responseJS.OK) {
					currentPageId = id;
					//document.getElementById('pagename').innerHTML = responseJS.name;
					document.getElementById('pageimg').src = 'i/pages/p'+responseJS.id+'.gif';
					document.getElementById('container').style.background = 'url(i/bg/b'+responseJS.bgid+'.jpg) repeat center 0px';
//					document.getElementById('center').innerHTML = responseJS.html;
					//responseJSText = responseJS.html;
					if (document.getElementById('path'))
					if (responseJS.path!='') {
						document.getElementById('path').style.display = 'block';
						document.getElementById('path').innerHTML = responseJS.path;
					} else {
						document.getElementById('path').style.display = 'none';
						document.getElementById('path').innerHTML = responseJS.path;
					}
					if (currentPageId<4 || currentPageId>10)
						scrollDown(0);
					if (!is_a) showNewContent(id,responseJS.html);
					else document.getElementById('center').innerHTML = responseJS.html;
					//showNewContent(id,responseJS.html);
					//startAnimateSplit();
					
					//jquerySet();
					hideLoading();
					
					if (!is_history) {
						if (mHistory[historyPos+1] && mHistory[historyPos+1]!='undefined') {
							mHistory[historyPos+1] = '?pid='+id;
							historyPos++;
						} else {
							historyPos++;
							mHistory.push('?pid='+id);
						}
					} else is_history = false;
					if (historyPos == 0) document.getElementById('backHistory').style.display = 'none';
					else document.getElementById('backHistory').style.display = 'block';
				}
			},
			true // true = disable caching
		);
	}
}

function jquerySet() {
	if (is_guest)
		if (document.getElementById('foto-gallery')) {
			$('#nem-cont1 #foto-gallery a').lightBox({txtImage : 'Фото', txtOf : 'из'});
		}
}


function ajaxgo(url) {
	showLoading();

	
	//g_jurnalcounter++;
	//location.href = '#' + g_jurnalcounter;
	var url2 = url;
	/*for(var i=0;i<10;i++) {
		url2 = url2.replace('_', '.');
		if(url2.search('_')==-1) break;
	}*/
	
	current_loc = '#' + url2;
	location.href = '#' + url2;



    JsHttpRequest.query(
        '/index.php',
        { url: url },
        function(responseJS, responseText) {
        	/*if(responseText) {
        		eval(responseText);
				hideLoading();
        		return 0;
        	}*/

            var html = responseJS.OK;
			if(html) {
				//document.getElementById('pagename').innerHTML = responseJS.name;
				document.getElementById('pageimg').src = 'i/pages/p'+responseJS.id+'.gif';
				document.getElementById('container').style.background = 'url(i/bg/b'+responseJS.bgid+'.jpg) repeat center 0px';
				//document.getElementById('center').innerHTML = responseJS.html;
				if (document.getElementById('path'))
				if (responseJS.path!='') {
					document.getElementById('path').style.display = 'block';
					document.getElementById('path').innerHTML = responseJS.path;
				} else {
					document.getElementById('path').style.display = 'none';
					document.getElementById('path').innerHTML = responseJS.path;
				}

				if (!is_a) showNewContent(url,responseJS.html);
				else document.getElementById('center').innerHTML = responseJS.html;
				//startAnimateSplit();
				
				//jquerySet();
				hideLoading();
				
				if (!is_history) {
					if (mHistory[historyPos+1] && mHistory[historyPos+1]!='undefined') {
						mHistory[historyPos+1] = url;
						historyPos++;
					} else {
						historyPos++;
						mHistory.push(url);
					}
				} else is_history = false;
				if (historyPos == 0) document.getElementById('backHistory').style.display = 'none';
				else document.getElementById('backHistory').style.display = 'block';
			}

			/*var place = responseJS.place;
			if(place && place instanceof Object) {
				for (var key in place) {
					var val = place[key];
					if(val instanceof Function) continue;
					document.getElementById(key).innerHTML = val;
					hideLoading();
				}
			}*/

			/*var ajaxeval = responseJS.ajaxeval;
			if(ajaxeval && ajaxeval instanceof Object) {
				for (var key in ajaxeval) {
					var val = ajaxeval[key];
					if(val instanceof Function) continue;
					eval(val);
					hideLoading();
				}
			}*/
        },
        true
    );
}


// переход по якорю
function goToHash(hash, ajax) {
	if(hash.search('#')!=-1) {
		var url = new String(hash).replace('#','');
		/*url = url.replace('.htm', '');
		for(var i=0;i<10;i++) {
			url = url.replace('\.', '_');
			if(url.search('.')==-1) break;
		}
		url += '.htm';*/
		
		if(ajax) ajaxgo(url);
		else document.location.replace(url);
	}
}

var current_loc = location.hash;
function checkLocation () {
	//alert('"'+document.location.hash+'" - "'+current_loc+'"');

	var hash = document.location.hash;    
    if (hash != current_loc) {
		if (hash=='') hash='#';
        current_loc = hash;
        goToHash(hash, true);
    }
    setTimeout("checkLocation();", 500);
}
// запускаем проверку раз в половину секунды
setTimeout("checkLocation();", 500);

if(document.location.hash && document.location.hash.indexOf('#') > -1) {
	goToHash(document.location.hash, false);
}










function showLoading() {
	offsetLeft = document.getElementById('header').offsetLeft;
	
	document.getElementById('opacity').style.left = offsetLeft+'px';
	document.getElementById('opacity').style.width = '980px';
	
	
	document.getElementById('opacity').style.backgroundColor = '#FFF';
	document.getElementById('opacity').style.opacity = 0.9;
	document.getElementById('opacity').style.filter = 'alpha(opacity=90)';
	brHeight = getPageHeight()-393;
	document.getElementById('opacity').style.height = brHeight+'px';
	document.getElementById('opacity').style.marginTop = '393px';
	document.getElementById('opacity').style.display='block';
	document.getElementById('loading').style.marginLeft = offsetLeft+((document.getElementById('opacity').offsetWidth/2)-30)+'px';
	fscroll = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	winHeight = self.innerHeight || ( document.documentElement && document.documentElement.clientHeight ) || document.body.clientHeight;
	margin = (winHeight+fscroll-395)/2+380;
	document.getElementById('loading').style.marginTop = margin + 'px';
	//document.getElementById('loading').style.display='block';
}

function hideLoading() {
	document.getElementById('opacity').style.display='none';
	document.getElementById('loading').style.display='none';
}

function getPageHeight() {
			var yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowHeight = document.body.clientHeight;
			}	
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			var ua = navigator.userAgent.toLowerCase();
			var isOpera = (ua.indexOf('opera')  > -1);
			if (isOpera) return document.body.scrollHeight+window.pageYOffset;
			return pageHeight;
};

var curOpacity = 0;
function showmainpage() {
	document.getElementById('opacity').style.display='block';
	opacityIn();
}

function opacityIn() {
	document.getElementById('opacity').style.backgroundColor = '#000';
	winHeight = self.innerHeight || ( document.documentElement && document.documentElement.clientHeight ) || document.body.clientHeight;
	document.getElementById('opacity').style.height = winHeight+'px';
	document.getElementById('opacity').style.opacity = curOpacity/100;
	document.getElementById('opacity').style.filter = 'alpha(opacity='+curOpacity+')';
	curOpacity = curOpacity+20;
	if (curOpacity <= 100) setTimeout('opacityIn()',15);
	else {
		opacityOut();
		document.getElementById('flashintro').style.display = 'none';
		document.getElementById('footer').style.display = 'block';
		document.getElementById('container').style.display = 'block';
		document.getElementById('footer_guard').style.display = 'block';
	}
}

function opacityOut() {
	document.getElementById('opacity').style.opacity = curOpacity/100;
	document.getElementById('opacity').style.filter = 'alpha(opacity='+curOpacity+')';
	curOpacity = curOpacity-20;
	if (curOpacity >= 0) setTimeout('opacityOut()',15);
	else {
		document.getElementById('opacity').style.display='none';
	}
}

function opacityIn2() {
	document.getElementById('opacity').style.backgroundColor = '#000';
	document.getElementById('opacity').style.opacity = curOpacity/100;
	document.getElementById('opacity').style.filter = 'alpha(opacity='+curOpacity+')';
	curOpacity = curOpacity+20;
	if (curOpacity <= 100) setTimeout('opacityIn2()',15);
	else {
		opacityOut();
		document.getElementById('flashintro').style.display = 'block';
		document.getElementById('footer').style.display = 'none';
		document.getElementById('container').style.display = 'none';
		document.getElementById('footer_guard').style.display = 'none';
	}
}

function opacityOut2() {
	document.getElementById('opacity').style.opacity = curOpacity/100;
	document.getElementById('opacity').style.filter = 'alpha(opacity='+curOpacity+')';
	curOpacity = curOpacity-20;
	if (curOpacity >= 0) setTimeout('opacityOut2()',15);
	else {
		document.getElementById('opacity').style.display='none';		
	}
}

function showtitul() {
	document.getElementById('opacity').style.display='block';
	opacityIn2();
}

function getMovie(movie) {
    var M$ =  navigator.appName.indexOf("Microsoft")!=-1
    return (M$ ? window : document)[movie]
}

function stopMusic() {
	getMovie("player").SetVariable("_root.on_stop","false");
	//getMovie("head").SetVariable("_root.on_play","true");	
	getMovie("head").sendFromJS('off');
}

function startMusic() {
	getMovie("player").SetVariable("_root.on_play","true");
	//getMovie("head").SetVariable("_root.on_play","false");	
	getMovie("head").sendFromJS('on');
}

function scrollToTop() {
	window.scroll(0,0);	
}


