var obj = null;
var clicked1 = false;
var clicked2 = false;


function hs_init() { //  highslide
                hs.graphicsDir = 'js/highslide/graphics/';
                hs.expandCursor = 'zoomin.cur'; // null disables
                hs.restoreCursor = 'zoomout.cur'; // null disables
                hs.expandDuration = 250; // milliseconds
                hs.restoreDuration = 250;
                hs.marginLeft = 15;
                hs.marginRight = 15;
                hs.marginTop = 15;
                hs.marginBottom = 15;
                hs.zIndexCounter = 1001; // adjust to other absolutely positioned elements
                hs.loadingOpacity = 0.55;
                hs.allowMultipleInstances= true;
                hs.numberOfImagesToPreload = 5;
                hs.outlineWhileAnimating = 2; // 0 = never, 1 = always, 2 = HTML only
                hs.outlineStartOffset = 3; // ends at 10
                hs.padToMinWidth = false;
                hs.fullExpandPosition = 'left center';
                hs.showCredits = true;
                hs.creditsHref = 'www.pulset.ru';
                hs.align = 'center';
                hs.transitions = ['expand', 'crossfade'];
                hs.fadeInOut = true;
                hs.width = 338;
                //hs.wrapperClassName: 'dark';
                hs.lang = {cssDirection:'ltr', loadingText : 'Loading...', loadingTitle : 'Click to cancel', focusTitle : '   ', fullExpandTitle : 'Expand to real size (f)', creditsText : 'www.pulset.ru', creditsTitle : 'PULSET', previousText : '<<', nextText : '>>', moveText : 'Move', closeText : 'Close', closeTitle : 'Close (Esc)', resizeTitle : 'Resize', playText : 'Auto', playTitle : 'Slideshow ()', pauseText : 'Pause', pauseTitle : '  ()', previousTitle : 'Back', nextTitle : 'Next', moveTitle : 'Move window', fullExpandText : 'Full size', number: 'Photo %1 of %2', restoreTitle : 'Click on picture to close the window. Hold the mouse button to move the window.'};
        }

		function tovarExp(obj, id) {
        	var ret = hs.htmlExpand(obj, {contentId:id});
            //jQuery('#PicName').html(jQuery('#name').html());
            //jQuery('#PicNameData').attr('value', jQuery('#name').html());
            //changeSrc(1);
            return ret;
        }

        function uslugaExp(obj, id) {
        	var ret = hs.htmlExpand(obj, {contentId:id});
            //jQuery('#PicName').html(jQuery('#name').html());
            //jQuery('#PicNameData').attr('value', jQuery('#name').html());
            //changeSrc(1);
            return ret;
        }

		function widesearch() {
			document.getElementById( 'searchfields' ).style.display = 'none';
			document.getElementById( 'widesearch' ).style.display = 'block';
			jQuery("#widesearch").css("display","block");
			params = {
			refreshEl: "#country, #region_f1, #id_city, #tmark, #pptype, #typeusl_0, #typeusl", /* перечисляем через запятую id селектов, которые нужно обновить */
			visRows: 6
			}
			cuSelRefresh(params);
		}
		function narrowsearch() {
			document.getElementById( 'searchfields' ).style.display = 'block';
			document.getElementById( 'widesearch' ).style.display = 'none';
			jQuery("#searchfields").css("display","block");
			params = {
			refreshEl: "#easy_country, #easy_region_f1, #easy_id_city, #easy_tmark, #easy_pptype, #easy_typeusl_0, #easy_typeusl", /* перечисляем через запятую id селектов, которые нужно обновить */
			visRows: 6
			}
			cuSelRefresh(params);
		}

		function changeSearch() {

		 	var search = $('.searchtext').attr('value');

		 	if(search == 'Что искать?') {
		 	var ansSearch = '';
		 	}
		 	if(search == '') {
		 	var ansSearch = 'Что искать?';
		 	}

			alert();

		 	$('.searchtext').attr('value') = ''+ansSearch+'';

		}

function closes()
{
	$('.b_close a').click(
		function(){
			$(this).parent().parent().remove();
			return false;
	});
}

function fn()
{
	obj.fadeOut(200);
	var id = obj.attr("id");
	var but_id = id.substring(0, id.length-5);
	$('#'+but_id).show();
	$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
	$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
	$('.service_item').removeClass('a_service_item');
}

$(document).ready(function(){


	// from body direct.html


	$('.gal_content').jCarouselLite({
                    btnNext: ".right_but",
                    btnPrev: ".left_but",
                    mouseWheel: true,
                    visible: 7,
                    circular: true,
                    scroll: 7,
                    way_back: true
                });

				$('#region_select').click(
					function() {

						if($('#reg_select').css('display')=='block') {

						 	$('#reg_select').hide();
							$('#below_regs').hide();
						}
						else {
						$('#reg_select').show();
						var hh = $('html').attr('clientHeight') || $('html').attr('offsetHeight');
		                if ($('html').attr('scrollHeight') > hh) {
		                    hh = $('html').attr('scrollHeight');
		                    hh = hh + 20;
		                }
                        $('#below_regs').css({height: hh + 'px'});

						//$('#below_regs').css(height:hh+'px');

                        $('#below_regs').show();
                        }
					}
				);

				$('#below_regs').click(
					function() {

						$('#reg_select').hide();
						$('#below_regs').hide();

					}
				);



				$('#close_reg').click(
					function() {

						$('#reg_select').hide();
						$('#below_regs').hide();

					}
				);

                $('.gal_item a img').hover(
					function(){
						$(this).stop().fadeTo('fast',0.5);
					},
					function(){
					    $(this).stop().fadeTo('fast',1);
					}
				);


                $(".list div a").click(function(){
				    $("#popup").each(function(){
							$(this).remove();
					});
			 		var num = $(this).attr('num');
			   		document.getElementById( 'd'+num ).innerHTML = '<div id="popup"></div>';
		      		$("#bovk").clone(true).appendTo("#popup");
		    	});

				$(".b_close img").click(function(){
					$("#popup").each(function(){
						$(this).remove();
					});
				});
				hs_init();
				//hs.outlineType = 'glossy-dark';
	            hs.wrapperClassName = 'dark';
	            hs.dimmingOpacity = 0.45;


	//для услуг

	$(".list2 div span a").click(function(){
	  $("#popup").each(function(){
				$(this).remove();
			});

	  var num1 = $(this).attr('num1');
	  document.getElementById('u'+num1).innerHTML = '<div id="popup" style="margin-left:12px;"></div>';
      $("#bovk").clone(true).appendTo("#popup");
    });

	$("#openall").click(function(){
	  $("#popup").each(function(){
				$(this).remove();
			});
	  $(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if(num)
				{
					document.getElementById( 'sm'+num ).style.display = 'block';
					$(this).addClass('act');
				}
			});
		document.getElementById( 'openall' ).style.display = 'none';
		document.getElementById( 'closeall' ).style.display = 'block';

    });

	$("#closeall").click(function(){
	  $("#popup").each(function(){
				$(this).remove();
			});
	  $(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if(num)
				{
					document.getElementById( 'sm'+num ).style.display = 'none';
					$(this).removeClass('act');
				}
			});
		document.getElementById( 'openall' ).style.display = 'block';
		document.getElementById( 'closeall' ).style.display = 'none';

    });
	//$('body').pngFix( );

	//if($('#serv_cont').height() < 600) $('#serv_cont').height(600);

/*	$('#s_about_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_about1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_about.png'); }
	);
	$('#s_control_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_control1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_control.png'); }
	);
	$('#s_publicity_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_publicity1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_publicity.png'); }
	);
	$('#s_clients_pic').hover(
		function(){ $(this).attr('src', 'img_n/pic_search_clients1.png'); },
		function(){ $(this).attr('src', 'img_n/pic_search_clients.png'); }
	);*/

	$('.tab a').hover(
		function(){
			$(this).css('color', '#699C00');
			$(this).parent().css({'background': 'url(images/left/tab_bg.gif) repeat-x 0px -10px', 'background-color':'#F9F9FA'});
			$(this).parent().prev().css({'background-color':'#DDDFE1'});
			$(this).parent().prev().children().attr('src','images/left/emp.gif');
			$(this).parent().next().css({'background-color':'#DDDFE1'});
			$(this).parent().next().children().attr('src','images/left/emp.gif');
		},
		function(){
			$(this).css('color', '#666666');
			$(this).parent().css({'background': 'url(images/left/tab_bg.gif) repeat-x 0px 0px', 'background-color':'#F9F9FA'});
			$(this).parent().prev().css({'background-color':'#ffffff'});
			$(this).parent().prev().children().attr('src','images/left/tab_l.gif');
			$(this).parent().next().css({'background-color':'#ffffff'});
			$(this).parent().next().children().attr('src','images/left/tab_l.gif');
		}
	);

	$('.b_search').hover(
		function(){ $(this).attr('src', 'images/left/b_search1.png'); },
		function(){ $(this).attr('src', 'images/left/b_search.png'); }
	);
	$('.b_search').click(
		function(){
			if (($('#qwe').val()=='') || ($('#qwe').val()=='Что искать:')) {
				alert('Не задано значение для поиска!');
				$('#qwe').focus();
				return false;
			}
			else {
				$('#loading').show();
				return true;
			}
	});


	$('.b_search2').hover(
		function(){ $(this).attr('src', 'images/left/b_search1.png'); },
		function(){ $(this).attr('src', 'images/left/b_search.png'); }
	);
	$('.b_search2').click(
		function(){
			if (($('#qwe2').val()=='') || ($('#qwe2').val()=='Что искать:')) {
				alert('Не задано значение для поиска!');
				$('#qwe2').focus();
				return false;
			}
			else {
				$('#loading').show();
				return true;
			}
	});


	$(document).ready(
		function(){
			$('.b_search').attr('src', 'images/left/b_search.png');
			$('.b_search2').attr('src', 'images/left/b_search.png');
			$('#b_login').attr('src', 'images/left/b_login.png');
			$('#b_login2').attr('src', 'images/left/b_login.png');
	});


	$('#qwe').click(
		function(){
			if(!clicked1)
			{
				$(this).val('');
				clicked1 = true;
			}
	});
	$('#qwe2').click(
		function(){
			if(!clicked2)
			{
				$(this).val('');
				clicked2 = true;
			}
	});

	$('#qwe2').keyup(
		function(){
			$('#te_type').empty();
			$('#te_type').append($(this).val());
	});

	$('#region_f1').click(
		function(){
			$('#re_type').empty();
			$('#re_type').append('Россия, '+$('#region_f1 option:selected').text());
	});

	$('#tmark').click(
		function(){
			$('#utt_type').empty();
			$('#utt_type').append('Товары: '+$('#tmark option:selected').text());
	});

	$('#typeusl_0').click(
		function(){
			$('#utt_type').empty();
			$('#utt_type').append('Услуги: '+$('#typeusl_0 option:selected').text());
	});

	$('.service_item').hover(
		function(){
			id = $(this).attr("id");
			if($('#'+id+'_info').css('display')!='block')
			{
				$('#'+id+'_pic').attr('src', 'images/left/'+id+'1.png');
				$("a", this).each(function(){
					$(this).addClass('hov');
				});
			}
		},
		function(){
			id = $(this).attr("id");
			$('#'+id+'_pic').attr('src', 'images/left/'+id+'.png');
			$("a", this).each(function(){
				$(this).removeClass('hov');
			});
		}
	);

	$('.service_item').click(
		function(){
			//?ane?uaaai
			if(!$(this).hasClass('a_service_item'))
			{
				var item = $(this);
				$('.service_item').each(function(){
					if( $(this).attr('id') != item.attr('id')) $(this).hide();
				});
				$(this).animate({"top":"-70px"}, 400, "linear", function(){
																	$(this).addClass('a_service_item');
																	$('#meta').animate({'top':$('#'+item.attr('id')+'_info').attr('clientHeight')-270},400,"linear");
																}
				);
				$('#'+item.attr('id')+'_info').fadeIn(400);
			}
/*			else// cae?uaaai
			{
				$('.serv_info_table').fadeOut(200);
				var but_id = $(this).attr("id");
				$('#'+but_id).show();
				$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
				$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
				$('.service_item').removeClass('a_service_item');
			}*/

			return false;
		}
	);

/*	$('.serv_info_table').hover(
		function(){},
		function(){ obj = $(this); setTimeout( 'fn();', 1500);
	});*/


	$('.b_hide_text').click(
		function(){
			$('.serv_info_table').fadeOut(200);
			var but_id = $(this).attr("id");
			$(but_id).show();
			$('#s_about').animate({"top":"-17px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_control').animate({"top":"120px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_publicity').animate({"top":"300px"}, 400, "linear", function(){$('.service_item').show();});
			$('#s_search_clients').animate({"top":"465px"}, 400, "linear", function(){$('.service_item').show();});
			$('.service_item').removeClass('a_service_item');
			$('#meta').css({'top':'305px'});
	});



	$('#tab1 a').click(
		function(){
			$('#atab1').show();
			$('#tab1').hide();
			$('#tab2').show();
			$('#atab2').hide();
			$('#atab3').hide();
			$('#tab3').show();

			$('#search_block').show();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').hide();
			$('#sale_block2').hide();
			$('#sale_block3').hide();
			$('#sale_block4').hide();

			return false;
	});

	$('#tab2 a').click(
		function(){
			$('#atab1').hide();
			$('#tab1').show();
			$('#tab2').hide();
			$('#atab2').show();
			$('#atab3').hide();
			$('#tab3').show();

			$('#search_block').hide();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').show();
			$('#sale_block2').show();
			$('#sale_block3').hide();
			$('#sale_block4').hide();

			return false;
	});

	$('#tab3 a').click(
		function(){
			$('#atab1').hide();
			$('#tab1').show();
			$('#atab2').hide();
			$('#tab2').show();
			$('#atab3').show();
			$('#tab3').hide();

			$('#search_block').hide();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#sale_block').hide();
			$('#sale_block2').hide();
			$('#sale_block3').show();
			$('#sale_block4').show();

			return false;
	});


	$('.wide_search').click(
		function(){
			$('#search_block').hide();
			$('#wide_search_block').show();
			$('#wide_search_block2').show();
			$('#bsearch').pngFix();
			$('#bsearch2').pngFix();

			return false;
	});

	$('.back_tosearch').click(
		function(){
			$('#search_block').show();
			$('#wide_search_block').hide();
			$('#wide_search_block2').hide();
			$('#bsearch').pngFix();
			$('#bsearch2').pngFix();

			return false;
	});

	$('input[type=radio]').click(
		function(){
			var n = $(this).attr('name');
			var val = $(this).attr('value');
			if( (n=="type")&&((val=="1")||(val=="2")||(val=="3"))||(val=="4") )
			{
				$('#wshr').show();
				$('#ws_sh').show();
				$('#ws_opt').show();
				$('#ws_pro').show();
				$('#wtov1').show();
				$('#wtov2').show();
				$('#wuss1').hide();
				$('#wuss2').hide();

				$('#sh_type').empty();
				$('#sh_type1').show();
				if (val=='3') {	$('#sh_type').append('В описании товаров');	}
				if (val=='1') {	$('#sh_type').append('В названии организации - товары');	}
				if (val=='2') {	$('#sh_type').append('В адресе организации - товары');	}
				if (val=='4') {	$('#sh_type').append('В ФИО руководителя - товары');	}

				$('#utt_type').empty();
				$('#utt_type').append('Товары: '+$('#tmark option:selected').text());
			}
			if( (n=="type")&&((val=="5")||(val=="6")||(val=="7"))||(val=="8") )
			{
				$('#wshr').hide();
				$('#ws_sh').hide();
				$('#ws_opt').hide();
				$('#ws_pro').hide();
				$('#wtov1').hide();
				$('#wtov2').hide();
				$('#wuss1').show();
				$('#wuss2').show();

				$('#sh_type').empty();
				$('#sh_type1').hide();
				if (val=='5') {	$('#sh_type').append('В описании услуг');	}
				if (val=='6') {	$('#sh_type').append('В названии организации - услуги');	}
				if (val=='7') {	$('#sh_type').append('В адресе организации - услуги');	}
				if (val=='8') {	$('#sh_type').append('В ФИО руководителя - услуги');	}

				$('#utt_type').empty();
				$('#utt_type').append('Услуги: '+$('#typeusl_0 option:selected').text());
			}

			if( (n=="ptype")&&(val=="ro") )
			{
				$('#sh_type1').empty();
				if (val=='ro') { $('#sh_type1').append(', магазины');	}
			}
			if( (n=="ptype")&&(val=="op") )
			{
				$('#sh_type1').empty();
				if (val=='op') { $('#sh_type1').append(', оптовые компании');	}
			}
			if( (n=="ptype")&&(val=="pr") )
			{
				$('#sh_type1').empty();
				if (val=='pr') { $('#sh_type1').append(', производство'); }
			}




	});


	$('.list div a').click(
		function(){
			$("#popup").each(function(){
				$(this).remove();
			});

/*			$('#d'+num).html('<div class="pop_block"><div class="b_close">Iiai?aeoa, eaao caa?ocea ...</div></div>');
*/
			var num = $(this).attr('num')

			jQuery.ajax({url:'out_tov1.php', type:'get', data:'tmark='+num, success:function(data){ $('#d'+num).html(data); } });
			closes();
			return false;
	});

	$('.list2 div a').click(
		function(){
			var num = $(this).attr('num');
			if($('#sm'+num).css('display')=='none')
			{
				$('#sm'+num).show(300);
				$(this).addClass('act');
			}
				else
				{
					$('#sm'+num).hide(300);
					$(this).removeClass('act');
				}
			return false;
	});

	/*$('.list2').hover(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='none')
				{
					$('#sm'+num).show(300);
					$(this).addClass('act');
				}
			});
			$('#open_all_block').hide();
			$('#close_all_block').show();
			return false;
	},
		function(){}
	);*/


	$('#open_all_block').click(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='none')
				{
					$('#sm'+num).show(300);
					$(this).addClass('act');
				}
			});
			$('#open_all_block').hide();
			$('#close_all_block').show();
			return false;
	});


	$('#close_all_block').click(
		function(){
			$(".list2 div a").each(function(){
				var num = $(this).attr('num');
				if($('#sm'+num).css('display')=='block')
				{
					$('#sm'+num).hide(300);
					$(this).removeClass('act');
				}
			});
			$('#open_all_block').show();
			$('#close_all_block').hide();
			return false;
	});


	$('#region_f').change(
		function(){

		var num1=$('#region_f').val();
/*	    alert('Auai? naaeai!'+num1);*/
		jQuery.ajax({url:'out_sel_1.php', type:'get', data:'id_region='+num1, success:function(data){ $('#u_city').html(data); } });
		return false;
	});

	$('#region_f1').change(
		function(){
		var num1=$('#region_f1').val();
		jQuery.ajax({url:'out_sel_1.php', type:'get', data:'id_region='+num1+'&tp=2', success:function(data){ $('#u_city1').html(data); } });
		return false;
	});

	$('#tmark').change(
		function(){
		var num1=$('#tmark').val();
		jQuery.ajax({url:'out_tov_1.php?tmark=', type:'get', data:'tmark='+num1, success:function(data){ $('#out_tov').html(data); } });
		return false;
	});

	$('#typeusl_0').change(
		function(){
		var num1=$('#typeusl_0').val();
		jQuery.ajax({url:'out_usl_1.php?typeusl_0=', type:'get', data:'typeusl_0='+num1, success:function(data){ $('#out_usl').html(data); } });
		return false;
	});


	$('.list2 div span a').click(
		function(){
			$("#popup").each(function(){
				$(this).remove();
			});

			var num1 = $(this).attr('num1')
			jQuery.ajax({url:'out_uss1.php', type:'get', data:'id_typeusl_0='+num1, success:function(data){ $('#u'+num1).html(data); } });

			closes();
			return false;
	});

	$('#qwe').click(
		function(){
			$('#where_search').show();
		}
	);


});



