$(document).ready(function() {
	//$(document).pngFix();
	
	$("#menu>li:not([class*='cur'])>ul").css('display','none');
	$("#menu>li").each(function() {
		var li=this;
		$('span',li).click(function() {
			$("#menu>li.cur>ul").animate({height: "hide"},200,function(){$(this).parent().removeClass('cur');});
			if($("#menu>li.cur>span").get(0)!=this)
				$(this).parent().addClass('cur').find('ul').animate({height: "show"},200);
		});
	});
	$("#rmenu>li:not([class*='cur'])").hover
	(
		function() {
			$(this).addClass('cur');
		},
		function() {
			$(this).removeClass('cur');
		}
	);
	/* $("#basket .basket_content").load('basket.php');
	$(".panel").each(function(i) {
		$('button',this).click(function() {
			panel=$(this).parent();
			id=$('input.id',panel).attr('value');
			n=$('input.n',panel).attr('value');
			$("#basket .basket_content").load('basket.php',{add:'',id:id,n:n});
		});
	}); */
	$('input.hidden').each(function(i) {
		$(this).attr('rel',$(this).val());
	});
	$('input.hidden').bind(
		'focus',
		function() {
			if($(this).attr('rel')==$(this).val())
				$(this).attr('value','');
		}
	).bind(
		'blur',
		function() {
			if($(this).attr('value')=='')
				$(this).val($(this).attr('rel'));
		}
	);
	$('.photo_item .add_vote').click(function() {
		$.get('add_vote.php',{id:$(this).attr('rel')},function(data) {
			alert(data);
			$('.photo_item .add_vote').remove();
		},'text');
		return false;
	});
	/* добавить в корзину */
	$('div.position div.panel button').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	if($('.catalogue').length>0) {
		var panel='';
		var producer=new Array();
		var producer_country=new Array();
		var age=new Array();
		$('.catalogue .position').each(function(){
			if(producer.indexOf($('.producer',this).text())<0)
				producer[producer.length]=$('.producer',this).text();
			if(producer_country.indexOf($('.producer_country',this).text())<0)
				producer_country[producer_country.length]=$('.producer_country',this).text();
			if(age.indexOf($('.age',this).text())<0)
				age[age.length]=$('.age',this).text();
		});
		panel+='<select class="select_producer" rel="producer"><option value="-1">Выберите производителя</option>';
		for(var i=0;i<producer.length;i++)
			panel+='<option>'+producer[i]+'</option>';
		panel+='</select>';
		panel+='<select class="select_producer_country" rel="producer_country"><option value="-1">Выберите страну производителя</option>';
		for(var i=0;i<producer_country.length;i++)
			panel+='<option>'+producer_country[i]+'</option>';
		panel+='</select>';
		panel+='<select class="select_age" rel="age"><option value="-1">Выберите возраст</option>';
		for(var i=0;i<age.length;i++)
			panel+='<option>'+age[i]+'</option>';
		panel+='</select>';
		panel=$('<div class="panel">'+panel+'</div>');
		panel.find('select').bind('change',function() {
			$('.position.hide').removeClass('hide').show(0);
			$(this).parent().find('select').each(function(){
				if($(this).attr('value')!=-1) {
					var t=$(this).attr('value');
					$('.position .'+$(this).attr('rel')).each(function(){
						if($(this).text()!=t) {
							$(this).parent().addClass('hide');
						}
					});
				}
			});
			$('.position.hide').hide();
		});
		$('.catalogue').prepend(panel);
	}
});

