﻿// This script tag contains goplayer's/Streamio's default scripts, with some minor changes for values
function embedFlashPlayer(videoId, width, height) {
    var params = { allowFullscreen: "true", allowScriptAccess: "always", base: "/templates/cs/SiGoPlayer/", wmode: "opaque" };
    var variables = { "skin:show-title": false, "streamio:api": "http://streamio.com/api", "src": "streamio:video:" + videoId, "videoid": videoId };
    swfobject.embedSWF("/templates/cs/SiGoPlayer/goplayer.swf", "player_div", width, height, "9.0.0", null, variables, params);
}

function embedHtmlPlayer(videoId) {
    $("#player_div").html("<video class=\'streamio\' controls src=\'https://streamio.com/api/v1/videos/" + videoId + "/download' poster=\'http://d253c4ja9jigvu.cloudfront.net/images/4d402a78e426000a8100037e_" + videoId + "_normal.jpg\'><\/video>");
    var video = $("video.streamio");
    video.bind("play", function() {
        postEvent("plays", videoId);
        video.unbind("play");
    })

    // Android phones dont support the usual click to play behaviour so we add it manually
    if (navigator.userAgent.match(/Android/i)) {
        video.click(function() {
            $("video.streamio").get(0).play();
        })
    }

    $(function() {
        postEvent("views", videoId);
    })
}

function postEvent(event, videoId) {
    $.post("http://streamio.com/api/v1/stats", { tracker_id: "global", video_id: videoId, event: event });
}

// sweden.se specific script for calling Google Analytics event tracking in the parent window (this file is supposed to be in an iframe)
function trackEvent(category, action, label, value) {
    // Check if this page is iframed (not the top level) and if the parent page has the trackEvent function we would like to call
    if (window.top != window) {
        if (window.top.trackEvent) {
            window.top.trackEvent(category, action, label, value);
        } else if (window.top._gaq) {
            window.top._gaq.push(['c._trackEvent', category, action, label, value]);
        }
    }
}
