function showSelectedMenu(){
	//console.log("showSelectedMenu");
	var itemClassName = '.current-menu-item';
	if($('.menu-header').children('.menu').children('.current-menu-item').width()>0){
		//console.log("fix current-menu-item");
		itemClassName = '.current-menu-item';	
	}else if($('.menu-header').children('.menu').children('.current-menu-parent').width()>0){
		//console.log("fix current-menu-parent");
		itemClassName = '.current-menu-parent';		
	}else if($('.menu-header').children('.menu').children('.current-post-ancestor').width()>0){
		//console.log("fix current-post-ancestor");
		itemClassName = '.current-post-ancestor';			
	}else if($('.menu-header').children('.menu').children('.current_page_ancestor').width()>0){
		//console.log("fix current_page_ancestor");
		itemClassName = '.current_page_ancestor';			
	}else if($('.menu-header').children('.menu').children('.current-page-ancestor').width()>0){
		//console.log("fix current-page-ancestor");
		itemClassName = '.current-page-ancestor';			
	}			
	$('.menu-header').children('.menu').children(itemClassName).children('.subme').css('margin-left', $('.menu-header').children('.menu').children(itemClassName).width() + 3 + 'px');
	$('.menu-header').children('.menu').children(itemClassName).children('.subme').show();
	$('.menu-header').children('.menu').children(itemClassName).children('.submd').show();		
}
$(document).ready(function() {

    $('.menu-item').hover(function(){
	//hover
	$(this).children('.sub-menu').show();

	$(this).children('.subme').css('margin-left', $(this).width() + 3 + 'px');

	if($(this).parent('.menu').hasClass('menu')) {
	    $(this).children('.subme').show();
	    $(this).children('.submd').show();
	}

	var submb = $(this).children('.sub-menu').children('.menu-item').width() - $(this).width()  + 14;
	//var wb = $(this).children('.sub-menu').width() - $(this).width() - 1;
	if(submb < 20) {submb = 20;}
	$(this).children('.sub-menu').children('.submb').width(submb);
	//console.log($(this).width() , $(this).children('.sub-menu').width(), $(this).children('.sub-menu').children('.menu-item').width());
	$(this).children('.sub-menu').children('.subma').width($(this).width());
	$(this).children('.sub-menu').children('.subma').css('padding-left', $(this).css('padding-left'));
	$(this).children('.sub-menu').children('.subma').css('padding-right', $(this).css('padding-right'));


	$(this).children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width());

	if (navigator.userAgent.toLowerCase().match('msie 7.0')) {
	    
		$(this).children('.sub-menu').children('.subma').width($(this).children('.sub-menu').children('.subma').width() - 1);

	    var submb = $(this).children('.sub-menu').children('.menu-item').width() - $(this).width() + 9 + 5;
	    if(submb < 20) {submb = 20;}
	    $(this).children('.sub-menu').children('.submb').width(submb);

	    $(this).children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').children('.submenu_sp_t').width());
	    $(this).children('.sub-menu').css('margin-left', $(this).width() * -1 - 13);
		
	}
	if (navigator.userAgent.toLowerCase().match('msie 8.0')) {
		$(this).children('.sub-menu').children('.submb').css('margin-left', '-2px');
		var submb = $(this).children('.sub-menu').children('.submb').width() + 2;
		if(submb < 20) {submb = 20;}
		$(this).children('.sub-menu').children('.submb').width(submb);
		$(this).children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width());
		//$(this).children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').children('.submenu_sp_t').width()+2);
		//$('.menu-header').children('.menu').children('.current-menu-item').children('.sub-menu').children('.submb').width($('.menu-header').children('.menu').children('.current-menu-item').children('.sub-menu').children('.submb').width() + 10);
		var itemClassName = '.current-menu-item';
		if($('.menu-header').children('.menu').children('.current-menu-item').width()>0){
			//console.log("fix current-menu-item");
			itemClassName = '.current-menu-item';	
		}else if($('.menu-header').children('.menu').children('.current-menu-parent').width()>0){
			//console.log("fix current-menu-parent");
			itemClassName = '.current-menu-parent';		
		}else if($('.menu-header').children('.menu').children('.current-post-ancestor').width()>0){
			//console.log("fix current-post-ancestor");
			itemClassName = '.current-post-ancestor';			
		}else if($('.menu-header').children('.menu').children('.current_page_ancestor').width()>0){
			//console.log("fix current_page_ancestor");
			itemClassName = '.current_page_ancestor';			
		}else if($('.menu-header').children('.menu').children('.current-page-ancestor').width()>0){
			//console.log("fix current-page-ancestor");
			itemClassName = '.current-page-ancestor';			
		}		
		$('.menu-header').children('.menu').children(itemClassName).children('.sub-menu').children('.submb').css('margin-left', '0px');		
		$('.menu-header').children('.menu').children(itemClassName).children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width()+0);				
		/*
		if($('.menu-header').children('.menu').children('.current-menu-item').width()>0){
			$('.menu-header').children('.menu').children('.current-menu-item').children('.sub-menu').children('.submb').css('margin-left', '0px');		
			$('.menu-header').children('.menu').children('.current-menu-item').children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width()+0);
		}else if($('.menu-header').children('.menu').children('.current-menu-parent').width()>0){
			$('.menu-header').children('.menu').children('.current-menu-parent').children('.sub-menu').children('.submb').css('margin-left', '0px');		
			$('.menu-header').children('.menu').children('.current-menu-parent').children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width()+0);			
		}else if($('.menu-header').children('.menu').children('.current-post-ancestor').width()>0){
			$('.menu-header').children('.menu').children('.current-post-ancestor').children('.sub-menu').children('.submb').css('margin-left', '0px');		
			$('.menu-header').children('.menu').children('.current-post-ancestor').children('.sub-menu').children('.submenu_sp_t').width($(this).children('.sub-menu').width()+0);			
		}		*/		
	}

    }, function(){
		//out
		$(this).children('.sub-menu').hide();
		$(this).children('.subme').hide();
		$(this).children('.submd').hide();

		$(this).children('.sub-menu').children('.subma').width(0);
		$(this).children('.sub-menu').children('.submb').width(0);
		$(this).children('.sub-menu').children('.submenu_sp_t').width(0);
		showSelectedMenu();
    });
    //-------------------------------------------------------------------------
	showSelectedMenu();
	//console.log($('.menu-header').children('.menu').children('.current-menu-item').width(),$('.menu-header').children('.menu').children('.current-menu-item').width()>0);
	//console.log($('.menu-header').children('.menu').children('.current-menu-item').width()>0, $('.menu-header').children('.menu').children('.current-menu-parent').width()>0);
	
    //-------------------------------------------------------------------------
	var post_1_height = $('#post_1').height();
	var post_2_height = $('#post_2').height();
	var post_3_height = $('#post_3').height();
	//console.log(post_1_height,post_2_height,post_3_height);
	var max = Math.max(post_1_height, post_2_height, post_3_height);
	var post_1_summary_height = max - $('#post_1').children('.post_title').height() - 57;
	$('#post_1').children('.post_summary_main').height(post_1_summary_height);
	
	var post_2_summary_height = max - $('#post_2').children('.post_title').height() - 57;
	$('#post_2').children('.post_summary_main').height(post_2_summary_height);	
	
	var post_3_summary_height = max - $('#post_3').children('.post_title').height() - 57;
	$('#post_3').children('.post_summary_main').height(post_3_summary_height);		
	/*
        var max = $('#post_1').children('.post_summary_main').height();
        if(max < $('#post_2').children('.post_summary_main').height()) {
	    max = $('#post_2').children('.post_summary_main').height();
        }
        if(max < $('#post_3').children('.post_summary_main').height()) {
	    max = $('#post_3').children('.post_summary_main').height();
        }
	max = max + 15;
        $('#post_1').children('.post_summary_main').height(max);
        $('#post_2').children('.post_summary_main').height(max);
        $('#post_3').children('.post_summary_main').height(max);
		*/
    //-------------------------------------------------------------------------
    $('#select_category_contact').click(function(){
	$("#select_person_contact_list").hide();
	$("#select_subject_contact_list").hide();
	if($("#select_category_contact_list").css('display') == 'none') {
	    $("#select_category_contact_list").show();
	} else {
	    $("#select_category_contact_list").hide();
	}
    });
    $('.category_name').click(function(){
	var id = $(this).attr('id');
	id = id.replace(/category_/gi, "");
	var old = $('#select_category_contact_selected').html();
	$('#select_category_contact_selected').html(id);
	$('#select_category_contact').html($(this).html());
	$("#select_category_contact_list").hide();
	if(old != $('#select_category_contact_selected').html()) {
	    var root_url = $('#root_url').html();
	    $.post(root_url + "/wp-admin/admin-ajax.php", {
		'action': 'a_bar',
		'cat_id': id
	    }, function(r){
		$('#bar_posts').html(r);
	    });
	}
    });
    $("#select_category").mouseleave(function(){
	$("#select_category_contact_list").hide();
	$("#select_category_contact_list").mouseenter(function(){
	    $("#select_category_contact_list").show();
	})
    });
    $("#select_category_contact_list").mouseleave(function(){
	$("#select_category_contact_list").hide();
    });
    //-------------------------------------------------------------------------
    $('#main_learn_more').click(function(){
	var id = $('#select_person_contact_selected').html();
	if(id != '') {
	    var slug = $('#js_slug_zespol').html();
	    var param = "?&id=";
	    var url = slug +"/" + param;
	    var t = id.split('_');
	    id = t[0];
	    document.location = url + id;
	}
    });
    $('#select_person_contact').click(function(){
	$("#select_subject_contact_list").hide();
	$("#select_category_contact_list").hide();

	var ida = $('#select_subject_contact_selected').html();
	var list = "";
	if(ida != '') {
	    list = "#select_person_contact_list_specialization_" + ida;
	} else {
	    list = "#select_person_contact_list";
	}

	if($(list).css('display') == 'none') {
	    $(list).show();
	} else {
	    $(list).hide();
	}

	$("#select_person_contact").mouseleave(function(){
	    $(list).hide();
	    $(list).mouseenter(function(){
		$(list).show();
	    })
	});
	$(list).mouseleave(function(){
	    $(list).hide();
	});
    });
    $('.person_name').click(function(){
	var id = $(this).attr('id');
	id = id.replace(/person_/gi, "");
	$('#select_person_contact_selected').html(id);
	var v = $(this).html();
	var maxLen = 25;
	if(v.length >maxLen) {
	    v = v.substr(0,maxLen-3);
	    v = v + "...";
	}
	$('#select_person_contact').html(v);
	$("#select_person_contact_list").hide();
    });
    //-------------------------------------------------------------------------
    $('#main_contact_an_attorney').click(function(){
	var id = $('#select_subject_contact_selected').html();
	var idp = $('#select_person_contact_selected').html();
	var t = idp.split('_');
	idp = t[0];
	if(idp != '') {
	    var slug = $('#js_slug_kontakt').html();
	    var param = "?type=specialization&id=" + id + "&pe=" + idp;
	    var url = slug +"/" + param;
	    document.location = url;
	}
    });
    $('#select_subject_contact').click(function(){
	$('#select_person_contact').html($('#select_person_contact_default').html());
	$('#select_person_contact_selected').html('');
	$("#select_person_contact_list").hide();
	$("#select_category_contact_list").hide();
	if($("#select_subject_contact_list").css('display') == 'none') {
	    $("#select_subject_contact_list").show();
	} else {
	    $("#select_subject_contact_list").hide();
	}
    });
    $('.subject_name').click(function(){
	var id = $(this).attr('id');
	id = id.replace(/specialization_/gi, "");
	$('#select_subject_contact_selected').html(id);
	var v = $(this).html();
	var maxLen = 25;
	if(v.length >maxLen) {
	    v = v.substr(0,maxLen-3);
	    v = v + "...";
	}
	$('#select_subject_contact').html(v);
	$("#select_subject_contact_list").hide();

    });
    $("#select_subject_contact").mouseleave(function(){
	$("#select_subject_contact_list").hide();
	$("#select_subject_contact_list").mouseenter(function(){
	    $("#select_subject_contact_list").show();
	})
    });
    $("#select_subject_contact_list").mouseleave(function(){
	$("#select_subject_contact_list").hide();
    });
    //-------------------------------------------------------------------------
    $('#contact_form_subject_form').click(function(){
	if($('#contact_form_subject_form').val() == $('#contact_form_subject_form_default').html()) {
	    $('#contact_form_subject_form').val("");
	}
    });
    //-------------------------------------------------------------------------
    $('#contact_form_name_form').click(function(){
	if($('#contact_form_name_form').val() == $('#contact_form_name_form_default').html()) {
	    $('#contact_form_name_form').val("");
	}
    });
    //-------------------------------------------------------------------------
    $('#contact_form_email_form').click(function(){
	if($('#contact_form_email_form').val() == $('#contact_form_email_form_default').html()) {
	    $('#contact_form_email_form').val("");
	}
    });
    //-------------------------------------------------------------------------
    $('#contact_form_message_form').click(function(){
	if($('#contact_form_message_form').val() == $('#contact_form_message_form_default').html()) {
	    $('#contact_form_message_form').val("");
	}
    });
    //-------------------------------------------------------------------------
    function email_validate(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(src);
    }
    $('#contact_form_linksend').click(function(){

	$('#select_person_contact_error').hide();
	$('#select_email_contact_error').hide();
	$('#select_subject_contact_error').hide();
	$('#select_name_contact_error').hide();
	$('#select_message_contact_error').hide();
	$('#com_send').hide();

	var osoba = $('#select_person_contact_selected').html();
	var osoba = osoba.split('_');
	osoba = osoba[0];
	var temat = $('#select_subject_contact_selected').html();
	var tytul = $('#contact_form_subject_form').val();
	var imie = $('#contact_form_name_form').val();
	var email = $('#contact_form_email_form').val();
	var wiadomosc = $('#contact_form_message_form').val();

	var error = false;

	if(osoba == "") {
	    $('#select_person_contact_error').show();
	    error = true;
	}
	if(tytul == "" || tytul == $('#contact_form_subject_form_default').html()) {
	    $('#select_subject_contact_error').show();
	    error = true;
	}
	if(wiadomosc == "" || wiadomosc == $('#contact_form_message_form_default').html()) {
	    $('#select_message_contact_error').show();
	    error = true;
	}
	if(imie == "" || imie == $('#contact_form_name_form_default').html()) {
	    $('#select_name_contact_error').show();
	    error = true;
	}
	if(email == "") {
	    $('#select_email_contact_error').show();
	    error = true;
	}
	if(!email_validate(email)) {
	    $('#select_email_contact_error').show();
	    error = true;
	}

	if(!error) {
	    var root_url = $('#root_url').html();
	    $.post(root_url + "/wp-admin/admin-ajax.php", {
		'action': 'a_sendmail',
		'IdOsoba': osoba,
		'IdSpecjalizacja': temat,
		'Tytul': tytul,
		'Nadawca': imie,
		'Email': email,
		'Wiadomosc': wiadomosc
	    }, function(r){
		$('#com_send').show();
	    });
	}
    });
//-------------------------------------------------------------------------

});

