var api;

$(document).ready(function(){//	$(".bottonUp").hide();
	$(window).resize(function(){		resizeContent();
		if(document.body.clientHeight<630)
		{
			$("#footers").css('top','590px');
			$("#contents").css('height','590px');
			$("#basket").css('top','30px');
		}
		else
		{			$("#footers").css('top',document.body.clientHeight-40+'px');
			$("#contents").css('height','100%');
			$("#basket").css('top','45px');
        }
		if(document.body.clientHeight<730)
		{
			$("#content").css('top','279px');
			$("#basket").css('top','30px');
		}
		else
		{
			$("#content").css('top','294px');
		}

		if(document.body.clientWidth<940)
			$("#contents").css('width','940px');
		else
			$("#contents").css('width','100%');
	});

	resizeContent();

	if(document.body.clientHeight<630)
	{
		$("#footers").css('top','590px');
		$("#contents").css('height','590px');
		$("#basket").css('top','30px');
    }
    else
		$("#footers").css('top',document.body.clientHeight-40+'px');

	if(document.body.clientHeight<730)
	{
		$("#content").css('top','279px');
		$("#basket").css('top','30px');
	}

	if(document.body.clientWidth<940)
		$("#contents").css('width','940px');

	$("a.collectionImg").fancybox({'padding': '0', 'AutoScale': 'true', 'overlayOpacity':'1', 'overlayColor':'#FFF', 'transitionIn': 'none', 'transitionOut': 'none',	'titlePosition': 'over'});
	$("a.noveltys").fancybox({'padding': '0', 'AutoScale': 'true', 'overlayOpacity':'1', 'overlayColor':'#FFF', 'transitionIn': 'none', 'transitionOut': 'none',	'titlePosition': 'over'});

	$("input.sendInput").click(function(){			var calc=$("select[name='p["+this.id+"]']").attr("value")*$("input[name='n["+this.id+"]']").attr("value");

			$.ajax(
			 {
			  type: "post",
			  dataType : "xml",
			  url: "/design/js/ajax.php",
			  data: "act=add_product&id="+this.id+"&calc=" + calc,
			  success: function(xml)
			  {
			  	if($(xml).find('note').text())
			  	{
			            $(xml).find('note').each(function(){			            	if($("#basket").is(":hidden"))
								$("#basket").show();
							$("#basket_summa").html($(this).find('summa').text());
							$("#basket_calc").html($(this).find('calc').text());

							alert("Модель была успешно добавлена в Вашу корзину.\n\nДля того чтобы оформить заказ на покупку выбранных моделей, нажмите кнопку 'ОФОРМИТЬ ЗАКАЗ' в Вашей корзине.");
			            });
			  	 }
			  	 else
			  	 	alert('Вы неверно указали количество товаров. Модель НЕ добалена в Вашу корзину.');
			  	}
			});
		return false;
	});

	$("#clearBasket").click(function(){		if(confirm('Действительно удалить все из Вашей корзины?'))
		{
			$.ajax(
			 {
				  type: "post",
				  dataType : "html",
				  url: "/design/js/ajax.php",
				  data: "act=del_product",
				  success: function()
				  {					$("#basket").hide();
				  }
			});
		}
		return false;
	});

	//скролинг
	if(document.getElementById('scroll-pane'))
	{
		var pane = $('.scroll-pane');
		pane.jScrollPane({showArrows:true, scrollbarWidth:19, autoReinitialise: true});
		api = pane.data('jsp');
	}

	//стрелка "вверх"
/*
	$("#text").hover(function(){		scrollToShow();
	},
	function(){
		$(".bottonUp").fadeOut(600);
	});

	$("#text").mousemove(function(){
		scrollToShow();
	});
*/
});

//прокрутка вверх
function scrollTo(){
	$(document).ready(function(){		api.scrollTo(0,0);	});
}
//показывает стрелку вверх
/*
function scrollToShow(){
	$(document).ready(function(){
		if(parseInt($(".jspPane").css("top")))
			$(".bottonUp").fadeIn(600);
		else
			$(".bottonUp").fadeOut(600);
	});
}
*/
//прелоадер
function loadMainPic(){	$(document).ready(function(){
		$("#loader").hide();
		$("#main_pic").fadeIn(1200);
	});
}
//ввод пароля в форму для просмотра наличия товара
$(document).ready(function(){
	$("#shop_select").change(function(){		if($("#shop_select option:selected").val()!=9000000)
		{
			$('#shop_pass').show();
			$('#shop_nopass').hide();
		}
		else
		{
			$('#shop_pass').hide();
			$('#shop_nopass').show();
		}
	})
});
//> МЕНЮ
 var old;
 var memold;
 var subold;
 if(document.layers)
 {
  window.captureEvents(Event.MOUSEDOWN);
  window.onmousedown=do_out;
 } else
 {
document.onmouseup=do_out;
}
function show_layer(x)
{
	if(document.layers)
		document.layers[x].visibility="show";
	else
		document.all[x].style.visibility="visible";
}
function hide_layer(x)
{
	if(document.layers)
		document.layers[x].visibility="hide";
	else
		document.all[x].style.visibility="hidden";
}
function do_menu(x)
{
	if(!old)
		old=memold;
	if(old!=x)
	{
		show_layer(x);
		old=x;
	} else
		old="";
}
function do_check(x)
{
	if(old && old!=x)
	{
		hide_layer(old);
		show_layer(x);
		old=x;
	}
	do_submenu();
}
function do_out()
{
	if(old)
		hide_layer(old);
	memold=old; old="";
	do_submenu();
}
function do_submenu(x)
{
	if(subold)
	{
		hide_layer(subold);
		subold="";
	}
	if(x)
	{
		show_layer(x);
		subold=x;
	}
}
//< МЕНЮ

