function f2011()
{
	//location="/main?old2"
	//location="/main?2010"
	location="/galery";
}
function f1_2010()
{
	//location="/main?old2"
	location="/galery"

}
function f1_1()
{
	location="/main?old"
return false;
}
function f1()
{
	location="/main"
//	location="/galery/cat265"
return false;
}
function f(num)
{
	location="/galery"
return false;
}
function setName(name)
{
	document.getElementById("ptitle").innerHTML="<h1>"+name+"</h1>"
}
function getSubCat()
{
	if(document.getElementById("sub_cat").style.display=="none")
		$("div.p_sub div.sub_cat:hidden").slideDown("slow")
	else
		$("div.p_sub div.sub_cat:visible").slideUp("slow")
}
function selDef(divid)
{

	var bgdef="#d0cfcf"
	var bgsel="#505351"
	var cls="l_f"
	obj=document.getElementById(divid)
	if(obj.firstChild.firstChild!=null)
	{
		var size=obj.firstChild.firstChild.childNodes.length
		for(var i=0; i<size; i++)
		{
			obj.firstChild.firstChild.childNodes[i].style.backgroundColor=bgdef
			obj.firstChild.firstChild.childNodes[i].firstChild.firstChild.className=cls
		}
	}
	else
	{
		 size=obj.childNodes[1].firstChild.childNodes.length
		for(var i=0; i<size; i++)
		{
			obj.childNodes[1].firstChild.childNodes[i].style.backgroundColor=bgdef
			obj.childNodes[1].firstChild.childNodes[i].firstChild.firstChild.className=cls
		}
	}
}
function sel(obj, bgdef, bgsel, cls)
{
	size=obj.parentNode.parentNode.childNodes.length
	for(var i=0; i<size; i++)
	{
		obj.parentNode.parentNode.childNodes[i].style.backgroundColor=bgdef
		obj.parentNode.parentNode.childNodes[i].firstChild.firstChild.className=cls
	}
	obj.parentNode.style.backgroundColor=bgsel
		
	obj.firstChild.className=cls+"_sel"
	obj.firstChild.onclick()
		
}
function selM(k)
{
	k--
	document.getElementById(cir_div_goods+"_"+k).onclick()
	document.getElementById(cir_div_goods+"_"+k).firstChild.onclick()
	// при нажатии на фото инфо
	//alert()
	k++
	document.getElementById("info").innerHTML=array_descr[cir_div_goods+"_"+k]

}
function setBigPhoto(photo, i)
{
	document.getElementById("info").style.display="block"
	$("#info").css('opacity','0.8')
	document.getElementById("maxi").style.display="block"
	document.getElementById("maxi").childNodes[0].src="/img_cat/3/"+photo
	if(i!=null && i!=0)
	{
		if(i > p.first+2)
			p.next()
		if(i > p.first+2)
			setTimeout("pos("+i+")",500);
			
		if(i < p.first)
			p.prev()
		if(i < p.first)
			setTimeout("pos("+i+")",500);
		
	}
	// при нажатии на меню инфо
	i++
	document.getElementById("info").innerHTML=array_descr[cir_div_goods+"_"+i]
}
function pos(i)
{
	if(i > p.first+2)
		p.next()
	if(i > p.first+2)
		setTimeout("pos("+i+")",500);
	if(i < p.first)
			p.prev()
	if(i < p.first)
			setTimeout("pos("+i+")",500);


}
function setPhoto(array)
{
	if(!$("#mini").is(':visible'))
	{
		//document.getElementById("mini").style.display="block"
		//document.getElementById("maxi").style.display="block"
		$("#mini, #maxi").show().css("visibility", "");
	}
	size_old=mycarousel_itemList.length
	for(var j=1; j<=size_old;j++)
	{
		if(p.has(j))
		p.remove(j)
	}
	if(size_old<3)
		for(var i=1; i<size_old;i++)
		{
			document.getElementById("mycarousel").removeChild(document.getElementById("mycarousel").childNodes[0])
		}
	else
		for(var i=1; i<4;i++)
			document.getElementById("mycarousel").removeChild(document.getElementById("mycarousel").childNodes[0])
	
	p.first=1 
	p.last=3
	mycarousel_itemList=array
	p.size(mycarousel_itemList.length)
 	mycarousel_itemLoadCallback(p, st)

}
cir_div_goods=""

function setFirst(id)
{

	cir_div_goods=id
	if(document.getElementById(id+"_1"))
	{
		document.getElementById(id+"_1").onclick()
		document.getElementById(id+"_1").firstChild.onclick()
	}

}
function setOpacity()
{
	var ops="0.8"
	$('#collect_ch').css('opacity',ops);
	$('#sub_cat').css('opacity',ops);
	
	var divs=divfrm.split(";")
  	for(var i=0;i<divs.length-1; i++)
		$('#'+divs[i]).css('opacity',ops);

	divs=divgds.split(";")
  	for(var i=0;i<divs.length-1; i++)
		$('#'+divs[i]).css('opacity',ops);

}
function hideAll(str)
{
	if(str==0)
	{
		//document.getElementById("mini").style.display="none"
		//document.getElementById("maxi").style.display="none"
		//document.getElementById("info").style.display="none"
		$("#mini, #maxi, #info").hide();
		
		hideAll(divfrm)
		hideAll(divgds)
		return
	}
  var divs=str.split(";")
  
  for(var i=0;i<divs.length-1; i++)
		document.getElementById(divs[i]).style.display="none"
}
function show(what, vis)
{
	document.getElementById(what).style.display=vis
}
function showgoods(id)
{
	window.open('/show.php?id='+id,'_blank','left='+((document.body.clientWidth-850)/2)+', top=200, width=850px,height=600px,location=no,toolbar=no,status=no,scrollbars=yes'); 

}
function bigphoto(obj)
{
	var str=obj.src.toString()
	document.getElementById('mainphoto').src=str.replace('/2/', '/3/')
}

function slideUP1(elem, clas) {
	clas.removeClass('vsel');
	elem.slideUp(600, function(){
			
	})
}
function slideDown1(elem, clas) {

	clas.addClass('vsel');

	elem.slideDown(600, 'linear', function(){})
}

function showjobs(id) {
	$('.vacans .full:not(#v-'+id+')').each(function(){
		slideUP1($(this), $('#v'+$(this).attr('id')))
	})
	
	if($('#v-'+id).css('display') == 'none'){
		slideDown1($('#v-'+id), $('#v'+$('#v-'+id).attr('id')))
	} else {
		slideUP1($('#v-'+id), $('#v'+$('#v-'+id).attr('id')))
	}
}

function sendrezume(elem){
	elem = $(elem).parent();
	var name= elem.find('.name').val();
	var contact= elem.find('.contact').val();
	var text= elem.find('.text').val();
	console.debug(name);
	console.debug(contact);
	console.debug(text);
}

function is_int(input){
    return typeof(input)=='number'&&parseInt(input)==input;
  }

function changeCountInOG(){
	var fp = 0;
	var price = parseInt($('#eo-price').attr('value'));
	$('.one-e-good table.rs input').each(function(){
		var d = parseInt($(this).attr('value'));
		if (d > 0)
			fp += price*d;
	});
	$('.one-e-good .full-price-num').text(fp + 'р.');
}


	var red1 = true;

function blinkf(selector) {
	if (red1) {
		$(selector).css("color", "#b2b3b4");

	} else {
		$(selector).css("color", "#ffffff");
	}
	red1 = !red1;
};

function pluralForm(item, f1, f2, f3){
	item = Math.abs(item) % 100;
	var item1 = item % 10;
	if (item > 10 && item < 20) return f3;
	if (item1 > 1 && item1 < 5) return f2;
	if (item1 == 1) return f1;
	return f3;
}

$(function(){

	var npg = function(){
			$('div.fool-goods .navigation a').click(function(){
			$('#idcontent .fool-goods').stop(true, false).animate({
				opacity: 0
			},700);

			$.ajax({
				url:$(this).attr('href'),
				dataType:'html',
				success: function(data){
					$('#idcontent .fool-goods').queue("fx", function(){
						
						$('#idcontent').html(data);	
						npg();
						$('#idcontent .fool-goods').css({ opacity: 0 });
						$('#idcontent .fool-goods').animate({
							opacity: 1
						},300);
					})
				},
				error: function(jqXHR, textStatus, errorThrown){
					alert(textStatus);
				}
			});
			return false;
		});
	}
	npg();


	$('input[title]').focus(function() {
			if ($(this).attr('title') == this.value) {
				this.value='';
				$(this).removeClass('titletip');
			}
		});
	$('input[title]').blur(function() {
			if (this.value == '') {
				this.value = $(this).attr('title');
				$(this).addClass('titletip');
			}
		})
	$('input[title]').each(function(){
		if (this.value == '') {
			this.value = $(this).attr('title');
			$(this).addClass('titletip');
		}
	});
	$('#srd').click(function(){
		$('.rezume').slideToggle('slow');
	})
	$('.vid-otobr .block-view').click(function(){
		if($(this).hasClass('selected')) {
			return;
		}
		$(this).addClass('selected')
		$('.vid-otobr .table-view').removeClass('selected');
		$('.goods-table').slideUp(300);
		$('.egoods').slideDown(300);
	});
	$('.vid-otobr .table-view').click(function(){
		if($(this).hasClass('selected')) {
			return;
		}
		$(this).addClass('selected')
		$('.vid-otobr .block-view').removeClass('selected');
		$('.egoods').slideUp(300);
		$('.goods-table').slideDown(300);
	});
	$('.one-e-good table.rs input').each(function(){
		var element = $(this);
		element.hide();
		var num = parseInt(element.attr('value'));
		if (isNaN(num)) {
			num=0;
		}
		element.after('<div class="counting"><span class="number"><span class="nn">'+num+'</span> '+pluralForm(num, 'коробка', 'коробки', 'коробок')+'</span><div class="minus"></div><div class="plus"></div></div>');
		element.parent().find('.minus').click(function(){
			var number = $(this).parent().find('.number');
			var d = parseInt(number.text());
			if (d>0) {
				d--;
				number.html('<span class="nn">'+d+'</span> '+pluralForm(d, 'коробка', 'коробки', 'коробок'));
				element.val(d);
				changeCountInOG();
			}
		});
		element.parent().find('.plus').click(function(){
			var number = $(this).parent().find('.number');
			var d = parseInt(number.text());
			if (isNaN(d)) {
				d=0;
			}
			d++;
			number.html('<span class="nn">'+d+'</span> '+pluralForm(d, 'коробка', 'коробки', 'коробок'));
			element.val(d);
			changeCountInOG();
		});
		changeCountInOG();
	});
	$('.one-e-good table.rs input').change(function(){
		changeCountInOG();
	})

	$('.cb').colorbox({});
	$('a.in-basket.frame').colorbox({
		iframe: true,
		width: 850,
		height: 350
	});
	$('.iframe').colorbox({
		iframe: true,
		width: 850,
		height: 350
	});

	$('#eogood #good-to-basket').submit(function() {
        $(this).ajaxSubmit({
			success: function(){
				parent.window.location.reload()
				/*parent.$.colorbox.close();*/
			}
		});
        return false;
    });
	$('#eogood .closeform').click(function() {
		parent.window.location.reload()
	});

	$('.toggleup').slideUp();
	$('.order-div .order').click(function(){
		$('#orders').slideToggle(300);
	});
	$('.oefilter').click(function(){
		$('.filter-form').slideToggle(300);
	});
	$('.filter-form .reset').click(function(){
		$('.filter-form').slideToggle(300);
	})

	$('.order-type .type').click(function(){
		if ($(this).hasClass('selected'))
			return false;
		$('.order-type .type').removeClass('selected');
		$(this).addClass('selected');
		switch ($(this).attr('id')) {
			case 'order-login':
				$('.order-form').slideUp(100, function(){
					$('.login-form').slideDown(300);
				});
				break;
			case 'order-register':
				$('.login-form').slideUp(100);
				$('.order-form').slideUp(100, function(){
					$('.order-form .registration').show();
					$('.order-form #wo-registration').val(0);
					$('.order-form #sendzak').attr('value', 'Зарегестрироваться и отправить заказ');
					$('.order-form').slideDown(300);
				});
				break;
			case 'order-order':
				$('.login-form').slideUp(100);
				$('.order-form').slideUp(100, function(){
					$('.order-form .registration').hide();
					$('.order-form #wo-registration').val(1);
					$('.order-form #sendzak').attr('value', 'Отправить заказ');
					$('.order-form').slideDown(300);
				});
				break;
		}

	});

	$('.show-order').click(function(){
		var eclass=$(this).attr('id');
		if ($('.order-html.'+eclass).css('display') == 'block') {
			$(this).html('Показать содержимое заказа');
		} else {
			$(this).html('Скрыть содержимое заказа');
		}
		$('.order-html.'+eclass).slideToggle(300);
	});
	
	setInterval('blinkf("#mloeshop a")', 500);


	if ($('#dostavkaselect').val() != '0') {
		$('#dostavkainput').hide();
	}
	$('#dostavkaselect').change(function(){
		if($(this).val() == 0) {
			$('#dostavkainput').show();
		} else {
			$('#dostavkainput').hide();
		}
	});
	
	var changeRadio1 = function(){
		if ($('#uridich').is(':checked')) {
			$('.fiz-fields').hide();
			$('.ur-fields').show();
		} else {
			$('.fiz-fields').show();
			$('.ur-fields').hide();
		}
	};
	changeRadio1();
	$('#uridich, #fizich').change(function(){
		changeRadio1();
	});

	$('.tooltip').removeAttr('title');
	$('.tooltip').hover(function(){
		$(this).find('.tooltip-content').fadeIn(300);
	}, function(){
		$(this).find('.tooltip-content').fadeOut(300);
	});

});
