﻿var isTitle = true;
var currentTarg = null;
var oldTarg = null;

var opening = true;

var vidop = new Array();

function addVidMouseovers()
{
    var vids = document.getElementsByTagName("div");
    var j = 0;
    for (var i=0;i<vids.length;i++)
    {
        if (vids[i].className == "title")
        {
            addEvent( vids[i], "mouseover", function(){overTitle(this)} ); 
            addEvent( vids[i], "mouseout", function(){outTitle(this)} );    
            addEvent( vids[i], "mousedown", function(){downTitle(this)} );
        
        }
        if (vids[i].className == "vid")
        {   
            vidop[j] = new thumbnail();
                        
            
            vidop[j].init(j, "tn_"+j+"", vids[i]);
            j++;
        }
        
    }        
    
    addEvent( document.body, "selectstart", function() {return false} );   
    
    
}

function hideBackground()
{
    var infos = document.getElementById("videosInfos");
    if (infos.hidden == "true")        
        infos.className = "videosInfos"; 
}
    
var dimmed = false;
function dimAll()
{
    if (!dimmed)
    {
        for (var i=0; i<vidop.length; i++)
        {
            vidop[i].dim();
        }
        dimmed = true;
    }

}

function lightAll()
{
    if (dimmed)
    {
        for (var i=0; i<vidop.length; i++)
        {
            vidop[i].light();
        }
    }
    dimmed = false;
}


function removeGlideVidMouseovers()
{
    var vids = document.getElementsByTagName("div");
    for (var i=0;i<vids.length;i++)
    {
        if (vids[i].className == "vid")
        {   
            
        }
    }
}

function overTitle(targ)
{
    if (isTitle)
        targ.className = "titleHover";
    else
        targ.className = "titleDownHover";
}
function outTitle(targ)
{
    if (isTitle)
        targ.className = "title";
    else
        targ.className = "titleDown";
}
function downTitle(targ)
{
    if (document.getElementById("isHP") != null)
    {
        targ.className = "titleDown";
        isTitle = false;
        document.getElementById("links").style.visibility = "visible";
        document.getElementById("linksBottom").style.visibility = "visible";
    }
    else
    {
        window.location = "/";
    }
}
function overClass(targ)
{
        
        feat = document.getElementById("videosInfos");
        
        if (!opening)
        {
            // Update glideVidInfo text to show the hovered-upon spot's information
            var gvi = document.getElementById("glideVidInfo");
        
            while (gvi.childNodes[0] != null)
            {
                gvi.removeChild(gvi.childNodes[0]);
            }
            
            var gvi_dl = document.createElement("dl");
            
            var gvi_dt1 = document.createElement("dt");
            var gvi_dt1text = document.createTextNode("Title:");
            
            gvi_dt1.appendChild(gvi_dt1text);
            
            var gvi_dd1 = document.createElement("dd");
            var gvi_dd1text = document.createTextNode(targ.title);
            
            gvi_dd1.appendChild(gvi_dd1text);
            
            gvi_dl.appendChild(gvi_dt1);
            gvi_dl.appendChild(gvi_dd1);
            
            gvi.appendChild(gvi_dl);
        
        }
        
                
}

function outClass(targ)
{
    targ.className = "vid";
    
    if (!opening)
    {
    
        var gvi = document.getElementById("glideVidInfo");
        
        while (gvi.childNodes[0] != null)
        {
            gvi.removeChild(gvi.childNodes[0]);
        }
        
        var gvi_text = document.createTextNode("Hover over a spot to confirm what it is.");
        gvi.appendChild(gvi_text);
    }
    
    
        
}


function checkNeedForAddNewLine()
{
    var videos = document.getElementById("videos");
    
    var cv = videos.childNodes.length-1;
    var vidsAfterCount = 0;
    var addNewLine = false;
    
    while (vidsAfterCount < 9)
    {
        if (videos.childNodes[cv].className != "vidPlaceHolder")
        {
            vidsAfterCount == 9;
            addNewLine = true;
            break;
        }
        else
        {
            cv--;
            vidsAfterCount++;
        }
    }
    
    if (addNewLine)
    {
        //add a new line
        for (var nv = 0; nv<9;nv++)
        {
        
            var placeHolder = document.createElement('div');
            placeHolder.className = 'vidPlaceHolder';
            videos.appendChild(placeHolder);
        
        }
        
    }


}

function setForSaving()
{
    var dvc = document.getElementById(document.getElementById("hfDivVideosContentsId").value);

    dvc.setAttribute("value", document.getElementById("videos").innerHTML);
    
}

function clearPage()
{
    var videos = document.getElementById("videos");
    
    for (var i=0; i< videos.childNodes.length; i++)
    {
        if (videos.childNodes[i].className == "vid")
        {
            var placeHolder = document.createElement('div');
            placeHolder.className = 'vidPlaceHolder';
            
            videos.insertBefore(placeHolder, videos.childNodes[i]);
            videos.removeChild(videos.childNodes[i+1]);
        }
    }

}