function handlefocus(element) { if (element.value == element.defaultValue) element.value = '';}  	  
function handleblur(element) { if (element.value == '') element.value = element.defaultValue;} 

$(document).ready(function(){
    $('#header-menu #menu a').hover(function() {
        if (!$(this).hasClass('active')) 
        {
            $(this).addClass('hover');	
        }
    }, function() {
        $(this).removeClass('hover');
    });
    
    initSmoothScroll('top');

    $('input').bind("focus",function(){$(this).addClass('over');}).bind("blur",function(){$(this).removeClass('over');});
    $('textarea').bind("focus",function(){$(this).addClass('over');}).bind("blur",function(){$(this).removeClass('over');});
    $('a.imagefancy').fancybox({transitionIn: 'elastic', transitionOut: 'elastic', speedIn: 600, speedOut: 200, titlePosition: 'over'});
});

function initSmoothScroll(hash_name){
    jQuery('a[href^=#'+ hash_name +']').click(function() {
    var duration = 500;
    // easing values: swing | linear
    var easing='swing';

    if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'') && location.hostname==this.hostname && this.hash.replace(/#/,''))
    {
        // get parameters
        var hash=this.hash;
        //var target=jQuery(hash).offset().top;
        // animate to target and set the hash to the window.location after the animation
        jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: target }, duration, easing, function() { location.hash=hash; });
        // cancel default click action
        return false;
    }
    }); 
};

function checkCaptchaValidity(){       
    var object2 = document.getElementById("captchal");
    var check = new Date();

    if($("#captcha").val() == check.getFullYear()){            
        $("#captcha").css("background-color", "#C5E86A");        
        object2.innerHTML="<img src='/_images/captcha_yes.png' />";
    }
    else if ($("#captcha").val() == "") {
        $("#captcha").css("background-color", null);        
        object2.innerHTML="";        
    }
    else{        
        $("#captcha").css("background-color", "#FF99FF");
        object2.innerHTML="<img src='/_images/captcha_no.png' />";
    }
} 

function checkEmailFilled() {
    if ($("#useremail").val() == "") { 
        alert('Nejprve je potřeba vyplnit emailovou adresu!');        
        $("#useremail").focus();        
    }    
}

function checkAddCommentSubmit() {
    if ($("#username").val() == "") {
        alert('Prosím vyplň před odesláním své jméno!');
        $("#username").focus();
        return false;
    }

    if ($("#captcha").val() == "") {
        alert('Prosím vyplň před odesláním kontrolní dotaz!');        
        $("#captcha").focus();
        return false;
    }

    if ($("#usercomment").val() == "") {
        alert('Prosím vyplň před odesláním své komentář!');        
        $("#usercomment").focus();
        return false;
    }
    
    if ($("#sendinfoemail:checked").val() == "on" && $("#useremail").val() == "") {
        alert('V případě zatržení příjmu infoemailu o komentářích je potřeba vyplnit emailovou adresu!');        
        $("#useremail").focus();
    }
   
    return true;
}
