jQuery(document).ready(function(){
    
    var layerVideo = jQuery('.layer-video');
    
    //var layerGroup = jQuery('.layer-group');
    //var layerBamboo = jQuery('.layer-bamboo');
    //var linkChoose = jQuery('#link-choose');
            
    layerVideo.fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'fade',
        'speedIn' : 400, 
        'speedOut' : 400,
        'overlayShow' :	true,
        'autoScale': false,
        'showNavArrows' : false,
        
        onComplete : function(){
            initVideos();
        }
    });
    
    /*layerGroup.fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'fade',
        'speedIn' : 400, 
        'speedOut' : 400,
        'overlayShow' :	true,
        'autoScale': false
    });
    
    /*layerBamboo.fancybox({
        'transitionIn' : 'elastic',
        'transitionOut' : 'fade',
        'speedIn' : 400, 
        'speedOut' : 400,
        'overlayShow' :	true,
        'autoScale': false
    });*/    
    
});


function initVideos(){
    var containerVideo = jQuery('.container-video');
    //var startDefaultVideo = jQuery('.start-default-video');
    //var videoBeschreibung = jQuery('.video-beschreibung');
    //var defaultVideo = jQuery('.video-aktiv');

    var video = jQuery('.play-video');
    
    video.unbind();
    //startDefaultVideo.unbind();
    
    //videoPlaying = defaultVideo.attr('id');
    
    video.click(function(){
        
        var currentVideo = jQuery('.play-video'+videoPlaying);
        var nextVideo = jQuery('.play-video'+this.id);
        videoPlaying = this.id;
        
        currentVideo.removeClass('video-aktiv');
        currentVideo.addClass('play-video');
        
        nextVideo.removeClass('play-video');
        nextVideo.addClass('video-aktiv');
        
        playVideo(this.id, containerVideo, videoBeschreibung);
    });
    
    startDefaultVideo.click(function(){
        playVideo('5', containerVideo, videoBeschreibung);
    });
    
    //startDefaultVideo.trigger('click');
    
}


function playVideo(id, container, beschreibung){
    container.html('');
    beschreibung.html('');
    switch (id){
        case '1':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/pq7Fv_vLNPs?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('Personalise your facebook picture and show your outstanding pictures to your friends...');
            break;
        case '2':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/zxg8dFOCgFM?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('Use Bamboo Paper to visualise your next city trip...');
            break;
        case '3':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/A12FkkM4Zx4?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('Prepare a vivid presentation...');
            break;
        case '4':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/aonRV483NjA?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('Highlight your new home on a digital map and invite your friends to a housewarming party...');
            break;
        case '5':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/NMBjdttxZic?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('See what you can do with our brand new 3rd Generation Bamboo Tablets...');
            break;
        case '6':
            container.html('<iframe width="558" height="314" src="https://www.youtube.com/embed/Z_zeW_BuQcU?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>');
            beschreibung.html('Turn your happy snapshots into photographic masterpieces...');
            break;
    }
}
