/**
 * Chrome for video tag
 * @author Martin Ericsson
 * @version 1
 */

/* check for touch device
TODO: find a better way than assume that touch device equals small mobile device
*/
function isTouchDevice() {
    try {
        document.createEvent("TouchEvent");
        return true;
    } catch (e) {
        return false;
    }
}

/* Fix for video tag for coherent look for all supported browsers */
$('.image_video_conceal_top_left').click(function() {
    // slide the concealer and fade in the video
    $(this).slideToggle('slow', function() {
        var v = $(this).parent().find('video');
        if(!isTouchDevice()) {
            var source = $(this).parent().find('source');
            //v.src = 'videos/ar.mp4';
            if(!$.browser.mozilla) {
                $(this).parent().find('source')[0].src = 'videos/aura.mp4';
                v.load();
            }
        }
        v.fadeIn('slow', function() {$(this)[0].play()});
    });
});

$('.image_video_conceal_top_right').click(function() {
    // slide the concealer and fade in the video
    $(this).slideToggle('slow', function() {
        var v = $(this).parent().find('video');
        if(!isTouchDevice()) {
            var source = $(this).parent().find('source');
            //v.src = 'videos/ar.mp4';
            if(!$.browser.mozilla) {
                $(this).parent().find('source')[0].src = 'videos/ar.mp4';
                v.load();
            }
        }
        v.fadeIn('slow', function() {$(this)[0].play()});
    });
});

$('.image_video_conceal_bottom').click(function() {
    // slide the concealer and fade in the video
    $(this).slideToggle('slow', function() {
        var v = $(this).parent().find('video');
        if(!isTouchDevice()) {
            var source = $(this).parent().find('source');
            //v.src = 'videos/ar.mp4';
            if(!$.browser.mozilla) {
                $(this).parent().find('source')[0].src = 'videos/mf.mp4';
                v.load();
            }
        }
        v.fadeIn('slow', function() {$(this)[0].play()});
    });
});

$(document).ready(function() {
    // show all concealers if JS is active
    $('.image_video_conceal').show();
    // hide all video on load    
    $('video').hide(); 
});

