////////////////
// INIT
////////////////
$(function(){
    $("#how_it_works").click(function(){openVideo($("#vid_how_it_works").html())});
    $("#thumb_hf").click(function(){openVideo($("#vid_hf").html())});
    $("#thumb_fct").click(function(){openVideo($("#vid_fct").html())});
    $("#thumb_wk").click(function(){openVideo($("#vid_wk").html())});
    $("#thumb_rsc").click(function(){openVideo($("#vid_rsc").html())});
});


////////////////
// FUNCTIONS
////////////////
function openVideo(embed){
    if($(window).width() < 640){
        // mobile...open in new tab
        
        var re = new RegExp("http://www.youtube.com/embed/(.{11})");
        var match = re.exec(embed);
        window.open("http://m.youtube.com/watch?v=" + match[1], "youtube");
    } else {
        //open overlay player
        fancyAlert(embed, 560);
    }
}


function fancyAlert(msg, w) {
    $.fancybox(
    msg, {
                          'autoDimensions': false,
                          'width': ($(window).width() < 640)? 'auto' : (w ||350),
                          'height': 'auto',
                          'transitionIn': 'none',
                          'transitionOut': 'none',
                          overlayColor: '#12285a'
    });
}

var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = (navigator.userAgent.match(/iPhone/i) != null);
