﻿var templateVideo = jQuery('<div style="display:none"><div class="VIDEO_zoomimage_s"><div class="VIDEO_zoomimage_st"><div class="VIDEO_zoomimage_stl iePNG"></div><div class="VIDEO_zoomimage_stc iePNGScale"></div><div class="VIDEO_zoomimage_str iePNG"></div></div><div class="VIDEO_zoomimage_sc"><div class="VIDEO_zoomimage_scl iePNGScale"></div><div class="VIDEO_zoomimage_scc iePNG"></div><div class="VIDEO_zoomimage_scr iePNGScale"></div></div><div class="VIDEO_zoomimage_sb"><div class="VIDEO_zoomimage_sbl iePNG"></div><div class="VIDEO_zoomimage_sbc iePNGScale"></div><div class="VIDEO_zoomimage_sbr iePNG"></div></div></div><div class="VIDEO_zoomimage_content"></div></div>');

var flashvars = {
    "m":"video",
    "file":"2iob3gRLvaFV2xzL05o7UQnVtQtB0c9IvIwhvak70dw1vaFV2xzL05o7UQnVtQtBk5Wa",
    "st":"2iob3gRLvaFV2xzL05o7UQnVtQtB0c9IvIwhvak70dw1vck7kdwLtjnMyQENvIolGArr",
    "comment":"apimondia2013",
    "uid":"VideoPlayer"
};
var params = {
    id:"VideoPlayer",
    bgcolor:"#ffffff",
    menu: "false",
    quality: "hight",
    wmode:"opaque",
    allowFullScreen:"true",
    allowScriptAccess:"always"
};
var attributes = {
    id: "VideoPlayer",
    name: "VideoPlayer"
};
var ShowVIDEO = function(event) {
/*
    jQuery('#layout').block({
        message: '<img src="assets/js/ajax-loader.gif" width="32" height="32" alt="Loading" />',
        css: {
            border: 'none',
            height: '32px',
            width: '32px',
            top: '0',
            right: '0'
        },
        overlayCSS: {
            backgroundColor: '#FFF',
            opacity: '0.6'
        },
        centerX: true,
        centerY: false
    });
*/
    jQuery('#VIDEO').find('>div.VIDEO_zoomimage_content').css({
        "width": "640px",
        "height": "480px",
        "display": "none"
    }).end().find('>div.VIDEO_zoomimage_s').css({ "display": "block" })
    .end().find('div.VIDEO_zoomimage_sc').data("css", { height0: "0px", height: parseInt(480) + "px" })
    .end().data("css", {
        top0: "-10px",
        left0: "-10px",
        width0: "36px",
        height0: "36px",
        top: "30px",
        left: parseInt((jQuery(document).width() - 640 - 36) / 2, 10) + "px",
        width: parseInt(640 + 36) + "px",
        height: parseInt(480 + 36) + "px"
    }).css({
        "top": jQuery('#VIDEO').data("css").top0,
        "left":  jQuery('#VIDEO').data("css").left0,
        "width":  jQuery('#VIDEO').data("css").width0,
        "height": jQuery('#VIDEO').data("css").height0,
        "display": "none",
        "overflow": "hidden"
    });
        jQuery('#videoClose').hide();
        jQuery('#videoIndicator').show();
        
        jQuery('#VIDEO').addClass('VIDEO_zoomimage_focused').show().stop().animate({
            "left": jQuery('#VIDEO').data("css").left,
            "top": jQuery('#VIDEO').data("css").top,
            "width": jQuery('#VIDEO').data("css").width
        }, "normal", function() {
            jQuery(this).find('div.VIDEO_zoomimage_scl, div.VIDEO_zoomimage_scc, div.VIDEO_zoomimage_scr')
                .stop()
                .animate({ "height": jQuery('div.VIDEO_zoomimage_sc').data("css").height }, "normal")
            .end().animate({ "height": jQuery('#VIDEO').data("css").height }, "normal", function() {
                jQuery(this).find('>div.VIDEO_zoomimage_content')
                    .empty()
                    .append('<div id="VideoPlayer"></div>')
                    .show()
                .end();
                new swfobject.embedSWF("files/uppod.swf", "VideoPlayer", "640px", "480px", "9.0.115",/* "files/expressInstall.swf"*/"", flashvars, params, attributes);
                jQuery('#videoIndicator').hide();
                jQuery('#videoClose').show();
            });
        });


/*
        jQuery('#layout').unblock();
*/
    return false;
}
var CloseVIDEO = function(event) {
    jQuery('#videoClose').hide();
    jQuery('#videoIndicator').show();
    jQuery('#VIDEO').find('>div.VIDEO_zoomimage_content')
        .empty()
        .hide()
    .end().find('div.VIDEO_zoomimage_scl, div.VIDEO_zoomimage_scc, div.VIDEO_zoomimage_scr')
        .stop().animate({ "height": jQuery('div.VIDEO_zoomimage_sc').data("css").height0 }, "normal")
    .end().stop().animate({ "height": jQuery('#VIDEO').data("css").height0 }, "normal", function() {
        jQuery(this).animate({
            "top": jQuery('#VIDEO').data("css").top0,
            "left": jQuery('#VIDEO').data("css").left0,
            "width":  jQuery('#VIDEO').data("css").width0
        }, "normal", function() {
            jQuery('#VIDEO').find('div.VIDEO_zoomimage_s')
                .hide()
            .end();
            jQuery('#videoIndicator').hide();
        });
    }).hide().removeClass('VIDEO_zoomimage_focused');
    return false;
}
jQuery(document).ready(function() {

    templateVideo.appendTo('body').attr('id', 'VIDEO').append('<img src="assets/js/ajax-loader.gif" width="32" height="32" alt="Loading" id="videoIndicator" style="display:none" />').append('<img src="assets/js/close.png" width="32" height="32" alt="Close" id="videoClose" style="display:none" />').css({
        "top": "-10px",
        "left": "-10px",
        "width": "36px",
        "height": "36px",
        "display": "none",
        "overflow": "hidden"
    });

    jQuery('a.showVideo').bind("click", ShowVIDEO);
    jQuery('#videoClose').bind("click", CloseVIDEO);
});