function hideScreenshot() {
    document.getElementById('screenshotPanel').style.display = 'none';
    document.getElementById('screenshotLockPage').style.visibility = 'hidden';
    document.getElementById('screenshotPopover').style.visibility = 'hidden';
    var screenshot = document.getElementById('screenshot')
    screenshot.src = '';
    changeVideo('');
}
function showScreenshot(screenshotFileName, screenshotDescription, isScreenshot) {
    var screenshot = document.getElementById('screenshot');
    var video = document.getElementById('Cinema');
    var description = document.getElementById('screenshotDescription');
    var screenshotPanel = document.getElementById('screenshotPanel');
    var fileName = document.getElementById('fileName');
    fileName.value = screenshotFileName;
    var fileType = document.getElementById('fileType');
    if (isScreenshot) { fileType.value = 'screenshot'; } else { fileType.value = 'video'; }
    var URL = 'http://';
    var domain = window.location.hostname;
    var port = window.location.port;
    URL = URL + domain;
    if (port != 80 && port !='') { URL = URL + ':' + port; }
    URL = URL + '/'
    if (fileType.value == 'screenshot') { URL = URL + 'cinema.asp?photo=Screenshots/' + screenshotFileName + '.png'; }
    if (fileType.value == 'video') { URL = URL + 'cinema.asp?film=' + screenshotFileName; }
    var screenshotURL = document.getElementById('screenshotURL');
    screenshotURL.value = URL;

    screenshotPanel.style.display = 'block';
    if (isScreenshot) {
        screenshot.src = 'Images/Screenshots/' + screenshotFileName + '.png';
        video.style.display = 'none';
        screenshot.onload = function() {
            screenshot.style.display = 'block';
            fixScreenshotSize(isScreenshot);
        }
    } else {
        screenshot.style.display = 'none';
        changeVideo(screenshotFileName + '.flv', screenshotDescription);
        video.style.display = 'block';
        fixScreenshotSize(isScreenshot);
    }
    
    description.innerHTML = screenshotDescription;

    window.setTimeout('showPopup();', 100);
}

function showPopup() {
    var lockPage = document.getElementById('screenshotLockPage');
    var popOver = document.getElementById('screenshotPopover');
    lockPage.style.visibility = 'visible';
    popOver.style.visibility = 'visible';
}

function fixScreenshotSize(isScreenshot) {
    if (isScreenshot) {
        var screenshot = document.getElementById('screenshot');
    } else {
        var screenshot = document.getElementById('Cinema');
    }
    var popOver = document.getElementById('screenshotPopover');

    popOver.style.width = screenshot.offsetWidth + 64 + 'px';
    popOver.style.marginLeft = 0 - (popOver.offsetWidth * 0.5) + 'px';
    popOver.style.height = screenshot.offsetHeight + 64 + 'px';
    popOver.style.marginTop = 0 - (popOver.offsetHeight * 0.5) + 'px';
}

function changeVideo(videoID) {
    var video = document.getElementById('Video');
    insertCodePage('_AJAX-video.asp?URL=' + videoID, 'Cinema');
}

function viewInCinema() {
    var fileName = document.getElementById('fileName').value;
    var fileType = document.getElementById('fileType').value;
    if (fileType == 'screenshot') { popup('cinema.asp?popup=1&photo=Screenshots/' + fileName + '.png'); }
    if (fileType == 'video') { popup('cinema.asp?popup=1&film=' + fileName); }
    hideScreenshot();
}
function copyURL() {
    var fileName = document.getElementById('fileName').value;
    var fileType = document.getElementById('fileType').value;

    hideScreenshot();
}
function insertIntoCopyBuffer(text) {
    alert(text);
}


function popup(URL) {
    window.open(URL,'_blank','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=550')
}

function flashVideoReady(strSource) {
    if (strSource != 'test.flv') {
        // REAL VIDEO READY! (this is called by the Flash plugin once the stream is ready)
    }
}