var big_h;
var big_w;

preload_images("menu2-bottom.gif", "menu2-sel.gif");

$(function(){
	$("ul.menu2 li").mouseover(function(){
		$(this).siblings(".sel").removeClass('selected');
		$(this).addClass("rollover");
	}).mouseout(function(){
		$(this).removeClass("rollover");
		$(this).siblings(".sel").addClass('selected');
	});
	$(".prod-wrap, .sea-wrap").each(function(){
		max_height = 0;
		$(this).children().each(function(){
			var h = $(this).height();
			if(h>max_height)
				max_height = h;
		});
		$(this).children().height(max_height);
	});
});
window.onload = function(){
	vertical_gallery();
};

function filter_model(obj)
{
	model_id = obj.value;
	var url = site_url+type+'-'+cat_id+'-'+producer_id;
	if(model_id!=0)
		url += '-'+model_id;
	document.location = url;
}
function filter_paper(obj)
{
	cat_id = obj.value;
	var url = site_url+'paper'+'-'+cat_id+'-'+producer2_id;
	document.location = url;
}

function load_models(obj)
{
	$("#model_cat").load(site_url+'products/load_models/'+obj.value);
	producer_id = obj.value;
}

function load_paper_cats(obj)
{
	$("#paper_cat").load(site_url+'products/load_paper_cats/'+obj.value);
	producer2_id = obj.value;
}

function search_1(f)
{
	model_id = f.model.value;
	var url = site_url+type+'-'+cat_id+'-'+producer_id;
	if(model_id!=0)
		url += '-'+model_id;
	document.location = url;
	return false;
}
function search_2(f)
{
	cat_id = f.paper_cat.value;
	var url = site_url+'paper'+'-'+cat_id+'-'+producer2_id;
	document.location = url;
	return false;
}
function update_pay_type(obj)
{
	var cur_option = $(obj).find("option:selected");
	if(cur_option.hasClass('courier'))
	{
		$("#pay_type .paysys").hide();
		$("#paytype").find("option:selected").attr('selected','');
		$("#paytype").find("option:first").attr('selected','selected');
	}
	else
		$("#pay_type .paysys").show();
}
function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function vertical_gallery()
{
	big_h   = $(".images .big").height();
	big_w   = $(".images .big").width();

	var src = $(".images a:first").attr('href');
	var big_img = $('<img />');
	$(big_img).load(function(){
		gall_load(this);
	}).attr('src',src);
	$(".images .big").append(big_img);

	ul_h  = $(".images ul").height();
	par_h = $(".images .ul-wrap").height();
	if(ul_h<par_h)
	{
		$(".images ul").css('top',(par_h-ul_h)/2);
	}
	$(".images a").click(function(){
		var src		= $(this).attr('href');
		var new_img = $('<img />');
		$(new_img).load(function(){
			$(this).css('opacity',0);
			$(".images .big").append(this);
			gall_load(this);
			$(".images .big img").not(":last").animate({opacity:0},600,function(){ $(this).remove(); });
			$(".images .big img:last").animate({opacity:1},600);
		}).attr('src',src);
		return false;
	});
	$(".images").css('opacity',0)
		.css('visibility','visible')
		.animate({opacity:1},300);
}
function gall_load(big_img)
{
	var img_w = $(big_img).width();
	var img_h = $(big_img).height();
	if(img_w<big_w)
		$(big_img).css('left',(big_w-img_w)/2);
	if(img_h<big_h)
		$(big_img).css('top',(big_h-img_h)/2);
}

