$(document).ready(function(){


    ////////          MENU

    $("#mm").lavaLamp({
        fx: "easeOutBack",
        speed: 600
    })
   
    // alert("hej")
    $("#mm .current a").css("color","#fff");
    $("#mm .current a").addClass("current");
    $("#mm li a").hover(function(){
    
        if(!$(this).hasClass("current")) {
            $("#mm li a").stop().dequeue();


            $("#mm li a").animate({
                color:"#386194"
            }, 200, "linear");
            $(this).animate({
                color:"#fff"
            }, 200, "linear");
        }
    }, function(){

        if(!$(this).hasClass("current")) {
            $("#mm li a").stop().dequeue();
      
            $(this).animate({
                color:"#386194"
            }, 200, "linear");
            $("#mm .current").find("a").animate({
                left:"0px"
            }, 200, "linear").animate({
                color:"#fff"
            }, 100, "linear");
        }
        
    })


    /////////    SIDE MENU


    //$("#sidemenu").lavaLamp({fx: "swing", speed: 500}) // nefunguje
    if($("#sidemenu").length > 0) {
        $("#sidemenu").append('<li class="back"></li>');
        if($("#sidemenu .current").length != 1) {
            $("#sidemenu li:first").addClass("current")
        }

        var startpos = $("#sidemenu .current").position();
        $("#sidemenu .back").css({
            "top":startpos.top+"px",
            "left":startpos.left+"px",
            "width":$("#sidemenu .current").width()+"px",
            "height":$("#sidemenu .current").height()+"px"
        })

        //alert(startpos.left);

        $("#sidemenu li").hover(function(){
            var h = $(this).height();
            var w = $(this).width();
            var p = $(this).position();
            $("#sidemenu .back").stop().animate({
                "top":p.top+"px",
                "left":p.left+"px",
                "width":w + "px",
                "height":h + "px"
            }, 600, "easeOutBack")
        }, function(){
            $("#sidemenu .back").stop().animate({
                "top":startpos.top+"px",
                "left":startpos.left+"px",
                "width":$("#sidemenu .current").width()+"px",
                "height":$("#sidemenu .current").height()+"px"
            }, 600, "easeOutBack")
        })
    }




    ////////// SLIDER

    $('.sinsider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        boxCols: 8, // For box animations
        boxRows: 2, // For box animations
        animSpeed:400, // Slide transition speed
        pauseTime:6000, // How long each slide will show
        directionNav:false, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:false, // 1,2,3... navigation
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:false // Stop animation while hovering
    });


    ///////                 HOVER TABS

    $(".osb").hover(function(){
        $(this).stop().animate({
            "height":"335px",
            "padding-top":"20px"
        }, 300, "swing")
    },function(){

        $(this).stop().animate({
            "height":"84px",
            "padding-top":"10px"
        }, 300, "swing")
    })


    ////////////            SCROLLER

    $(".newsscrollable-insider .newswrapper").css("width",$(".newsscrollable-insider .onenew").length * 355+ "px" );
    $(".newsscrollable-insider").jScrollPane();





    ////////     VIDEOLINK BUTTON
    $("a.videolink span").css("opacity","0.5");
    $("a.videolink").hover(function(){
        $(this).find("span").stop().animate({
            "opacity":"0.9"
        }, 200, "swing")
    },function(){
        $(this).find("span").stop().animate({
            "opacity":"0.5"
        }, 200, "swing")
    })


    ///////// othebtns 0.8

    $("a.fbtn").css("opacity","0.8").hover(function(){
        $(this).stop().animate({
            "opacity":"1"
        }, 200, "swing")
    },function(){
        $(this).stop().animate({
            "opacity":"0.8"
        }, 200, "swing")
    })
    ///////// othebtns 0.6
    $("a.detailbtn, a.addtobtn, .lbtn, .atc").css("opacity","0.6").hover(function(){
        $(this).stop().animate({
            "opacity":"1"
        }, 200, "swing")
    },function(){
        $(this).stop().animate({
            "opacity":"0.6"
        }, 200, "swing")
    });


    ///////// catimgs

    $(".onecategory img").css("opacity","1");
    $(".onecategory").hover(function(){
        $(this).find("img").stop().animate({
            "opacity":"0.8"
        }, 400, "swing")
    },function(){
        $(this).find("img").stop().animate({
            "opacity":"1"
        }, 400, "swing")
    })


    /// style cats











    //////////////                SATELITES

    $(".cbg").after('<div class="satstars"></div>');
    $(".satstars").append('<div class="satstar0"></div><div class="satstar1"></div><div class="satstar2"><div class="satstar3"></div><div class="satstar4"></div>');

    var ss = Array();

    //alert(Math.round(Math.random()*2))

    ss[0] = {
        "state" : false
       
    };
    ss[1] = {
        "state" : false
        
    };
    ss[2] = {
        "state" : false
      
    };
ss[3] = {
        "state" : true
    };
    ss[4] = {
        "state" : true
    };

    //alert(ss[0].state);

    function moveSat () {
        for (var i=0;i<5;i++) {

            // alert($(".satstars").width());

            
            if(ss[i].state==true) {
                ss[i].x = ss[i].x - (-ss[i].vx);
                ss[i].y = ss[i].y - (-ss[i].vy);
                $(".satstar"+i).css({
                    "left": Math.round(ss[i].x)+"px",
                    "top":Math.round(ss[i].y)+"px"
                })
                if (ss[i].blinks >= ss[i].blinkat) {
                    ss[i].blinks = 0;
                }
                if (ss[i].blinks < ss[i].blinklt) {
                    $(".satstar"+i).css("opacity", "0.9");
                    ss[i].blinks++;
                } else if (ss[i].blinks < ss[i].blinkat){
                    $(".satstar"+i).css("opacity", "0.1");
                    ss[i].blinks++;
                }

                if(ss[i].x - 2 > $(".satstars").width() || ss[i].x + 2 < 0 || ss[i].y - 2 > $(".satstars").height() || ss[i].y + 2 < 0 ) {
                    ss[i].state = false;
                   // alert("stojí");
                }
             
            //alert(i);
            } else {
                //alert(Math.round(Math.random()*20));
                if(Math.random() < 0.01) {
                   // alert("generuju #"+i);
                    generateSatelite(i)
                }
            }
        }       
    }

    function generateSatelite(num) {
        var x = 0;
        var y = 0;
        var vx = 0;
        var vy = 0;
        var dir = ""

        var blinklt = Math.round(Math.random()*20);
        var blinkat = Math.round(Math.random()*50)-10;
        if(blinkat < blinklt) {
            blinkat = blinklt;
        }
        
       // alert(Math.round(Math.random()*2));
        if(Math.round(Math.random()*2) == 1 ){
            if(Math.round(Math.random()*2) == 1 ){
                x = -1;
                y = Math.round(Math.random()*$(".satstars").height());
                dir = "x";
            } else {
                x = $(".satstars").width()+1;
                y = Math.round(Math.random()*$(".satstars").height());
                dir = "-x";
            }
        } else {

            if(Math.round(Math.random()*2) == 1 ){
                y = -1;
                x = Math.round(Math.random()*$(".satstars").width());
                dir = "y";
            } else {
                y = $(".satstars").height()+1;
                x = Math.round(Math.random()*$(".satstars").width());
                dir = "-y";
            }
         }
          if(dir == "x") {
              vx = Math.round(Math.random()*50)/10;vy = (Math.round(Math.random()*40)-20)/10;
          } else if(dir == "-x") {
                vx = -Math.round(Math.random()*50)/10;vy = (Math.round(Math.random()*40)-20)/10;
          } else if(dir == "y") {
                 vx = (Math.round(Math.random()*100)-50)/10;vy = Math.round(Math.random()*20)/10;
          } else {
                vx = (Math.round(Math.random()*100)-50)/10;vy = -Math.round(Math.random()*20)/10;
          }
ss[num] = {
        "state" : true,
        "x" : x,
        "y" : y,
        "vx": vx,
        "vy":vy,
        "blinklt":blinklt,
        "blinkat":blinkat,
        "blinks":"0"
    }
      //  alert(x+" "+ y + " "+ vx+" "+ vy+" - "+num)
        //alert("generated #"+num)
    }

//    $(".satstars").click( function(){
//        generateSatelite(0);
//    })

    var Sinterval = setInterval(moveSat, 40);





/////////////////            forms

if($("#contact-form").length > 0){
    //alert("jo")
    $("#contact-form").jqTransform();
}


///// video load

Shadowbox.init({
    skipSetup: true
});


$(".videolink").click(function(){

    Shadowbox.open({
        content:    '<div id="videoover"><a onclick="Shadowbox.close()" class="vclose" href="#"></a><p class="viddesc"><strong>Lorem ipsum dolor sit amet</strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p><iframe src="http://player.vimeo.com/video/8449716?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="640" height="362" frameborder="0"></iframe></div>',
        player:     "html",
       
        height:     450,
        width:      650
    });

})



  
});






