// misc.js
//
// Misc. javascript functions
//
// April, 2010, Chip Moore

// Get the width and height of the browser view port.
// Code acquired at
// http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/

function viewportWidth()
{
    var viewportwidth;

    // The more standards compliant browsers ( mozilla/netscape/opera/IE7 )
    // use window.innerWidth and window.innerHeight
    if ( typeof window.innerWidth != 'undefined' )
    {
        viewportwidth = window.innerWidth;
    }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the
    // first line in the document)
    else if ( ( typeof document.documentElement != 'undefined' )
            && ( typeof document.documentElement.clientWidth != 'undefined' )
            && ( document.documentElement.clientWidth != 0 ) )
    {
        viewportwidth = document.documentElement.clientWidth;
    }
    // older versions of IE
    else
    {
        viewportwidth = document.getElementsByTagName( 'body' )[0].clientWidth;
    }

    return viewportwidth;
}

function viewportHeight()
{
    var viewportheight;

    // The more standards compliant browsers ( mozilla/netscape/opera/IE7 )
    // use window.innerWidth and window.innerHeight
    if ( typeof window.innerHeight != 'undefined' )
    {
        viewportheight = window.innerHeight;
    }
    // IE6 in standards compliant mode (i.e. with a valid doctype as the
    // first line in the document)
    else if ( ( typeof document.documentElement != 'undefined' )
            && ( typeof document.documentElement.clientHeight != 'undefined' )
            && ( document.documentElement.clientHeight != 0 ) )
    {
        viewportheight = document.documentElement.clientHeight;
    }
    // older versions of IE
    else
    {
        viewportheight = document.getElementsByTagName( 'body' )[0].clientHeight;
    }

    return viewportheight;
}

// Get the value for some style property for some ellement
// From http://www.quirksmode.org/dom/getstyles.html
function getStyle( el, styleProp )
{
    var s;

    // The Explorer way: the currentStyle of the HTML element:
    if ( el.currentStyle )
    {
	s = el.currentStyle[styleProp];
    }
    // The Mozilla way: the getComputedStyle() method, which also works in Opera:
    else if ( window.getComputedStyle )
    {
	s = document.defaultView.getComputedStyle( el, null ).getPropertyValue( styleProp );
    }

    return s ;
}

// Let's stop for a while.
function pause( ms )
{
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while( curDate-date < ms );
}


