var progressControl;
var progressHolder;
var playProgressBar;
var playProgressInterval;
var currentTimeDisplay;
var durationDisplay;
var volumeControl;
var volumeDisplay;
var fullScreenControl;

var videoWasPlaying;
var videoIsFullScreen;
var videoOrigWidth;
var videoOrigHeight;
var video;

$(document).ready(function() {

//    controls = document.getElementById("controls");

//    progressControl = document.getElementById("progress");
//    progressHolder = document.getElementById("progress_box");
//    playProgressBar = document.getElementById("play_progress");
//    currentTimeDisplay = document.getElementById("current_time_display");
//    durationDisplay = document.getElementById("duration_display");
//    volumeControl = document.getElementById("volume");
//    volumeDisplay = document.getElementById("volume_display");

//    fullScreenControl = document.getElementById("full_screen");



//    video = document.getElementById("video");

//    $(".playPause").click(function() {


//        if (video.paused) {
//            playVideo();

//        } else {
//            pauseVideo();
//        }

//    });
//    $("#Down").click(function() {
//        if ($("#volumeDown").attr("src") == "/js/player/volumeUp.png") {
//            $("#volumeDown").attr("src", "/js/player/volumeDown.png");
//            setVolume(350);
//        }
//        else {
//            $("#volumeDown").attr("src", "/js/player/volumeUp.png");
//            setVolume(400);
//        }

//    });


//    $("#progress_box").bind("mousedown", function(e) {


//        stopTrackingPlayProgress();

//        if (video.paused) {
//            videoWasPlaying = false;
//        } else {
//            videoWasPlaying = true;
//            video.pause();
//        }

//        blockTextSelection();
//        document.onmousemove = function(e) {
//            setPlayProgress(e.pageX);

//        }

//        document.onmouseup = function() {
//            unblockTextSelection();
//            document.onmousemove = null;
//            document.onmouseup = null;
//            if (videoWasPlaying) {
//                video.play();
//                trackPlayProgress();
//            }
//        }

//    });

//    $("#progress_box").bind("mouseup", function(e) {

//        setPlayProgress(e.pageX);
//    });

//    $("#volume").bind("mousedown", function() {
//        blockTextSelection();
//        document.onmousemove = function(e) {
//            setVolume(e.pageX);
//        }
//        document.onmouseup = function() {
//            unblockTextSelection();
//            document.onmousemove = null;
//            document.onmouseup = null;
//        }
//    });

//    $("#volume").bind("mouseup", function(e) {
//        setVolume(e.pageX);
//    });

//    updateVolumeDisplay();






//    function playVideo() {
//        video.play();
//        $("#playIcon").attr("src", "/js/player/play.png");
//        $("#playIcon").attr("alt", "Reproducir");
//        trackPlayProgress();
//    }

//    function pauseVideo() {
//        video.pause();
//        $("#playIcon").attr("src", "/js/player/pause.png");
//        $("#playIcon").attr("alt", "Parar");
//    }




//    function trackPlayProgress() {
//        playProgressInterval = setInterval(updatePlayProgress, 33);
//    }

//    function stopTrackingPlayProgress() {

//        clearInterval(playProgressInterval);
//    }

//    function updatePlayProgress() {

//        playProgressBar.style.width = ((video.currentTime / video.duration) * (progressHolder.offsetWidth - 2)) + "px";
//        updateTimeDisplay();
//    }

//    function setPlayProgress(clickX) {
//        var newPercent = Math.max(0, Math.min(1, (clickX - findPosX(progressHolder)) / progressHolder.offsetWidth));
//        video.currentTime = newPercent * video.duration
//        playProgressBar.style.width = newPercent * (progressHolder.offsetWidth - 2) + "px";
//        updateTimeDisplay();
//    }

//    function updateTimeDisplay() {
//        currentTimeDisplay.innerHTML = formatTime(video.currentTime);
//        if (video.duration) durationDisplay.innerHTML = formatTime(video.duration);
//    }
//    function blockTextSelection() {
//        document.body.focus();
//        document.onselectstart = function() { return false; };
//    }

//    function unblockTextSelection() {
//        document.onselectstart = function() { return true; };
//    }

//    // Return seconds as MM:SS
//    function formatTime(seconds) {
//        seconds = Math.round(seconds);
//        minutes = Math.floor(seconds / 60);
//        minutes = (minutes >= 10) ? minutes : "0" + minutes;
//        seconds = Math.floor(seconds % 60);
//        seconds = (seconds >= 10) ? seconds : "0" + seconds;
//        return minutes + ":" + seconds;
//    }


//    function findPosX(obj) {
//        var curleft = obj.offsetLeft;
//        while (obj = obj.offsetParent) {
//            curleft += obj.offsetLeft;
//        }
//        return curleft;
//    }

//    function setVolume(clickX) {

//        var newVol = (clickX - findPosX(volumeControl)) / volumeControl.offsetWidth;
//        if (newVol > 1) {
//            newVol = 1;
//        } else if (newVol < 0) {
//            newVol = 0;
//        }
//        video.volume = newVol;
//        updateVolumeDisplay();
//    }

//    // Unique to these controls.
//    function updateVolumeDisplay() {
//        var volNum = Math.floor(video.volume * 6);
//        for (var i = 0; i < 6; i++) {
//            if (i < volNum) {
//                volumeDisplay.children[i].style.backgroundColor = "#ADDE71";
//            } else {
//                volumeDisplay.children[i].style.backgroundColor = "#4B851F";
//            }
//        }
//    }



});

