/*
* SimpleModal Basic Modal Dialog
* http://www.ericmmartin.com/projects/simplemodal/
* http://code.google.com/p/simplemodal/
*
* Copyright (c) 2009 Eric Martin - http://ericmmartin.com
*
* Licensed under the MIT license:
*   http://www.opensource.org/licenses/mit-license.php
*
* Revision: $Id: basic.js 212 2009-09-03 05:33:44Z emartin24 $
*
* Customization: Ryan Vannin - http://www.plastical.com
* 
*
*/

$(document).ready(function() {
    // Image
    $('a.imagePopup').click(function(e) {
        e.preventDefault();
        var img = $(this).children("img").attr("alt");
        var name = $(this).children("img").attr("title");
        var cap = $(this).siblings("small:first").text();
        if (cap.length > 0)
            cap = "<br/><small>" + cap + "</small>";
        modalFx($("#imagePopup-modal").html("<img alt=\"" + img + "\" title=\"" + name + "\" src=\"/files/images/l_" + img + "\" />" + cap));
    });
    $("#imagePopup-modal").hide();
    $('a.videoPopup').click(function(e) {
        e.preventDefault();
        var video = $(this).attr("id");

        if (video.indexOf(".flv") >= 0) {
            modalFx($("#videoPopup-modal").flash({
                src: '/videoPlayer.swf',
                width: 640,
                height: 480,
                flashvars: { Item: video }
            },
            { version: 8 })
            );
        } else {
            modalFx($("#videoPopup-modal").html(embedMobile(video)));
        }
    });
    $("#videoPopup-modal").hide();
    $('a.moviePopup').click(function(e) {
        e.preventDefault();
        var movie = $(this).attr("id");
        modalFx($("#moviePopup-modal").flash({
            src: '/moviePlayer.swf',
            width: 780,
            height: 580,
            flashvars: { Item: movie }
        },
            { version: 8 })
            );
    });
    $("#moviePopup-modal").hide();
    $('a.audioPopup').click(function(e) {
        e.preventDefault();
        var audio = $(this).attr("id");
        var author = $(this).siblings("span.author").text();
        var title = $(this).siblings("span.title").text();
        modalFx($("#audioPopup-modal").flash({
            src: '/audioPlayer.swf',
            width: 424,
            height: 64,
            flashvars: { Item: audio, Author: author, Title: title }
        },
            { version: 8 })
            );
    });
    $("#audioPopup-modal").hide();
});

function modalFx(popUp) {
    popUp.modal({
        overlayClose: true, minWidth: 424, minHeight: 64,
        maxWidth: 780, maxHeight: 580,
        onOpen: function(dialog) {
            dialog.overlay.fadeIn('fast', function() {
                dialog.container.slideDown('fast', function() {
                    dialog.data.fadeIn('fast');
                });
            });
        },
        onClose: function(dialog) {
            dialog.data.fadeOut('fast', function() {
                dialog.container.slideUp('fast', function() {
                    dialog.overlay.fadeOut('fast', function() {
                        $.modal.close(); // must call this!
                    });
                });
            });
        }
    });
}

function embedMobile(video) {
    var str = "<OBJECT id=\"obj" + video + "\" CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" WIDTH=\"640\" HEIGHT=\"480\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\">" +
"<PARAM name=\"SRC\" VALUE=\"/Files/Videos/" + video + "\">" +
"<PARAM name=\"AUTOPLAY\" VALUE=\"true\">" +
"<param NAME=\"type\" VALUE=\"video/quicktime\">" +
"<PARAM name=\"CONTROLLER\" VALUE=\"true\">" +
"<EMBED SRC=\"/Files/Videos/" + video + "\" WIDTH=\"640\" HEIGHT=\"480\" AUTOPLAY=\"true\" CONTROLLER=\"true\" type=\"video/quicktime\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download/\">" +
"</EMBED>" +
"</OBJECT>";
    return str;
}
