geck.requireScript('js/jquery.ui.js');
geck.requireScript('js/jquery.timers.js');
geck.requireScript('objects/prettyPhoto/js/jquery.prettyPhoto.js');
geck.requireStyle('css/jquery/dot-luv.css');

$(function() {
    
    $('#menu .main a').hover( 
    function() {$('.bullet',this).stop().animate({opacity:1, left:10},500); }, 
    function() {$('.bullet',this).stop().animate({opacity:0, left:0},500); });
    
    $('#menu .main a .bullet')
    .add('#menu .sub.hide')
    .add('#menu .background.hide')
    .css({opacity:0, display:'block'});
   
    var reactionTime = 300;
    var menuShow = function($subMenu) {
        $(document).stopTime('menu');
        $(document).oneTime(reactionTime, 'menu', function() {
            
            $('#menu .sub').stop().animate({opacity:0},500);
            
            $subMenu.stop().animate({opacity:1},500, function() {
                $('#menu .sub').css({zIndex:1});
                $(this).css({zIndex:2});
            });               
        });
    }
    var menuEmpty = function(time) {
        $(document).stopTime('menu');
        $(document).oneTime(reactionTime, 'menu', function() {    
            $('.background.full').stop().animate({opacity:0},1000); 
            $('.background.part').stop().animate({opacity:1},1000);
            $('#menu .sub').stop().animate({opacity:0},700);
        });
    }
    var menuDefault = function() {
        $(document).stopTime('menu');
        $('.background.hide').stop().animate({opacity:0},1000); 
        $('.background.show').stop().animate({opacity:1},1000);
        $('#menu .sub.hide').stop().animate({opacity:0},700);
        $('#menu .sub.show').stop().animate({opacity:1},700, function(){
            $('#menu .sub.hide').css({zIndex:1});
            $('#menu .sub.show').css({zIndex:2});
        });
    }
    
    $('#menu a.base').each( function() { 
        var $sub = $(this).next();
        
        $(this).hover( function() {
            
            if ($sub.hasClass('sub')) {
                $('.background.part').stop().animate({opacity:0},500);
                $('.background.full').stop().animate({opacity:1},500);
                menuShow($sub);
            } else {
                menuEmpty();
            }
        });
    });
    $('#menu .sub').hover( function(){ $(document).stopTime('menu'); });
    $('#menu').hover( function(){}, function(){ menuDefault(1) });
    
    // Intro
    $('#intro').each( function() {
        
        $('.product1').hover( 
        function() {$('.product2').stop().animate({opacity:0.3},1000); }, 
        function() {$('.product2').stop().animate({opacity:1},500); });

        $('.product2').hover( 
        function() {$('.product1').stop().animate({opacity:0.3},1000); }, 
        function() {$('.product1').stop().animate({opacity:1},500); });
        
        $('.link',this).hover( 
        function() {$('.background',this).stop().animate({opacity:0.1},500); }, 
        function() {$('.background',this).stop().animate({opacity:1},500); });
        
        $('.video',this).hover( 
        function() {$('.background',this).stop().animate({opacity:1},500); }, 
        function() {$('.background',this).stop().animate({opacity:0},500); });
        
        $('.video .background',this).css({opacity:0, display:'block'});
    
    });
    
    // Video
    
    var youtubeUrl;
    
    switch (lang.site) {
        case 'cs': youtubeUrl = 'http://www.youtube.com/embed/m04FowWUI6c?hl=cs&fs=1'; break;
        case 'de': youtubeUrl = 'http://www.youtube.com/embed/7tQd6-4lYtw?hl=cs&fs=1'; break;
        case 'ru': youtubeUrl = 'http://www.youtube.com/embed/KamfKGUKJds?hl=cs&fs=1'; break;
        default:   youtubeUrl = 'http://www.youtube.com/embed/5qjI6IORcsc?hl=cs&fs=1'; break;
    }
    
    //var youtubeUrl = 'http://www.youtube.com/watch?v=7tQd6-4lYtw';
    
    var $videoContent = $('<div id="videoWindow"><iframe width="800" height="500" src="'+ youtubeUrl +'" frameborder="0" allowfullscreen></iframe></div>');
    
    $('#playVideo').click( function() {
        
        $videoContent.dialog({
            modal: true,
            title: 'Video',
            resizable: false,
            width: 850,
            height: 560,
            close: function(){ 
                $videoContent.remove(); 
            }
        })
        return false;
    });
    
    var $introRotation = $('#intro-rotation');
    $('table tr td',$introRotation).each( function() {
        $('<div class="frameRotation"></div>').append($(this).html()).appendTo($introRotation).css({opacity:0, display:'none'});
        //$('div',$introRotation).css({opacity:0, display:'none'});
        $('.frameRotation:first',$introRotation).css({opacity:1, display:'block'});
    });
    
    $('table',$introRotation).remove();
    
    var introRotate = function() {
        $('.frameRotation:first',$introRotation).animate({opacity:0},1000, function() {
            $(this).css({display:'none'}).appendTo($introRotation);
            $('.frameRotation:first',$introRotation).css({display:'block'}).animate({opacity:1},1000);
        });
        
        $(document).oneTime(6000, 'rotation', function() {introRotate()});
    }
    
    $(document).oneTime(3000, 'rotation', function() {introRotate()});
    
    //pretty photo
    $("a[rel^='gallery,a[href$=jpg]").prettyPhoto({animationSpeed:'slow',slideshow:5000, autoplay_slideshow: false}); 
});





