var tt = new Array();

function show(id)
{
	$('#'+id).show();
	return false;
}

function openm(id)
{
	clearTimeout(tt[id]);
	$('#submenu'+id).css({overflow:''}).animate({height:'show',opacity:'show'}, 350);
}

function closem(id)
{
	clearTimeout(tt[id]);
	tt[id] = setTimeout("closemenu("+id+")", 500);
}

function closemenu(id)
{
	$('#submenu'+id+':not(:animated)').css({overflow:'hidden'}).animate({height:'hide', opacity:'hide'}, 350);
}

function isEmailCorrect(formname, fieldname) { 
	var re = /^[a-zA-Z0-9\-_](([a-z0-9\-_\.\+\&]?)+[a-z0-9])?\@((\w([a-zA-Z0-9\-_]+)?\.[a-z]{2,4})|(([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d |2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5]))|(localhost))$/i;
	if(re.test(eval("document.forms['"+formname+"']."+fieldname+".value"))) return true;
	else {
		alert("Неверно указан Email!");
		eval("document.forms['"+formname+"']."+fieldname+".focus()");
		return false; 
	} 
}

function showphoto(id)
{
	document.getElementById('main_photo').src='/img/models/big/'+id+'.jpg';
	return false;
}


function checkform()
{
	var error = '';
	if(document.getElementById('fio').value.length<4) error += 'Укажите ФИО!\n';
	if(document.getElementById('femail').value.length<6) error += 'Укажите свой e-mail адрес!\n';
	if(document.getElementById('model').value==0) error += 'Укажите модель компьютера!\n';
	if(document.getElementById('quest').value==0) error += 'Сформулируйте свой вопрос!';
	if(error != ''){ alert(error); return false; } else return true;
}

function move_photos_up()
{
	next_top = parseFloat($('#gallery').css('marginTop')) + 106;
	if(next_top > 0) next_top = 0;
	if(next_top <= 0)
	{
		if(next_top == 0) $('#cat_str_up').hide();
		$('#cat_str_down').show();
		$('#gallery').animate({'marginTop':next_top}, 400);
	}

	return false;
}

function move_photos_down()
{
	height = 206 - $('#gallery').height();
	next_top = parseFloat($('#gallery').css('marginTop')) - 106;
	if(next_top < height) next_top = height;
	if(next_top <= 0)
	{
		if(next_top == height) $('#cat_str_down').hide();
		$('#cat_str_up').show();
		$('#gallery').animate({'marginTop':next_top}, 400);
	}

	return false;
}

function move_shops_up()
{
	next_top = parseFloat($('#gallery_shop').css('marginTop')) + 163;
	if(next_top > 0) next_top = 0;
	if(next_top <= 0)
	{
		if(next_top == 0) $('#cat_str_up_shop').hide();
		$('#cat_str_down_shop').show();
		$('#gallery_shop').animate({'marginTop':next_top}, 400);
	}

	return false;
}

function move_shops_down()
{
	height = 311 - $('#gallery_shop').height();
	next_top = parseFloat($('#gallery_shop').css('marginTop')) - 163;
	if(next_top < height) next_top = height;
	if(next_top <= 0)
	{
		if(next_top == height) $('#cat_str_down_shop').hide();
		$('#cat_str_up_shop').show();
		$('#gallery_shop').animate({'marginTop':next_top}, 400);
	}

	return false;
}

function click_on(id)
{
	$('#tbl_info, #tbl_review, #tbl_otz').hide();
	$('#tbl_'+id).show();
	$('#link_info, #link_review, #link_otz').addClass('link_c16').removeClass('link_gray').removeClass('bold');
	$('#link_'+id).addClass('link_gray').addClass('bold').removeClass('link_c16');
	
	return false;
}

function show_more(id)
{
	$('#more'+id).toggle();
	var html = $('#mimg'+id).attr('src') == '/img/str_down.png' ?
		'свернуть<img id="mimg'+id+'" src="/img/str_up.png" width="12" height="6" border="0" alt="" class="pl12"/>' : 'развернуть<img id="mimg'+id+'" src="/img/str_down.png" width="12" height="6" border="0" alt="" class="pl12"/>';
	$('#aimg'+id).html(html);
		
	return false;
}

function show_filter(id)
{
	$('#td'+id).height(124);
	$('#filter'+id+'_on').show();

	return false;
}

function hide_filter(id)
{
	$('#td'+id).height(15);
	$('#filter'+id+'_on').hide();

	return false;
}

function set_filter(id, val)
{
	$('#fval'+id).val(val);
	$('#fa'+id+'_off').html($('#fa'+id+'_on'+val).attr('rel'));
	$('A[id^=fa'+id+'_on]').each(function(){ $(this).removeClass('filter_on').addClass('filter'); });
//	$('#fa'+id+'_on1, #fa'+id+'_on2, #fa'+id+'_on3, #fa'+id+'_on4, #fa'+id+'_on5, #fa'+id+'_on6, #fa'+id+'_on7').removeClass('filter_on').addClass('filter');
	$('#fa'+id+'_on'+val).removeClass('filter').addClass('filter_on');
	load_lamps($('#fval1').val(), $('#fval2').val(), $('#fval3').val(), $('#fval4').val());

	return hide_filter(id);
}

function load_lamps2(id1, id2, id3, id4)
{
	$('#lamps').animate({'height':'0'}, 700, function(){
		$('#lamps').html('');
		$.getJSON("/ajax/search_lamps.php",{id1:id1, id2:id2, id3:id3, id4:id4},function(dataArray){ $.each(dataArray,function(index,data){ $('#lamps').html(data.res).animate({'height':'100%'}, 1100); $('#all_models, #showed_models').html(data.count); }); });
	});
}

function load_lamps(id1, id2, id3, id4)
{
	if($('#lamps DIV.lamp_div').slice(1).width() > 140) delay = 350; else delay = 1;
	$('#lamps DIV.lamp_div').each(function(){ $(this).animate({'width':'0', 'opacity':'0'}, delay); });
	setTimeout("load_lamps_ajax("+id1+","+id2+","+id3+","+id4+")", delay);
}

function load_lamps_ajax(id1, id2, id3, id4)
{
	$.getJSON("/ajax/search_lamps.php",{id1:id1, id2:id2, id3:id3, id4:id4},function(dataArray){
		$.each(dataArray,function(index,data){
			$('#lamps').html(data.res);
			$('#lamps DIV.lamp_div').each(function(){ $(this).css({'opacity':'0'}); });
			$('#lamps DIV.lamp_div').each(function(){ $(this).animate({'width':'148px', 'opacity':'1'}, 500); });
			$('#all_models, #showed_models').html(data.count);
		});
	});
}

function load_shops_ajax()
{
	var html = '', count = 0, city_id = $('#city_id').val();
	$.getJSON("/ajax/search_shops.php",{city_id:city_id},function(dataArray){
		$.each(dataArray,function(index,data){
			html += data.res;
			count += 1;
		});

		$('#shops_div').html(html);
		move_shops_up();
		if(count < 7) $('#cat_str_up_shop, #cat_str_down_shop').hide();
	});
}

function show_shops()
{
	var div = $('#shops_inner');
	var left = ($(window).width() - $(div).width()) / 2;
	var top = ($(window).height() - $(div).height()) / 2;
	$(div).css({'left':left, 'top':top, 'opacity':0}).show().animate({opacity:1}, 500);
	$('#shops').css({'opacity':0}).show().animate({opacity:0.6}, 500);

	return false;
}

function close_shops()
{
	$('#shops_inner,#shops').animate({opacity:0}, 300, function(){ $('#shops_inner,#shops').hide(); });
	
	return false;
}

