﻿function getItemId(sourceId) {
    return sourceId.substring(7);
}

function getItemFilterText(item) {
    return item["FullName"].toLowerCase();
}

function updateFilter() {
    updateFilterInternal("div.people-items ul li");
}

function initializePlayer(flv, loop) {
    var params = {
        quality: "high",
        menu: "false",
        allowScriptAccess: "always",
        bgcolor: "#ffffff",
        allowfullscreen: "true",
        wmode: "transparent"
    };

    var attrs = {
        id: "videoplayer",
        name: "videoplayer",
        wmode: "transparent"
    };
         
    var flashvars = { 
        file: flv,
        autostart: "true",
        displayclick: "none",
        icons: "false",
        repeat: "always",
        stretching: "none",
        backcolor: "FFFFFF",
        screencolor: "FFFFFF",
        frontcolor: "333333",
        controlbar: "none"
    };

    swfobject.embedSWF("/flash/player.swf", "videoplayer", 148, 100, "9.0.0", false, flashvars, params, attrs);   
}

function showPerson(item) {
    showHighlightBox(407, 258);

    if (item["VideoUrl"].indexOf(".flv") != -1) 
    {
        showVideo(item["VideoUrl"]);
    }
    else 
    {
        $("#justaphoto img").attr("src", item["PhotoUrl"]);
        $("#justaphoto img").attr("alt", item["FullName"]);
        $("#justaphoto").show();
    }
    
    $("#highlight h1.title").text( item["FullName"] );
    $("#highlight p.function").text( item["JobTitle"] );
    
    if ( item["Tel"] != null ){
        $("#highlight p.tel").text( item["Tel"] );
    } else {
        $("#highlight p.tel").text( '' );
    }
    
    if ( item["Email"] != null ){
        $("#highlight p.mail a")[0].href = "mailto:" + item["Email"];
        $("#highlight p.mail a").text(item["Email"]);
    } else {
        $("#highlight p.mail a")[0].href = '';
        $("#highlight p.mail a").text('');
    }    

    if ( item["Description"] != null ){
        $("#highlight p.description").text(item["Description"]);
    } else {
        $("#highlight p.description").text( '' );
    }

    document.title = item["FullName"] + " - " + originaltitle;
    
    // icons
    if (item["LinkedInUrl"] != null) {
        $("#highlight #linkedin")[0].href = item["LinkedInUrl"];
        $("#highlight #linkedin").show();
    }
    else {
        $("#highlight #linkedin").hide();
    }
    
    $("#highlight #vcardlink")[0].href = "/" + item["CleanName"] + ".vcf";

    /*if (item["BlogUrl"] != null) {
        $("#highlight #blog")[0].href = item["BlogUrl"];
        $("#highlight #blog").show();
    }
    else {
        $("#highlight #blog").hide();
    }*/
    
}

function showHighlight(itemId) {
    var item = dataitems[itemId];

    showPerson(item);
    showGlobalHighlight(item);       
}

function hideHighlight(item) {
    $("#justaphoto").hide();
    stopVideo();

    hideHighlightBox();    
}

$(document).ready(function() {
    initWindow();

    //globale variabele
    var currentPersonName;

    $("div.people-items ul li").click(function() {
        var itemId = getItemId(this.id);
        var personItem = dataitems[itemId];

        currentPersonName = personItem["FullName"];

        _gaq.push(['_trackEvent', 'TT - Mensen', 'Medewerker pop-up', currentPersonName]);

        showHighlight(itemId);

        return false;
    });

    $("#highlight div.icons a").click(function() {
        _gaq.push(['_trackEvent', 'TT - Mensen', this.id, currentPersonName]);
    });

    $("#highlight p.mail a").click(function() {
        _gaq.push(['_trackEvent', 'TT - Mensen', 'E-mail', currentPersonName]);
    });
});
