﻿var flashvars = {};
var params = {};
params.wmode = "transparent";
params.width = "512";
params.height = "288";
var attributes = {};

var videos = new Array();
var videoId;

$(document).ready(function() {
    $(".Video").each(function() {
        var galleryid = videos.length;

        videos[galleryid] = new Object();

        $(this).find(".Image").each(function() {
            videos[videos.length - 1].alt = this.alt;
        });

        $(this).find(".Link").click(function() {
            ShowVideoPopup(galleryid);
        });

        $(this).find("a").each(function() {
            videos[videos.length - 1].src = this.rel;
        });
    });

    $("#PopupVideo .Close").each(function() {
        this.onclick = function() {
            $('#PopupVideoWrapper').hide();
            $("#PopupVideo .Media").html("<div id=\"PopupVideoFlash\"></div>");
        }
    });

    $("#PopupVideo .Next").each(function() {
        this.onclick = function() {
            ShowVideo(videoId + 1);
        }
    });

    $("#PopupVideo .Back").each(function() {
        this.onclick = function() {
            ShowVideo(videoId - 1);
        }
    });
})

function ShowVideoPopup(id) {
    /* out of range */
    if (id < 0 || id >= videos.length)
        return;
    if ($('#PopupImage').css("position") != "fixed")
        scroll(0, 0);
    videoId = id;
    UpdateVideo(videoId);
    $('#PopupVideoWrapper').animate({ height: 'show', opacity: 'show' }, 'slow');
}

function UpdateVideo(id) {
    swfobject.embedSWF(videos[id].src, "PopupVideoFlash", "612", "344", "8.0.0", "Content/Flash/expressInstall.swf", flashvars, params, attributes);

    $('#PopupVideo .Text').each(function() {
        this.firstChild.data = videos[id].alt;
    });
}

function ShowVideo(id) {
    /* out of range */
    if (id < 0 || id >= videos.length) return;

    videoId = id;

    $('#PopupVideo .Media').hide();
    UpdateVideo(videoId);
    $('#PopupVideo .Media').animate({ opacity: 'show' }, 'slow');
}