// JavaScript Document
$(function(){

    // when clicking the tabs do this
    $("ul.tabs li").find("a").click(function(e){
        e.preventDefault();
        // add class "active" to clicked tab, remove class from all other tabs
        $(this).addClass("active").parent().siblings().find("a").removeClass("active");

        var tab = $(this).attr("href");
        // show correct content
        $(tab).show().siblings('.content').hide();
        // set id's on iframes
        $(tab).siblings().find("iframe").attr("id","player");
        // set id on active iframe
        $(tab).find("iframe").attr("id","player-active");
        // reload active iframe
        $("iframe#player-active").each(function(){
        var src = $(this).attr("src");
            $(this).attr("src",src);
        });
        // stop inactive iframes
        callPlayer("player","stopVideo");
    });
    
    $("a.fancylink").fancybox({
        ajax:{
            data: $(this).attr("href")+" #pagewrapper"
        }
    });
    $("a.fancylink-iframe").fancybox({
        'height'            : '400',
        'autoScale'         : true,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'type'              : 'iframe'
    });


    // fix youtube iframe issues
    $('iframe').each(function(){
        var url = $(this).attr("src");
        $(this).attr("src",url+"&wmode=transparent");
    });

});

// controls youtube
function callPlayer(a,b,c){if(!a)return;if(a.id)a=a.id;else if(typeof jQuery!="undefined"&&a instanceof jQuery&&a.length)a=a.get(0).id;if(!document.getElementById(a))return;c=c||[];var d=document.getElementsByTagName("iframe");for(var e=0,f=d.length;e<f;e++){if(d[e].id==a||d[e].parentNode.id==a){window.frames[e].postMessage(JSON.stringify({event:"command",func:b,args:c,id:a}),"*")}}}
