//statcount variables
var sc_project=2776400; 
var sc_invisible=0; 
var sc_partition=28; 
var sc_security="3260b096"; 


//site functions
function showElement(id)
{
    document.getElementById(id).style.visibility = 'visible';
}

function hideElement(id)
{
    document.getElementById(id).style.visibility = 'hidden';
}

function toggleShowDivs(recording_id)
{
    var notes = document.getElementById("notes_" + recording_id);
    var songs = document.getElementById("songs_" + recording_id);
    var photos = document.getElementById("photos_" + recording_id);
    
    if (notes)
    {
        if (notes.style.display == 'block')
        {
            notes.style.display = 'none';
        }
        else
        {
            notes.style.display = 'block';
        }
    }
    
    if (songs)
    {
        if (songs.style.display == 'block')
        {
            songs.style.display = 'none';
        }
        else
        {
            songs.style.display = 'block';
        }
    }
    
    if (photos)
    {
        if (photos.style.display == 'block')
        {
            photos.style.display = 'none';
        }
        else
        {
            photos.style.display = 'block';
        }
    }
    
}

function addPhotoRow()
{
        var currentRow = parseInt(document.getElementById('rowCount').value) + 1;
        
        if (currentRow > 5)
        {
            showElement("warning");
            return false;
        }
        
        if (document.all)
        {
            document.getElementById("row" + currentRow).style.display = 'inline';
        }
        else
        {
            document.getElementById("row" + currentRow).style.display = 'table-row';
        }
                      
        document.getElementById('rowCount').value = currentRow;
}

function SetupHoverBox(description, source, url)
{
    CloseHoverBox();
    var linkElement = document.createElement('a');
    linkElement.href = url.replace("medium", "large");
    linkElement.id = "imageLink";
    linkElement.name = "imageLink";
    linkElement.target = "_blank";
    imageElement = document.createElement('IMG');
    imageElement.style.borderStyle = "none";
    imageElement.src = url;
    
    linkElement.appendChild(imageElement);
    document.getElementById("hoverBoxImage").appendChild(linkElement);
    
    var textElement = document.createElement('span');
    textElement.innerHTML = description + "<br /><br />" + "Photo By: " + source;
    document.getElementById("hoverBoxText").appendChild(textElement);
    
    var box = document.getElementById("waitBox");
    box.style.display = "block";
    centerElement(box);
    
    waitForComplete(imageElement, document.getElementById("hoverBox"));
}

function centerElement(box)
{
    var IpopTop = (getWindowHeight() - box.offsetHeight) / 2;
    var IpopLeft = (getWindowWidth() - box.offsetWidth) / 2;
    
    box.style.left = IpopLeft + getScrollWidth() + "px";
    box.style.top = IpopTop + getScrollHeight() + "px";
}

function waitForComplete(image, box)
{
    if (!image.complete)
    {
        setTimeout(function() { waitForComplete(image, box);}, 50);
    }
    else
    {
        document.getElementById("waitBox").style.display = "none";
        box.style.display = "block";
        centerElement(box);
    }
}

function CloseHoverBox()
{
    var box = document.getElementById("hoverBox");
    box.style.display = "none";
    clearChildren(document.getElementById("hoverBoxImage"));
    clearChildren(document.getElementById("hoverBoxText"));
}

function clearChildren(obj)
{
    while(obj.firstChild) obj.removeChild(obj.firstChild);
}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function getWindowHeight()
{
	var h = 0;

	//IE
	if(!window.innerHeight)
	{
		//strict mode
		if(!(document.documentElement.clientHeight == 0))
		{
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		h = window.innerHeight;
	}
	return h;
}

function getWindowWidth()
{
	var w = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
	}
	return w;
}

var unavailable = "Sorry, the requested song is not available for download.";
