function example(a,b)
{
		document.getElementById(a).style.display = 'none';
		document.getElementById(b).style.display = 'inline';
		document.getElementById('in').value= '';
}
function add(a,b)
{
		document.getElementById(a).style.display = 'none';
		document.getElementById(b).style.display = 'inline';
}
function getElement(aID){
		var rv = (document.getElementById) ? document.getElementById(aID) : document.all[aID];
		return rv;
}
function badd(pid,y2,x2) {
		f=getElement('pform')
		f.pid.value=pid;
		f.y2.value=y2;
		f.x2.value=x2;
		f.sbm.click()
		return false;
}
function badd(pid,y2,x2) {
		f=getElement('pform')
		f.pid.value=pid;
		f.y2.value=y2;
		f.x2.value=x2;
		f.sbm.click()
		return false;
}
/* Создание нового объекта XMLHttpRequest для общения с Web-сервером */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callServer() {
  // Получить данные из web-формы
  var name = document.getElementById('name').value;
  var question = document.getElementById('question').value;
  var phone = document.getElementById('phone').value;
  var email = document.getElementById('email').value;
  var header = document.getElementById('tema').value;
  var guest = document.getElementById('guest').value;


  // Продолжать только если есть значения всех полей
  if ((name == null) || (name == "")) return document.getElementById("quest_1").style.display = 'inline';
  if ((email == null) || (email == "")) return document.getElementById("quest_1").style.display = 'inline';
   if ((question == null) || (question == "")) return document.getElementById("quest_1").style.display = 'inline';

  // Создать URL для подключения
  var url = "608?question=" +  question + "&phone=" + phone + "&email=" + email + "&header=" + header + "&name=" + name + "&guest=" + guest;

  // Открыть соединение с сервером
  xmlHttp.open("GET", url, true);

  // Установить функцию для сервера, которая выполнится после его ответа
  xmlHttp.onreadystatechange = updatePage;

  // SПередать запрос
  xmlHttp.send(null);
}

function updatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("quest").style.display = 'inline';
    document.getElementById("quest_1").style.display = 'none';
  }
}

var Fat = {
	make_hex : function (r,g,b)
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function (dur)
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++)
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,dur,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to)
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF55";
		if (!to) to = this.get_bgcolor(id);

		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;

		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);

		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);

		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);

			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame;
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

addLoadEvent(function ()  {
	Fat.fade_all();
});


var speed_ms = 10;
var speed_px = 11;
var width_max = 180;
var width_min = 60;
var padding_top = 7;
var padding_left = 0;
var vertical = 1;

var img = new Array();
var i;
var first = -1;
var last = -1;

function nameByWidth(name, width)
{
	if (!(slash = name.lastIndexOf("/") + 1)) return name;
	dir = name.substr(0, slash);
	file = name.substr(slash);
	s = file.split(".");
	//alert(dir + s[0] + '.' + width + '.' + s[s.length - 1]);
	return dir + s[0] + '.' + width + '.' + s[s.length - 1];
}

var image_change = function (image_i) {
	var image = img[image_i];
	var width = parseInt(image.style.width) + image.speed;
	var top = parseInt(image.style.top) + image.top;
	var left = parseInt(image.style.left) + image.left;
	if (width < width_min) {
		image.setAttribute('src', nameByWidth(image.src, width_min));
		image.parentNode.parentNode.style.position = 'static';
		image.style.position = 'static';
		clearInterval(image.interval);
	} else if (width > width_max) {
		clearInterval(image.interval);
	} else {
		image.parentNode.parentNode.style.zIndex = width >= width_max / 2 ? 10 : 1;
		image.style.width = width + 'px';
		image.style.height = width + 'px';
		image.style.top = top + 'px';
		image.style.left = left + 'px';
	}
}
window.onload = function() {
	img = document.getElementsByTagName('img');
	for (i = 0; i < img.length; i++) {
		if (img[i].parentNode.className == 'img1') {
			if (vertical) {
				if (first == -1 && img[i].offsetTop < width_max/2 + 10) first = i;
				if (last == -1 && img[i].offsetTop + width_max > document.height + 10) last = i;
			}
			img[i].style.width = width_min + 'px';
			img[i].style.height = width_min + 'px';
			img[i].parentNode.parentNode.style.top = 0 + 'px';
			img[i].parentNode.parentNode.style.left = 0 + 'px';
			img[i].style.top = padding_top + 'px';
			img[i].style.left = padding_left + 'px';
			img[i].xi = i;
			//big = new Image();
			//big.src = nameByWidth(img[i].src, width_max);
			img[i].onmouseover = function () {
				this.speed = speed_px;
				this.parentNode.parentNode.style.position = 'relative';
				this.style.position = 'absolute';
				if (this.xi == first) this.top = 0;
				else if (this.xi == last) this.top = -speed_px;
				else this.top = -Math.round(speed_px/2);

				if (vertical) this.left = 0;
				else this.left = -Math.round(speed_px/2);

				if (this.interval) clearInterval(this.interval);
				this.src = nameByWidth(this.src, width_max);
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
			img[i].onmouseout = function () {
				this.speed = -speed_px;
				if (this.xi == first) this.top = 0;
				else if (this.xi == last) this.top = speed_px;
				else this.top = Math.round(speed_px/2);

				if (vertical) this.left = 0;
				else this.left = Math.round(speed_px/2);

				if (this.interval) clearInterval(this.interval);
				this.interval = setInterval("image_change("+this.xi+")", speed_ms);
			};
		}
	}
}

