function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var amplitude = -1;
var count = 0;
var dir = 1;
var process = false;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') > 0);
var ie6 = (navigator.userAgent.toLowerCase().indexOf('msie 6.0') > 0);
var counts = new Array(0,20,10,5);

function la() {
	var string = document.getElementById('pre'), f, header = document.getElementById('hb');
	process = true;
	if(amplitude == -1) amplitude = 3;
	if(amplitude > 0) {
		if(dir > 0) { 
		    dir = -1; 
			string.style.left = -amplitude + 'px'; 
			if(safari) header.style.left = -amplitude + 'px'; 
		} else {
			dir = 1;
			string.style.left = amplitude + 'px';
			if(safari) header.style.left = amplitude + 'px'; 
			if(count > counts[amplitude]) {
				count = 0;
				amplitude -= 1;
			} else count++;
		}
		setTimeout('la()',16);
	} else {
		string.style.left = '0px';
		if(safari) header.style.left = '0px'; 
		process = false;
		amplitude = -1;
	}
}

var heightProcess = false;
var heightSpeed = 0;
var steps = 40;
var newHeight = 0;

function changeHeight(height) {
	var ajaxBox = document.getElementById('ajax');
	if(ajaxBox.controlHeight == null) ajaxBox.controlHeight = ajaxBox.offsetHeight - 95;
	newHeight = height - 95;
	heightSpeed = (newHeight - ajaxBox.controlHeight) / steps;
	if(!heightProcess) processHeight();
	return false;
}

function isNear(num1,num2,eps) {
	if(Math.abs(num1 - num2) < eps) return true; else return false;
}

function processHeight() {
	var ajaxBox = document.getElementById('ajax');
	heightProcess = true;
	var next;
	if(!isNear(newHeight,ajaxBox.controlHeight,heightSpeed/2)) {
		ajaxBox.controlHeight += heightSpeed;
		ajaxBox.style.height = ajaxBox.controlHeight + 'px';
		next = true;
	} else {
		ajaxBox.controlHeight = newHeight;
		ajaxBox.style.height = ajaxBox.controlHeight + 'px';
		next = false;
	}
	if(next) setTimeout('processHeight()',25);
	else heightProcess = false;
}

function theShow() {
	var ajaxObj = document.getElementById('ajax');
	ajaxObj.style.height = (ajaxObj.offsetHeight - 95) + 'px';
	ajaxObj.innerHTML = '<div class="loader"></div>';
	setTimeout('theShowContinue()',1000);
	return false;
}

function theShowContinue() {
	var ajaxObj = document.getElementById('ajax');
	ajaxObj.innerHTML = '<p align="center"><img src="images/content/blog01.jpg" width="800" height="532" alt="" /></p><p align="center"><img src="images/content/blog02.jpg" width="800" height="532" alt="" /></p><p align="center"><img src="images/content/blog03.jpg" width="800" height="613" alt="" /></p>';
	changeHeight(ajaxObj.scrollHeight);
}

function switchPhoto() {
	
	var args = switchPhoto.arguments;
	var i,yes = false;
	var photo = args[0].parentNode.parentNode.getElementsByTagName('IMG')[1];
	if(args.length > 2) {
		for(i=1;i<args.length;i++) {
			if(photo.src.indexOf(args[i]) >= 0) {
				if(i + 1 < args.length) {
					photo.src = args[i + 1];
					return false;
				}
			}
		}
		photo.src = args[1];
	}
	
	return false;
}

function closePopup() {
	document.getElementById('cover').style.display = 'none';
	document.getElementById('popup').style.display = 'none';
	return false;
}

window.onresize = function() {
	var cover = document.getElementById('cover');
	var popup = document.getElementById('popup');
	if(popup.style.display == 'block') {
		if(cover.offsetWidth - popup.offsetWidth > 0) popup.style.left = ((cover.offsetWidth - popup.offsetWidth) / 2) + 'px';
		if(cover.offsetHeight - popup.offsetHeight > 0) popup.style.top = ((cover.offsetHeight - popup.offsetHeight) / 2) + 'px';
	}
}

function showPersonInfo(name) {
	/* функция аяксом подгружает данные о пользователе, потом наверное вделаю раздвижение и прелоадер */
	var cover = document.getElementById('cover');
	var popup = document.getElementById('popup');
	cover.style.display = 'block';
	popup.style.display = 'block';
	popup.style.left = ((cover.offsetWidth - popup.offsetWidth) / 2) + 'px';
	popup.style.top = ((cover.offsetHeight - popup.offsetHeight) / 2) + 'px';
	document.getElementById('popup-body').getElementsByTagName('H2')[0].innerHTML = name;
	return false;
}

function showVacancyForm() {
	/* функция аяксом подгружает данные для */
	var cover = document.getElementById('cover');
	var popup = document.getElementById('popup');
	cover.style.display = 'block';
	popup.style.display = 'block';
	document.getElementById('popup-body').innerHTML = '<h2>Тут информация по вакансиям</h2><p>Пишем всякую <a href="#">фигню</a></p>';
	popup.style.left = ((cover.offsetWidth - popup.offsetWidth) / 2) + 'px';
	popup.style.top = ((cover.offsetHeight - popup.offsetHeight) / 2) + 'px';
	return false;
}

function picLeft(linkObj) {
	linkObj.blur();
	var picBox = document.getElementById('thr-pics');
	if(picBox.scrollTop - 140 < 0) picBox.scrollTop = picBox.scrollHeight - 140;
	else picBox.scrollTop -= 140;
	return false;
}

function picRight(linkObj) {
	linkObj.blur();
	var picBox = document.getElementById('thr-pics');
	if(picBox.scrollTop + 140 > picBox.scrollHeight - 140) picBox.scrollTop = 0;
	else picBox.scrollTop += 140;
	return false;
}