﻿var cs = window.cs ? window.cs : {};

cs.videogallery = {
    onPlay: function(flashPlayerId, videoInfo) {
        cs.videogallery.loadNewFileDetails(flashPlayerId, videoInfo);

        //document.location.hash = videoInfo.id;
    },

    getMovie: function(movieName) {
        return document[movieName];
    },

    onPause: function(flashPlayerId, videoInfo) {

    },

    setFirstFile: function(flashPlayerId, videoInfo) {
        cs.videogallery.loadNewFileDetails(flashPlayerId, videoInfo);
    },

    onNext: function(flashPlayerId, videoInfo) {
        cs.videogallery.loadNewFileDetails(flashPlayerId, videoInfo);
    },

    onPrev: function(flashPlayerId, videoInfo) {
        cs.videogallery.loadNewFileDetails(flashPlayerId, videoInfo);
    },

    loadNewFileDetails: function(flashPlayerId, videoInfo) {
        var container = jQueryCS('.VideoGallery:has(#' + flashPlayerId + ')');

        if (flashPlayerId && videoInfo) {

            document.location.hash = videoInfo.id;

            if (videoInfo.thumbnail) {
                jQueryCS(' .VideoFileThumbnail', container).attr('src', videoInfo.thumbnail);
            }
            if (videoInfo.caption) {
                jQueryCS(' .VideoFileTitle', container).text(videoInfo.caption);
            }
            if (videoInfo.description) {
                jQueryCS(' .VideoFileDescription', container).text(videoInfo.description);
            }

            jQueryCS(' .VideoUrl', container).val(document.location);
            if (GetEmbedCode) {
                jQueryCS(' .EmbedText', container).val(GetEmbedCode(videoInfo.thumbnail, videoInfo.id));

            }
        }

        var listContainer = jQueryCS('.thumbnails', container);

        cs.videogallery.applyCssPropertiesForCurrent(flashPlayerId, videoInfo.id, listContainer);
    },

    playFileInFlash: function(movieName, fileId) {
        var movie = cs.videogallery.getMovie(movieName);
        if (movie) {
            movie._playById(fileId);
        }
    },

    applyCssPropertiesForCurrent: function(flashPlayerId, fileId, listContainer) {
        //unselect previous file
        jQueryCS(' .current', listContainer).removeClass('current');
        //add css class for current displayed file
        jQueryCS(' .n' + fileId, listContainer).addClass('current');

    }
}