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_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 openStuffList(cat_id, cat_name) {
	if (cur_cat != cat_id) {
		if (lastItem) {
			lastItem = 0;
			$("#item_info").fadeOut("slow");
		}
		if (cur_cat != 0) {
			$('#cat'+cur_cat).html('<a class="item" href="#" onClick="openStuffList('+cur_cat+', \''+cur_cat_name+'\'); return false;">'+cur_cat_name+'</a>');
			$('#cat'+cur_cat).toggleClass('select');
		}
		$('#cat'+cat_id).html('<div><a class="item" href="javascript:void(null);">'+cat_name+'</a></div><img src="/img/menu_selector.gif" width="65" height="42" alt="">');
		$('#cat'+cat_id).toggleClass('select');
		cur_cat = cat_id;
		cur_cat_name = cat_name;
		 
		return xajax_openStuffList(cat_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;
	  }
	);
	
	// Меню изделий
	var botScroll = $("#botScrollbox").scrollLeft();
	var botBoxWidth = $("#botScrollbox").width();
	var botMenuWidth = $("#items_menu").width();
	var botScrollWidth = (botMenuWidth - botBoxWidth) /2;

	$("#botScrollbox").animate({ scrollLeft: botScrollWidth }, 1500, 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(){
	// Меню коллекций
	var scroll = $("#scrollbox").scrollLeft();
	var boxWidth = $("#scrollbox").width();
	var menuWidth = $("#menuBlock").width();
	var scrollWidth = (menuWidth - boxWidth) /2;

	$("#scrollbox").animate({ scrollLeft: scrollWidth }, 1500, function ()
	{
		$("#scrollbox").mouseover(function(e){
			  var mouse = e.clientX;
			  var width = $("#scrollbox").width();
			  var halfWidth = width / 2;
			  var offset = $("#menuBlock").offset();
									  
				if (mouse > halfWidth)
				{
					var mPlus = mouse - halfWidth;
					mPlus = parseInt(mPlus * 3);
					curPos = offset.left;	
				}
				else
				{
					curPos = offset.left;
					var mMinus = -1 * (halfWidth - mouse);
					mMinus = parseInt(mMinus * 3);
				}
				if ( mPlus > 0 )
				{
					$("#scrollbox").animate({ scrollLeft: mPlus }, delay);
				} 
				else
				{
					$("#scrollbox").animate({ scrollLeft: mMinus }, delay);
				}
								$("#scrollbox").mouseout(function(){
							$("#scrollbox").stop();
				});	
		});
		}
	);
	
	/* 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
}