$(document).ready(function()
{
    var max=1260;
    var min=980;
    var left=$("div.left").width();
    var right=$("div.right").width();
    var reduce=0;
    var width=$(window).width();

    function shadow(width)
    {
        if(width<max)
        {
            reduce=Math.ceil((max-width)/2);
        }
        else
        {
            reduce=0;
        }

        if(reduce>(max-min)/2)
        {
            reduce=(max-min)/2;
        }

        $("div.left").width(left-reduce);
        $("div.right").width(right-reduce);
    }

    shadow(width);

    $(window).resize(function()
    {
        width=$(window).width();

        shadow(width);
    });

    var span=1;
    var autoTime=4000;
    var x=setInterval("$('div.control span').eq("+span+").trigger('click');",autoTime);

    $('div.box').scrollTo({top:'0',left:'0'},400);

    $("div.control span").click(function()
    {
        var id=$(this).attr("class");
        var position=new Array();
        
        position["a"]=0;
        position["b"]=340;
        position["c"]=680;

        if(!$(this).hasClass("active"))
        {
            $("div.control span").removeClass("active");
            $(this).addClass("active");
            $('div.box').scrollTo({top:'0',left:position[id]},400);
        }

        span=$(this).index()+1;

        if(span>2)
        {
            span=0;
        }

        clearInterval(x);
        x = setInterval("$('div.control span').eq("+span+").trigger('click');", autoTime);
    });

    var li=1;
    var y=setInterval("$('div.intro li').eq("+li+").trigger('click');",autoTime);

    $("div.intro li").click(function()
    {
        var id=$(this).attr("class");

        if(!$(this).hasClass("active"))
        {
            $("div.intro div."+id).addClass("new");
            $("div.intro div."+id).fadeIn();
            $("div.intro div").removeClass("new");
            $("div.intro div.active").fadeOut();
            $("div.intro div").removeClass("active");
            $("div.intro div."+id).addClass("active");
            $("div.intro li").removeClass("active");
            $(this).addClass("active");
        }

        li=$(this).index()+1;

        if(li>2)
        {
            li=0;
        }

        clearInterval(y);
        y = setInterval("$('div.intro li').eq("+li+").trigger('click');", autoTime);
    });

    $("div.partner span.hover").hover
    (
        function()
        {
            $(this).find("span").fadeOut(400);
        },
        function()
        {
            $(this).find("span").fadeIn(400);
        }
    );

    $('div.popup p').after
    (
        "<span class=\"top\"></span>"+
        "<span class=\"bottom\"></span>"
    );

    $("div.map a").click(function()
    {
        return false;
    });

    var popup=0;
    var position=0;

    $("div.map a").hover(function()
    {
        popup=$(this).attr("href");
        position=$(this).position();

        $(popup).css({"bottom":372-position.top,"left":position.left-108});
        $(popup).fadeIn();
    }, 
    function()
    {
        $(popup).fadeOut();
    });

    $("p.fb a").click(function()
    {
        window.open($(this).attr('href'),"share","location=no,status=yes,width=600,height=300,resizable=yes,menubar=no,srcollbars=no");
        return false;
    });

    $('a[rel="gallery"]').fancybox(
    {
        'padding'           : 0,
        'autoScale'         : false,
        'showNavArrows'     : true,
        'titleShow'         : true,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'overlayOpacity'    : 0.6,
        'overlayColor'      : '#000',
        'type'              : 'image'
    });

    $('div.slide').hide();

    $('p.slide a').click(function()
    {
        $(this).parent().parent().find('div.slide').slideToggle();

        if($(this).hasClass("hide"))
        {
            $(this).removeClass("hide");
            $(this).html("<span>+</span> Zobrazit detailní ceník");
        }
        else
        {
            $(this).addClass("hide");
            $(this).html("<span>&ndash;</span> Skrýt detailní ceník");
        }

        return false;
    });
});

Cufon.replace("div.head h1, div.head h3, div.intro h2, div.about h2, h2.top",{fontFamily:'Frutiger'});
Cufon.replace("div.headlines, div.about h2 strong",{fontFamily:'Frutiger Condensed'});
Cufon.replace("div.menu",{fontFamily:'Frutiger Condensed',hover: true});
Cufon.replace("div.foot p.fb span",{fontFamily:'Klavika'});
