$(document).ready(function(){
	$(".box .close").html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    $(".menu li").corner("3px");
    $(".menu a").hover(function(){
       $(this).parent("li").addClass("hover").find(".arr").show();
    },function(){
       $(this).parent("li").removeClass("hover").find(".arr").hide();
    });
    /*$(".sbox").selectbox();
    $("select[name='doctor']").selectbox();*/

    $(".left,.right").hover(function(){
       $(this).addClass("hove");
    },function(){
       $(this).removeClass("hove");
    });

    $(".navi .item").hover(function(){
       $(this).addClass("hover");
    },function(){
       $(this).removeClass("hover");
    });
    $(".navi .item").click(function(){
	selector = $(this).attr("id");
	$(".navi a").removeClass("active");
	$(this).addClass("active");
	$(".slider .items").hide();
	$("."+selector).show();
	return false;
    });
    $(".navi .left").click(function(event){
	event.preventDefault();
	cur_item = $(".navi").find(".active");
	index = parseInt(cur_item.attr("index"));
	selector = "item"+(index-1);
	if($("."+selector).html().length>0) {
	    $(".navi a").removeClass("active");	    
	    $("#"+selector).addClass("active");
	    $(".slider .items").hide();
	    $("."+selector).show();
	}
	return false;
    });
    $(".navi .right").click(function(event){
	event.preventDefault();
	cur_item = $(".navi").find(".active");
	index = parseInt(cur_item.attr("index"));
	selector = "item"+(index+1);
	if($("."+selector).html().length>0) {
	    $(".navi a").removeClass("active");	    
	    $("#"+selector).addClass("active");
	    $(".slider .items").hide();
	    $("."+selector).show();
	}
    });
    
    $(".search-text").focus(function(){
	if($(this).val()=='Поиск') $(this).val('');
    });	
    $(".search-text").focusout(function(){
	if($(this).val()=='') $(this).val('Поиск');
    });	

    $(".speciality_title").hover(function(){
        $(this).addClass("hover");
    },function(){
        $(this).removeClass("hover");
    });
    
    $("#search-icon").click(function(){
       $(this).parents("form").submit();       
       return false;
    });

    $("a.ask_question, .ask_question .button").click(function(){
		$(".box.quest").css("margin-top",-($(".box.quest").height()/2)).show();
		$(".box.quest .select-btn").show();
       return false;
    });

    $('.jcalcont').jCal({
	day:			new Date(),
	days:			1,
	showMonths:		1,
	monthSelect:	false,
	callback:		function (day, days) {
						$("input[name='date']").val(day.getDate()+'.'+((day.getMonth()+1))+'.'+day.getFullYear());
                        $("input[name='date_h']").val(day.getDate()+'.'+(day.getMonth()+1)+'.'+day.getFullYear());
                        $(".date_name span").html(day.getDate()+'.'+(day.getMonth()+1)+'.'+day.getFullYear());
                        $('.jcalcont').hide();
		},
        dCheck: function (day) {
            if ( day.getTime() <= (new Date()).getTime() || day.getDay()==0)
                return 'invday';            
            else 
            return 'day';
            }
	});
    $('.cald').jCal({
	day:			new Date(),
	days:			1,
	showMonths:		1,
	monthSelect:	false,
	callback:		function (day, days) {
			$("input[name='date']").val(day.getDate()+'.'+(day.getMonth()+1)+'.'+day.getFullYear());
                        $("input[name='date_h']").val(day.getDate()+'.'+(day.getMonth()+1)+'.'+day.getFullYear());
                        $(".date_name span").html(day.getDate()+'.'+(day.getMonth()+1)+'.'+day.getFullYear());
                        $('.cald').hide();
		},
        dCheck: function (day) {
            if ( day.getTime() <= (new Date()).getTime() )
                return 'invday';
            else
            return 'day';
            }
	});
    $("#calendar").click(function(){
		$('.jcalcont').show();
		return false;
    });

    $(".serv").click(function(e){
       $(".appointment-box.servic-es").css("top",e.pageY-60+'px').show();
       return false;
    });
    $(".doc").click(function(e){
       $(".appointment-box.docto-rs").css("top",e.pageY-60+'px').show();
       return false;
    });
    $(".appointment-box-container td a").live("click",function(){
       $(this).parents("table").find(".active").removeClass("active");
       $(this).addClass("active");
	   $(".servic-es .submit").click();
	   $(".docto-rs .submit").click();
       return false;
    });
    $(".appointment-box .cancel").live("click",function(){
        $(".appointment-box table").find(".active").removeClass("active");
        $(".appointment-box").hide();
return false;
    });
    $(".servic-es .submit").live("click",function(){
        active = $(".appointment-box.servic-es table").find(".active");
        var inp_t = 'input[name="'+active.attr("rel")+'"]';
        var inp_h = 'input[name="'+active.attr("rel")+'_h"]';
        var inp_ta = 'input[name="'+active.attr("rel")+'a"]';
        var inp_ha = 'input[name="'+active.attr("rel")+'_ha"]';
        div_n = '.'+active.attr("rel")+'_name';
        $(div_n).find("span").html(active.text());
        $(inp_t).val(active.text());
        $(inp_h).val(active.text());
        $(inp_ta).val(active.text());
        $(inp_ha).val(active.attr("index"));
        $(".appointment-box").hide();
        if(active.attr("rel")=='service'){
            $.post(
                window.location.toString(),
                { ajax_doctor: 1, service_id:active.attr("index")},
                function(data){					
                    $(".doct-ors").html(data);
                    $(".appointment-box-container td a").corner("3px");
            });			
        }
        return false;
    });
    $(".docto-rs .submit").live("click",function(){
        active = $(".appointment-box.docto-rs table").find(".active");
        var inp_t = 'input[name="'+active.attr("rel")+'"]';
        var inp_h = 'input[name="'+active.attr("rel")+'_h"]';
        var inp_ta = 'input[name="'+active.attr("rel")+'a"]';
        var inp_ha = 'input[name="'+active.attr("rel")+'_ha"]';
        div_n = '.'+active.attr("rel")+'_name';
        $(div_n).find("span").html(active.text());
        $(inp_t).val(active.text());
        $(inp_h).val(active.text());
        $(inp_ta).val(active.text());
        $(inp_ha).val(active.attr("index"));
        $(".appointment-box").hide();        
        return false;
    });    

    $("a.appointment-btn").click(function(){
       $(".box.appointment").css("margin-top",-($(".box.appointment").height()/2)).show();       
       return false;
    });

    $("a.appointment-btn-doca").click(function(){
       $(".box.appointment").css("margin-top",-($(".box.appointment").height()/2)).show();
       dname = $(".doctor-personal h2.dtitlte").html();
       sname = $(".breadcrumbs li:last-child").html();
       $(".service_name span").html(sname);
       $(".service_name input").val(sname);
       $(".specialist_name span").html(dname);
       $(".specialist_name input").val(dname);
	   did = $("input[name='doc_id']").val();
	   sid = $("input[name='spec_id']").val();
		$(".box.appointment").find("input[name='specialist_ha']").val(did);		
		$(".box.appointment").find("input[name='service_ha']").val(sid);
       return false;
    });
	
	$("a.ask_question_doca").click(function(){		
		$(".box.quest").css("margin-top",-($(".box.quest").height()/2)).show();
		dname = $(".doctor-personal h2.dtitlte").text();
		did = $("input[name='doc_id']").val();
		sname = $(".breadcrumbs li:last-child").text();
		sid = $("input[name='spec_id']").val();
		$(".box.quest").find("input[name='servicea']").val(sname);		
		$(".box.quest").find("input[name='specialista']").val(dname);
		$(".box.quest").find("input[name='specialist_ha']").val(did);		
		$(".box.quest").find("input[name='service_ha']").val(sid);
		$(".box.quest .select-btn").hide();
		return false;
    });

    $(".map").click(function(){
       $(".map-container").css({"margin-top":-($(".map-container").height()/2),"top":"50%"}).show();
       return false;
    });

    $(".service-item-padding").corner("6px");
    $(".pagination .pages-list").corner("3px");
    $(".service-item2 a").corner("3px");
    $(".sections a").corner("3px");
    $(".speciality_title").corner("3px");
    $(".how-sort").corner("6px");
    $(".appointment-box-container td a").corner("3px");
    $(".jcalcont,.cald").corner("6px");
	
	/*$(".pagination ul").css("margin-left",-$(".pagination ul").width()/2+"px");*/
});
