$(document).ready(function(){

	$('#fmenu #cssmenu2 li').hover(function(){ /*alert();*/ if($(this).find('ul').height()){ var dd = $(this).find('ul').height(); dd = (dd-2); }  $('#cssmenu2 ul').css('top', '-'+dd+'px'); }, function(){ });

	$('.cat_name').live('click', function(){
		var cat = $(this).attr('rel');
		$(this).attr('class', 'cat_name_e');

		$('.cg'+cat).removeClass('second');
		$('.cg'+cat).addClass('second_e');
	});

	$('.cat_name_e').live('click', function(){
		var cat = $(this).attr('rel');
		$(this).attr('class', 'cat_name');

		$('.cg'+cat).removeClass('second_e');
		$('.cg'+cat).addClass('second');
	});

	$("body").mousemove(function(e){
		var x =e.pageX+15;
		$("#preloader").css('left',x);
		$("#preloader").css('top',e.pageY);

		$("#preloader2").css('left',x);
		$("#preloader2").css('top',e.pageY);
	});

	$('#left_menu a').mouseenter(function(){
		var slogan_id = $(this).attr('rel');

		if(slogan_id > 0)
		{
			$('#slogan_1').attr('style','display:none;');
			$('#slogan_'+slogan_id).attr('style','display:block;');
		}
	});

	$('#left_menu a').mouseleave(function(){
		var slogan_id = $(this).attr('rel');

		if(slogan_id > 0)
		{
			$('#slogan_'+slogan_id).attr('style','display:none;');
			$('#slogan_1').attr('style','display:block;');
		}
	});


	$('.tov_small_img').click(function(){
		var big_img_url = $(this).attr('rel');
		$('#tov_big_img').attr('src', 'gall/'+big_img_url).load(function() {
			document.getElementById('tov_big_img').src = 'gall/'+big_img_url;
			document.getElementById('tov_big_a').href = 'gall/'+big_img_url;
		});
	});


	$('.radio').click(function(){
		var classes = $(this).attr('class');
		var df = classes.split(' ');
		var value = $(this).attr('rel');
		var cur_value = $('.'+df[1]+'_value').attr('value');

		$('.'+df[1]).removeClass('active');
		if(df[2] == undefined) $(this).addClass("active");

		if(cur_value == value)
			$('.'+df[1]+'_value').attr('value', 0);
		else
			$('.'+df[1]+'_value').attr('value', value);
	});


	$('.param_search_link').click(function(){
		var new_action = $(this).attr('href');
		$('#search_form_param').attr('action', new_action);
		$('#search_form_param').submit();
		return false;
	});

	$('.add_to_bag').click(function(){
		var tov_id = $(this).attr('rel');
		var tov_col = $('.tov_col').attr('value');

		if(tov_col == 0 || tov_col == '')
			alert('Заполните поле количество');
		else
		{
			$('#preloader').css('display','block');

			$.get("addtocard.php", {'id': tov_id, 'count': tov_col, 'action': 'add'}, function(data){
				$('#preloader').css('display','none');
				$.get("addtocard.php", { 'action': 'count' }, function(data2){$('#tov_count').text("("+data2+")");});
			});
		}
		return false;
	});

	$('.add_to_live').click(function(){
		var tov_id = $(this).attr('rel');
		var tov_col = 1;

		if(tov_col == 0 || tov_col == '')
			alert('Заполните поле количество');
		else
		{
			$('#preloader2').css('display','block');

			$.get("addtolive.php", {'id': tov_id, 'count': tov_col, 'action': 'add'}, function(data){
				$('#preloader2').css('display','none');
				$.get("addtolive.php", { 'action': 'count' }, function(data2){$('#live_count').text("("+data2+")");});
				$('.live_').remove();
				$('.add_to_live').remove();
			});
		}
		return false;
	});

	$('.butot2').click(function() {
		if(jQuery("input[name=f_famili]").val() == ''){alert('Заполните поле Фамилия');return false;}
		if(jQuery("input[name=f_phone]").val() == ''){alert('Заполните поле Телефон');return false;}
		if(jQuery("textarea[name=f_adres]").val() == ''){alert('Заполните поле Адрес');return false;}
		$("#fo2rmsend").submit();
	});
	
	
	$("#ones1").click(function  () {
		if($('#ones2').attr('rel') == 1){
			$("#ones2_hid").css('display','none');
			$("#ones2").attr('style',' ');
			$("#ones2").attr('rel','0');
		}
		if($('#ones3').attr('rel') == 1){
			$("#ones3_hid").css('display','none');
			$("#ones3").attr('style',' ');
			$("#ones3").attr('rel','0');
		}
		if($('#ones4').attr('rel') == 1){
			$("#ones4_hid").css('display','none');
			$("#ones4").attr('style',' ');
			$("#ones4").attr('rel','0');
		}
		$("#ones0_hid").css('display','none');
		var zu = $(this).attr('rel');	
			if(zu == 1)
			{
				$("#ones1_hid").hide();
				$('#ones1').attr('rel','0');
			}
			else
			{
				$("#ones1_hid").show();
				$('#ones1').attr('rel','1');
				$('#ones1').attr('style','background: url("images/filters_radio.gif") left -12px no-repeat; color:#F26521; text-decoration: none;');
			}
	});
	
	$("#ones2").click(function  () {
		if($('#ones1').attr('rel') == 1){
			$("#ones1_hid").css('display','none');
			$("#ones1").attr('style',' ');
			$("#ones1").attr('rel','0');
		}
		if($('#ones3').attr('rel') == 1){
			$("#ones3_hid").css('display','none');
			$("#ones3").attr('style',' ');
			$("#ones3").attr('rel','0');
		}
		if($('#ones4').attr('rel') == 1){
			$("#ones4_hid").css('display','none');
			$("#ones4").attr('style',' ');
			$("#ones4").attr('rel','0');
		}
		$("#ones0_hid").css('display','none');
		var zu = $(this).attr('rel');	
			if(zu == 1)
			{
				$("#ones2_hid").hide();
				$('#ones2').attr('rel','0');
			}
			else
			{
				$("#ones2_hid").show();
				$('#ones2').attr('rel','1');
				$('#ones2').attr('style','background: url("images/filters_radio.gif") left -12px no-repeat; color:#F26521; text-decoration: none;');
			}
	});
	
	$("#ones3").click(function  () {
		if($('#ones1').attr('rel') == 1){
			$("#ones1_hid").css('display','none');
			$("#ones1").attr('style',' ');
			$("#ones1").attr('rel','0');
		}
		if($('#ones2').attr('rel') == 1){
			$("#ones2_hid").css('display','none');
			$("#ones2").attr('style',' ');
			$("#ones2").attr('rel','0');
		}
		if($('#ones4').attr('rel') == 1){
			$("#ones4_hid").css('display','none');
			$("#ones4").attr('style',' ');
			$("#ones4").attr('rel','0');
		}
		$("#ones0_hid").css('display','none');
		var zu = $(this).attr('rel');	
			if(zu == 1)
			{
				$("#ones3_hid").hide();
				$('#ones3').attr('rel','0');
			}
			else
			{
				$("#ones3_hid").show();
				$('#ones3').attr('rel','1');
				$('#ones3').attr('style','background: url("images/filters_radio.gif") left -12px no-repeat; color:#F26521; text-decoration: none;');
			}
	});
	
	$("#ones4").click(function  () {
		if($('#ones1').attr('rel') == 1){
			$("#ones1_hid").css('display','none');
			$("#ones1").attr('style',' ');
			$("#ones1").attr('rel','0');
		}
		if($('#ones2').attr('rel') == 1){
			$("#ones2_hid").css('display','none');
			$("#ones2").attr('style',' ');
			$("#ones2").attr('rel','0');
		}
		if($('#ones3').attr('rel') == 1){
			$("#ones3_hid").css('display','none');
			$("#ones3").attr('style',' ');
			$("#ones3").attr('rel','0');
		}
		$("#ones0_hid").css('display','none');
		var zu = $(this).attr('rel');	
			if(zu == 1)
			{
				$("#ones4_hid").hide();
				$('#ones4').attr('rel','0');
			}
			else
			{
				$("#ones4_hid").show();
				$('#ones4').attr('rel','1');
				$('#ones4').attr('style','background: url("images/filters_radio.gif") left -12px no-repeat; color:#F26521; text-decoration: none;');
			}
	});
	

});
