

$.ceda = {
    initClouds: function() {
        var vH=$('.precontainer').height();
        var vW=$('.precontainer').width();
        var vT=$('.precontainer').offset().top;
        var vL=$('.precontainer').offset().left;
        //                    console.log(vH,vW,vT,vL);

        $('body').mousemove(function(e){
            var ypos = e.pageY-vT;
            var xpos = e.pageX-vL;
            y = -(ypos/vW*5);
            x = -(xpos/vH*20);

//            $('.precontainer').css({backgroundPosition: x+'% '+-y+'%'});
            $('.mountains').css({backgroundPosition: x/4+'% 153px'});

            $('#sun').css({'left' : x/2+'px', 'top' : y/2+'px'});

        });
}};



jQuery(document).ready(function() {

//    $.ceda.initClouds();


    $('#balon').sprite({fps: 10, no_of_frames: 1})
    .spRandom({top: 0, bottom: 100, left: 50, right: 1600,speed: 30000, pause: 3300})
    .active();

    $('.precontainer').pan({fps: 10 , speed: 1, dir: 'left'});

    $('div.hcontent a img').CreateBubblePopup();

    $('div.hcontent a img').mouseover(function(){

        if(!$(this).hasClass('termit'))
            {
            $(this).ShowBubblePopup({
                innerHtml: $(this).attr('alt'),
                innerHtmlStyle: { 'text-align':'center' },    
                themeName:     'all-black',
                themePath:     '/images/jquerybubblepopup-theme'                                 
            });
        }
    });

    $('.house').mouseover(function() { 
        $(this).attr("src","/images/house-hover.png");
    })
    .mouseout(function() {
        $(this).attr("src","/images/house.png");
    });  



    function callback(hash)  
    {
        var hash = window.location.hash.substr(1);
        var toLoad
        $('#menu li a').each(function(){
            var href = $(this).attr('href');
            if(hash==href){
                toLoad = hash;
            }                                            
        });          

        $('.header a').each(function(){
            var href = $(this).attr('href');
            if(hash==href){
                toLoad = hash;
            }                                            
        });        
        $('a.ajax').each(function(){
            var href = $(this).attr('href');
            if(hash==href){
                toLoad = hash;
            }                                            
        });        


        $('div#primary').load(toLoad);            
    }



    var origContent = "";

    function selected() {   

        $("a").each(function() {
            var hreflink = $(this).attr("href");
            if (hreflink==window.location.hash.substr(1)) {
                $(this).addClass("selected");
            }
            else
                {
                $(this).removeClass("selected");

            }
        });
    }

    function load(hash) {
        selected();

        if(hash != "") {
            $('div#primary').prepend('<span id="load"><img src="/images/ajax-loader.gif"> Nahrávám obsah stánky...</span>');
            $('#load').fadeIn('slow');  
            if(origContent == "") {
                origContent = $('div#primary').html();

            }
            $('div#primary').load(hash);
        } else if(origContent != "") {
            $('div#primary').html(origContent);    
            $('#load').fadeOut('slow');  

        }


    }                 



    $.history.init(function(url){
        load(url)}, {unescape: "/"
    });

    $('#menu a,.hcontent a,a.ajax').live('click', function(e) {        
        var url = $(this).attr('href');
        url = url.replace(/^.*#/, '');    
                    _gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);
  
        $.history.load(url);
        return false;
    });





});



