$(document).ready(function() {

        $('#slider').cycle({
	    fx:      'scrollUp',
	    speed:    1000,
	    pause : 1,
	    timeout:  5000
		});


        $('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		//$('#mask').fadeIn(1000);
		//$('#mask').fadeTo("slow",0.8);
        $('#mask').css("display", "block").fadeTo("fast",0.8);

		//Get the window height and width
		var winH = $(document).height();
		var winW = $(document).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(1000);

	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		$('#mask').hide();
		$('.window').hide();
	});
        $('#showaddask').click(function () {
		$('.ask_l').slideToggle();
	});
        $('#send_ask').click(function () {
                var vl=$('input[name=youname]').val();
                var vn=$('textarea[name=asktext]').val();
                
                if(vl=="Ваше имя" || vn=="Текст вопроса" || $('input[name=iman]').is(':checked')==false) alert('Заполните поля');
		else document.formmail.submit()
	});
        
        $("input[name=youname]").focus(function () {
            if($(this).val()=="Ваше имя") $(this).attr("value","");
            return false;
        }).focusout(function() {
            if($(this).val()=="") $(this).attr("value","Ваше имя").blur();
        });
        $("textarea[name=asktext]").focus(function () {
            if($(this).val()=="Текст вопроса") $(this).attr("value","");
            return false;
        }).focusout(function() {
            if($(this).val()=="") $(this).attr("value","Текст вопроса").blur();
        });
        
        $("textarea[name=otvtext]").focus(function () {
            if($(this).val()=="Текст ответа") $(this).attr("value","");
            return false;
        }).focusout(function() {
            if($(this).val()=="") $(this).attr("value","Текст ответа").blur();
        });


	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});






	  $("#searchcat").click(function(){
			$("#div_searchcat").slideToggle(400);
	  });
      $("div.newsdates:first").show();
	  $("div.news_date").click(function(){
		$(this).next(".newsdates").slideToggle(500).siblings(".newsdates:visible").slideUp("fast");
		$(this).toggleClass("news_date_active");
        $(this).siblings(".news_date").removeClass("news_date_active");
	 });


	  $("#authc").click(function(){
			$("#div_authc").slideToggle(400);
	  });
	  $("#close_searchcat").click(function(){
			$("#div_searchcat").slideToggle(400);
	  });
	  $("#close_authc").click(function(){
			$("#div_authc").slideToggle(400);
	  });

       $("select#rubr").change(function () {

          $("select#rubr option:selected").each(function () {

			if($(this).attr("value")>0)
			{
				$("#content_pr").empty().html('<img src="/images/loader.gif"> загрузка...');

				$.get("/get_pr.php", { r: $(this).attr("value") },
				 function(data){
				   $("#content_pr").empty().html(data);
				  });

			}
              });

        }) ;
        $("select#regg").change(function () {

          $("select#regg option:selected").each(function () {

			if($(this).attr("value")>0)
			{
				$("#content_city").empty().html('<img src="/images/loader.gif"> загрузка...');

				$.get("/get_city.php", { r: $(this).attr("value") },
				 function(data){
				   $("#content_city").empty().html(data);
				  });

			}
              });

        }) ;

      $("select#sel_searchcat").change(function () {

          $("select#sel_searchcat option:selected").each(function () {

			if($(this).attr("value")>0)
			{
				$("#typesservice").empty().html('<img src="/images/loader.gif"> загрузка...');

				$.get("/adr_inf_prop.php", { city: $(this).attr("value") },
				 function(data){
				   $("#typesservice").empty().html(data);
				  });

			}
              });

        }) ;

       $("select#vv").change(function () {

          $("select#vv option:selected").each(function () {

			if($(this).attr("value")>0)
			{
				$("#view").empty().html('<img src="/images/loader.gif"> загрузка...');

				$.get("/calc.php?type=1&", { v: $(this).attr("value") },
				 function(data){
				   $("#view").empty().html(data);
				  });

			}
              });

        }) ;



  });
 function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function confirmPoll(url){
	var agree = confirm('Подтверждаете выбор?');
	if (agree){
	document.location=url;
	}
	}
