﻿// JScript File

/*  Because the editor seems to render hash links back to the site url (instead of writing a hash), and attempts to write the javascript 
    function call with a youtube url as a parameter seems to mangle the anchor's attributes, it was deeemed easier just to let jquery do
    all the work. The href is simply the set to the youtube url, and the jquery binds the onclick event with the correct function. 
    
    The advantage of this also means that if the jquery doesn't work, the link will still work as the href will just be the youtube link */
    
$(document).ready(function() {
    $('a.youTubePopup').bind('click', function() { youTube_PopUp(this.href); return false; });    
});

// YouTube PopUp
function youTube_PopUp(url)
{
    var width = 1280;
    var height = 720;
    
    // If the window is smaller than 1280, then setup a fancybox width that will fit the browser
    if($(window).width() < 1280)
    {
        width = $(window).width() - 100;
        height = Math.round(width / 1.77777777777);
    }

    $.fancybox({
        'padding'		: 0,
        'autoScale'		: false,
        'transitionIn'	: 'none',
        'transitionOut'	: 'none',
        'titleShow'			: false,
        'overlayColor': '#000',
        'overlayOpacity': 0.7,
        'width'		: width,
        'height'		: height,
        'href'			: url.replace(new RegExp("watch\\?v=", "i"), 'v/'),
        'type'			: 'swf',
        'swf'			: {
          'wmode'		: 'transparent',
          'allowfullscreen'	: 'true'
        }
      });
}
