$(function() {
    
    /* input focus */
    $('input[type="text"]').focus(function() {  
        if (this.value == this.defaultValue){ this.value = ''; }  
    });

    if($('#bmi').length > 0){
    
        $('#bmi').click(function() {
    	     
             var vyska = $('#vyska').val() / 100;
            
             var bmi = $('#vaha').val() / Math.pow(vyska, 2);
               
             var bmiFixed = bmi.toFixed(2);
    
             var vysl = parseFloat(bmiFixed);
    
             if(vysl <= 18.5){
                $('.vysledek').hide();
                $('#vysl1').show(); 
             } 
             if((vysl > 18.5) && (vysl <= 24.9)){  
                $('.vysledek').hide();
                $('#vysl2').show();   
             } 
             if((vysl >= 25) && (vysl <= 29.9)){  
                $('.vysledek').hide();
                $('#vysl3').show();   
             } 
             if((vysl >= 30) && (vysl <= 34.9)){  
                $('.vysledek').hide();
                $('#vysl4').show();   
             } 
             if((vysl >= 35) && (vysl <= 39.9)){  
                $('.vysledek').hide();
                $('#vysl5').show();   
             } 
             if(vysl >= 40){    
                $('.vysledek').hide();
                $('#vysl6').show(); 
             }
             
             
             $('.vysledek h2 span').html(vysl);
             
        }); 
    }
    /* specialization */
    $('.sNavigation li.open ul').slideDown("slow");
        
    $('.sNavigation li:last').css('background', 'none');
    $('.sNavigation li:has(ul)').addClass('close');
    $('.sNavigation li:has(ul) span').click(function() {
            if($(this).parent().hasClass('open') == true){
                $(this).parent().removeClass('open');
                $(this).html('+');
                $(this).parent().addClass('close');
                $(this).parent().find('ul').slideUp("slow");
            }else{
                $(this).parent().addClass('open');
                $(this).html('-');
                $(this).parent().removeClass('close');
                $(this).parent().find('ul').slideDown("slow");
            }
    });
    
    /* datepicker */
    $("#calendar").datepicker(  
        { 
        showOtherMonths: true,
        firstDay: 1,
        
        onSelect: function(dateText, inst) 
        { 
             den = dateText;
             den = den.replace(/\./g, "");
             den = 'div.day'+den;
             
             
            
             
             $(den).show('slow');
             
            
        },
        
        beforeShowDay: function(date)
        {
            //alert(date);
            var formated_date = $.datepicker.formatDate( "ddmmyy", date ); 
            formated_date = '.day'+formated_date;
            
            //alert(formated_date);
            var is_akce = $(formated_date);
            //alert(is_akce);
            if (is_akce.length)
            { 
                return [1, 'high','Klikněte pro zobrazení detailu události.'];
            }
            else
            {
                return [1, '',''];
            }
        }

        
        
             
        },
        $.datepicker.regional['cs']
    );
    $("input.date").datepicker(
        {
        showOtherMonths: true,
        firstDay: 1,
        showOn: 'button',
        buttonImage: 'img/calendar/calendar.gif',
        buttonImageOnly: true

        },
        $.datepicker.regional['cs']
    );

    /* fancybox */
    $(".gallery a").fancybox();

    /* other */
    $('table tr:even').addClass('even');
    $('.workPlaceItem:odd').addClass('odd');
    $('.linkItem:odd').addClass('odd');
    $('.commentWrap:odd').addClass('odd');
    $('.gallery a:first').css('margin', '0');
    $('.sNavigation ul li:first').css('background', 'none');
    $('.tabsWrap .tabs a:first').addClass('first');

    /* tabs */
    $('.tabs a').click(function(a) {
        a.preventDefault();
        $(this).parent().find('a').addClass('inactive');
        $(this).removeClass('inactive');
        $('.tabsWrap .padding').removeClass('show');
        $('.tabsWrap .padding').addClass('hide');
        $($(this).attr('href')).addClass('show');
        

    });

    $('#calendar table td').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });


		$('#content a[href^="http"]:not([href*='+window.location.host+'])').filter(function(){ return !$(this).find('img').length }).addClass('external');
		
		$('tr:even').addClass('even');
  
		$('.rssRow').each(function(){
			var h = $(this).innerHeight();
			$(this).find('.inner').height(h);
		});
		
		$('#dicFavorite dt').each(function(i){
			$(this).prepend('<span class="no">' + (i+1) + '.</span> ');
		});
		
		$('.tabs a').each(function(){
		  $(this).click(function(){
				$($(this).siblings().removeClass('selected').attr('href')).hide();
			  $($(this).addClass('selected').attr('href')).show();
			});
			if($(this).hasClass('selected'))
			{
			  $($(this).attr('href')).show();
			}
			else
			{
			  $($(this).attr('href')).hide();
			}
		});
		
	



    
});

