var xajaxRequestUri="/procajax.php";
var xajaxDebug=false;
var xajaxStatusMessages=false;
var xajaxWaitCursor=true;
var xajaxDefinedGet=0;
var xajaxDefinedPost=1;

function xajax_openStuffList(cat_id) {
	return xajax.call("openStuffList", arguments, 1);	
}
function xajax_openPodCatList(type_id) {
	return xajax.call("openPodCatList", arguments, 1);	
}

function xajax_openStuffDescription(stuff_id) {
	return xajax.call("openStuffDescription", arguments, 1);	
}

function xajax_changePhoto(photo_id) {
	return xajax.call("changePhoto", arguments, 1);	
}

function changePhoto(photo_id) {
	$('td.select>img').attr('src', '/img/0.gif');
	$('td.select').toggleClass('select');
	$('#gi'+photo_id).attr('src', '/img/gall_bg.gif');
	$('td#g'+photo_id).toggleClass('select');
	xajax_changePhoto(photo_id);
	return false;
}

var xajax=new Xajax();

var m = 0;
var delay = 5000;
function show_block(id, name){
	$('#ul_cat').hide("fast");
	$('#block_cat').fadeIn("fast");
	$('li').removeClass("active");
	$('#'+id).addClass("active");
	$('#ul_cat').show("fast");	
	return xajax_openPodCatList(id);
}
function openStuffList(cat_id, type_id, cat_name) {
	cur_cat = cat_id;
	cur_typ = type_id;
	$('li').removeClass('select');
	$('#podcat_'+cat_id).addClass('select');
	return xajax_openStuffList(cat_id,type_id);		
}

function menu_in(o)
{
	var pic = document.getElementById(o.id);
	pic.src = '/img/' + o.id + '_h.gif';
}
function menu_out(o)
{
	var pic = document.getElementById(o.id);
	pic.src = '/img/' + o.id + '.gif';
}

// Навигация изделий
	var item = 0;
	var pic = 0;

function initializeStuffLinks() {
	$("#items_menu .item").click(
	  function () {
		if (lastItem != 0)
		{
			item = this;
			$('#'+lastItem).find(".select").html("");
			$(item).find(".select").html("<div class='blue_light'><img class='png' style='background: url(/img/blue.png) top left no-repeat; margin: 0 0 0 -43px; position: absolute' src='/img/0.gif' width='85' height='52'></div>");
			$("#item_info").fadeOut("slow", function()
				{
					pic = $(item).attr("rel");
					iid = $(item).attr("id");
					$("#bigfoto").attr("src", pic);
					xajax_openStuffDescription(iid);
				}	
			);
		}
		else
		{
			item = this;
			pic = $(item).attr("rel")
			iid = $(item).attr("id");
			$("#bigfoto").attr("src", pic);
			$(this).find(".select").html("<div class='blue_light'><img class='png' style='background: url(/img/blue.png) top left no-repeat; margin: 0 0 0 -43px; position: absolute' src='/img/0.gif' width='85' height='52'></div>");
			xajax_openStuffDescription(iid);
		}
		lastItem = this.id;
	  }
	);
	
	initializeBotMenu();
}

function initializeBotMenu(){
	// Меню изделий
	var botScroll = $("#botScrollbox").scrollLeft();
	var botBoxWidth = $("#botScrollbox").width();
	var botMenuWidth = $("#items_menu").width();
	var botScrollWidth = (botMenuWidth - botBoxWidth) /2;

	$("#botScrollbox").animate({ scrollLeft: 50 }, 500, function ()
	{
		$("#botScrollbox").mouseover(function(e){
		  var botMouse = e.clientX;
		  var botWidth = $("#botScrollbox").width();
		  var botHalfWidth = botWidth / 2;
		  var botScroll = $("#botScrollbox").scrollLeft();

			if (botMouse > botHalfWidth)
			{
				var botMouseFinal = botMouse - botHalfWidth;
				botMouseFinal = botMouseFinal * 4;
			}
			if (botMouse < botHalfWidth)
			{
				var botMouseFinal = -1 * (botHalfWidth - botMouse);
				botMouseFinal = botMouseFinal * 4;
			}

			if (botMouseFinal > 0)
			{
				$("#botScrollbox").animate({ scrollLeft: botScroll + botMouseFinal }, delay);
			}
			{
				$("#botScrollbox").animate({ scrollLeft: botScroll + botMouseFinal }, delay);
			}

			$("#alert").html("мышь:" + botMouseFinal + "<br/>блок: " + botWidth + "<br/>половина блока" + botHalfWidth + "<br/>текущий скролл: " + botScroll);

			$("#botScrollbox").mouseout(function(){
						$("#botScrollbox").stop();

			});
			$("#items_menu .item").click(function(){
						$("#botScrollbox").stop();
			});	

		});
	});	
}

$(document).ready(function(){
	/* scrolling */
	var delay = 1000;
	var sup = 5;
	
	$("#scrollLeft2").mouseover(function(e){
		//cWidth = $("#scrollbox").width() + 80;
        cWidth = $("#tscrollbox2").width() + 70;
		cLeft = $("#scrollbox2").scrollLeft();
		$("#scrollbox2").animate({ scrollLeft: 0 }, (cLeft)*sup);
	});	
	$("#scrollLeft2").mouseout(function(){
		$("#scrollbox2").stop();
	});
	$("#scrollRight2").mouseover(function(e){
		//cWidth = $("#scrollbox").width() + 80;
        cWidth = $("#tscrollbox2").width() + 70;
		cLeft = $("#scrollbox2").scrollLeft();
		$("#scrollbox2").animate({ scrollLeft: cWidth }, (cWidth-cLeft)*sup);
	});	
	$("#scrollRight2").mouseout(function(){
		$("#scrollbox2").stop();
	});
});

function switc(obj){
 if(document.getElementById){
 var el = document.getElementById(obj);
  if(el.style.display != "block"){
   el.style.display = "block";
  }else{
   el.style.display = "none";
  }
 }
}

function SendForm(f)
{
	if (typeof(f.email)=='object')
	{
		var reg_email = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi
		var	StrObj=f.email.value;
		var email=StrObj.match(reg_email);
	}

	if (typeof(f.name)=='object' && f.name.value=='') alert('Укажите Ваше имя:')
	else if (typeof(f.firm)=='object' && f.firm.value=='') alert('Укажите Вашу организацию:')
	else if (typeof(f.phone)=='object' && f.phone.value=='') alert('Укажите телефон (с кодом города):')
	else if (typeof(f.email)=='object' && email==null) alert('Укажите Ваш адрес Email:')
	else if (typeof(f.theme)=='object' && f.theme.value=='') alert('Укажите тему обращения:')
	else if (typeof(f.text)=='object' && f.text.value=='') alert('Укажите текст сообщения:')
	else if (typeof(f.captcha)=='object' && f.captcha.value=='') alert('Введите слово на картинке:')
	else return true
	
	return false
}
