window.onload = function ()
{
	if (self.init) init();
}
window.onresize = function ()
{
	if (self.init) init();
}

var intCover = 1;

function init()
{
    document.getElementById('page').style.visibility = 'hidden';
    document.getElementById('loading').style.visibility = 'visible';

	getWindowDims();
	setWindowElementDims();
}

function getWindowDims()
{
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
	
	if (document.getElementById('headerClear') != null)
	    headerOffsetHeight = document.getElementById('headerClear').offsetHeight;
	else
	    headerOffsetHeight = document.getElementById('headerBanner').offsetHeight;
	
	footerOffsetHeight = document.getElementById('footerBox').offsetHeight;
	
	if (!document.all)
	    footerOffsetHeight -= 10;
}

function setWindowElementDims()
{
    headerBorder = 10 + 10;
    headerHeight = headerOffsetHeight + headerBorder;

    footerBorder = 10 + 20;
    footerHeight = footerOffsetHeight + footerBorder;
    
    boxCornerSize = 9;

    contentHeight = windowHeight - headerHeight - footerHeight;
    
    document.getElementById('info').style.height = contentHeight;
    document.getElementById('info').className = 'block';
    
    if (document.getElementById('linksBox') != null)
    {
        linksBorder = 10;
        infoHeight = contentHeight - (document.getElementById('linksBox').offsetHeight + linksBorder)
    }
    else
        infoHeight = contentHeight;
        
    document.getElementById('infoBox').style.height = infoHeight;
    document.getElementById('infoBoxContent').style.height = infoHeight - (boxCornerSize * 2);
    
    document.getElementById('detailsCnt').style.height = contentHeight;
    document.getElementById('details').style.height = contentHeight;

    detailsBorder = 10;
    detailsHeight = ((contentHeight - detailsBorder) / 2);
    
    document.getElementById('descBox').style.height = detailsHeight;
    document.getElementById('castBox').style.height = detailsHeight;
    
    document.getElementById('descBoxContent').style.height = detailsHeight - (boxCornerSize * 2);
    document.getElementById('castBoxContent').style.height = detailsHeight - (boxCornerSize * 2);

    document.getElementById('detailsCnt').className = 'block';
    document.getElementById('info').className = 'block';

    if (intCover == 1)
    {
        intCoverImageWidth = intCoverFrontWidth
        intCoverImageHeight = intCoverFrontHeight
        
        intCoverChangerImageWidth = intCoverBackWidth
        intCoverChangerImageHeight = intCoverBackHeight
    }
    else
    {
        intCoverImageWidth = intCoverBackWidth
        intCoverImageHeight = intCoverBackHeight
        
        intCoverChangerImageWidth = intCoverFrontWidth
        intCoverChangerImageHeight = intCoverFrontHeight
    }
    
    coverBorder = 10 + 10;
    coverHeight = contentHeight - (boxCornerSize * 2);
    coverWidth = Math.round(coverHeight * (intCoverImageWidth / intCoverImageHeight));
    
    document.getElementById('coverImage').style.height = coverHeight;
    document.getElementById('coverImage').style.width = coverWidth;
    
    coverBoxHeight = coverHeight + (boxCornerSize * 2);
    coverBoxWidth = coverWidth + (boxCornerSize * 2);
    
    document.getElementById('cover').style.height = coverBoxHeight;
    document.getElementById('cover').style.width = coverBoxWidth;

    infoBorder = 10 + 10;
    infoWidth = document.getElementById('info').offsetWidth + infoBorder;

    detailsWidth = windowWidth - infoWidth - coverBoxWidth - coverBorder;
    
    if (detailsWidth > 0)
    {
        document.getElementById('details').style.width = detailsWidth;
    
        document.getElementById('descBox').style.width = detailsWidth;
        document.getElementById('castBox').style.width = detailsWidth;

        if (document.all)
        {
            document.getElementById('descBoxContent').style.width = detailsWidth;
            document.getElementById('castBoxContent').style.width = detailsWidth;
        }
        else
        {
            document.getElementById('descBoxContent').style.width = detailsWidth - 18;
            document.getElementById('castBoxContent').style.width = detailsWidth - 18;
        }

        document.getElementById('cover').className = 'block';
    }
    else
    {
        document.getElementById('cover').className = 'hidden';
    }
    
    coverChangerHeight = document.getElementById('coverChangerImage').offsetHeight + (boxCornerSize * 2);
    coverChangerWidth = document.getElementById('coverChangerImage').offsetWidth + (boxCornerSize * 2);

    document.getElementById('coverChangerBox').style.margin = (coverBoxHeight - coverChangerHeight) + 'px 0 0 ' + (coverBoxWidth - coverChangerWidth) +'px';
    
    document.getElementById('page').style.visibility = 'visible';
    document.getElementById('loading').style.visibility = 'hidden';
}

function toggleCover()
{
    intCover = intCover * -1;
    
	largeCover = document.getElementById('coverImage').src;
	smallCover = document.getElementById('coverChangerImage').src;
	
	document.getElementById('coverImage').src = smallCover;
	document.getElementById('coverChangerImage').src = largeCover;
	
	setWindowElementDims();
}





