 $(document).ready(function(){
   var useFacebook = facebookPrepareLikeBox();
   if (useFacebook) facebookInit();
 });

// ------------ Drobečková navigace ----------------
$('#drobeckovanavigace').ready(function(){
    resizeDrobMenu()
});

$(window).resize(function(){
    resizeDrobMenu()
});

function resizeDrobMenu()
{
    $('#drobeckovanavigace').width($('#paticka').width()+15);
}

// ------------ Menu Page (dmenu) ----------------
$('#dmenuunder').ready(function(){
    $("#dmenuunder").height(100+$("#dmenu").height());
});

// ------------ Čtvereček ----------------
$('ul.jd_menu').ready(function(){
    $('ul.jd_menu').jdMenu({
        onAnimate: zmenctverecek,
        showDelay:1,
        disableLinks:false
    });
});

function zmenctverecek(show)
{
    if (show) {
        $(this).show();
    } else {
        $('#ctverecek').css('backgroundColor', colorctverecek);
        $(this).hide();
    }

    $('#ctverecek').css('backgroundColor', $('ul.jd_menu > li > ul:visible').parent().find('> a').css('border-top-color'));

}

// skrývání flash zpráviček
$("div.flash").livequery(function () {
    var el = $(this);
    setTimeout(function () {
        el.animate({
            "opacity": 0
        }, 2000);
        el.slideUp();
    }, 7000);
});

// ------------ Facebook ----------------
function facebookPrepareLikeBox()
{
    $("#facebook-column").append('<fb:like-box profile_id="120668441288793" connections="0"></fb:like-box>');
    return (document.getElementById('facebook-column') != null)
}

function facebookInit()
{
    $("body").append('<div id="fb-root"></div>');
    window.fbAsyncInit = function() {
        FB.init({
            appId: '113523918691443',
            status: true,
            cookie: true,
            xfbml: true});
    };
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol +
              '//connect.facebook.net/cs_CZ/all.js';
    document.getElementById('fb-root').appendChild(e);
}

// ------------ Call Back Form ----------------

function callBackFormHide(){
    $("#callBackForm").slideUp();
}

function lateCallBackFormHide()
{
    setTimeout(function () {
        $("#callBackForm .flash").hide();
        $("#callBackForm").slideUp();
    }, 4000);
}

$(".showCallBackForm").ready(function(){
    $(".showCallBackForm").click(function(){
        $("#callBackForm").slideToggle();
        return false;
    })
});

$("#callBackForm .bt-close").ready(function(){
    $("#callBackForm .bt-close").livequery(function () {
        $("#callBackForm .bt-close").click(function(){
            callBackFormHide();
            return false;
        })
    })
});

// ------------ External link ----------------
function externalLinks() { 
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") &&
            anchor.getAttribute("rel") == "external")
            anchor.target = "_blank";
    }
}

window.onload = externalLinks;

