var prevWidth = 0;
var nav3width = 900;
var disable = false;

function resizeElements() {
	if (!disable && prevWidth != getWindowWidth()) {
                disable = true;

                var obj = document.getElementById("navlevel3");
	        if (obj != null) {
	            obj.style.width = (getWindowWidth() - 400) + 'px';
                }

	        var trans = document.getElementById('trans');
		var transhalf = document.getElementById('transhalf');
		
		if (trans)
			trans.style.height = pageHeight() + 'px';
		if (transhalf)
			transhalf.style.height = pageHeight() + 'px';
		prevWidth = getWindowWidth();
		disable = false;
	}
}
window.onresize = resizeElements;

function pageHeight() {
  windowHeight=document.body.clientHeight;

  return windowHeight;
}

function getWindowWidth() {
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
          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.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
           viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }

    return viewportwidth;
}

function getWindowHeight() {
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
          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.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
           viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
           viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }

    return viewportheight;
}

function hide(itemId) {
    var obj = document.getElementById(itemId);
    obj.style.visibility = 'hidden';

    obj = document.getElementById('card' + itemId);
    obj.style.visibility = 'visible';
}

function show(itemId) {
    var obj = document.getElementById(itemId);
    obj.style.visibility = 'visible';

    obj = document.getElementById('card' + itemId);
    obj.style.visibility = 'hidden';
}




function showInfoBox(url, elementId) {
    var height = f_scrollTop() + 25;
    if (height < 185)
        height = 185;
    var d = document.getElementById('trans');
    if (d != null)
        d.style.visibility = 'visible';
    var i = document.getElementById('contentbox');
    i.src = url;
    i.style.top = height + 'px';
    i.style.visibility = 'visible';
}

// This is used when clicking the semi-transparent layer
function unShowInfoBox() {
    var d = document.getElementById('contentbox');
    if (d != null)
        d.style.visibility = 'hidden';
        
    d = document.getElementById('trans');
    if (d != null)
        d.style.visibility = 'hidden';
        
    d = document.getElementById('transhalf');
    if (d != null)
        d.style.visibility = 'hidden';
}

function showInfoBoxHalf(url) {
    var height = f_scrollTop() + 25;
    if (height < 185)
        height = 185;
    var d = document.getElementById('transhalf');
    if (d != null)
        d.style.visibility = 'visible';
    var i = document.getElementById('contentbox');
    i.src = url;
    i.style.top = height + 'px';
    i.style.visibility = 'visible';
}

function hideInfoBox() {
    window.frameElement.style.visibility = 'hidden';
    var d = window.parent.document.getElementById('trans');
    if (d != null)
        d.style.visibility = 'hidden';
    d = window.parent.document.getElementById('transhalf');
    if (d != null)
        d.style.visibility = 'hidden';
}

function showInfoBoxNoDim(url) {
    var i = document.getElementById('contentbox');
    i.src = url;
    i.style.visibility = 'visible';
}

function hideInfoBoxNoDim() {
    var d = document.getElementById('contentbox');
    d.style.visibility = 'hidden';
}

function showImg(url, magnifyUrl) {
    var img = document.getElementById('largeimage');
    img.src = url;
    
    if (fb.anchors != null)
        fb.anchors.length = 0;

    var link = document.getElementById('magnifier');
    if (magnifyUrl == '') {
        link.removeAttribute("href");
    } else {
        link.href = magnifyUrl;
        fb.tagAnchors(link);
    }
}

function findPos(elementId) {
    obj = document.getElementById(elementId)
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return curtop;
}

function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function switchImages(hide, show) {
    var s;
	document.getElementById(hide).style.display = 'none';
	
	s = document.getElementById(show).style;
	if (s.visibility != 'hidden') {
	    s.display = 'block';
	}
}

function turnCardBack(img, imgC, div) {
    var s;
    
    s = document.getElementById(img).style;
	s.visibility = 'hidden'; s.display = 'none';
	
	if (imgC != '') {
	    s = document.getElementById(imgC).style;
	    s.visibility = 'hidden'; s.display = 'none';
	}
	
	s = document.getElementById(div).style;
	s.visibility = 'visible'; s.display = 'block';

    doHiddenReplaceNow();
}

function turnCardFront(img, imgC, div) {
	var s;
    
    if (imgC != '') {
        s = document.getElementById(img).style;
	    s.visibility = 'visible'; s.display = 'none';
    	
	    s = document.getElementById(imgC).style;
	    s.visibility = 'visible'; s.display = 'block';
	} else {
	    s = document.getElementById(img).style;
	    s.visibility = 'visible'; s.display = 'block';
	}
	
	s = document.getElementById(div).style;
	s.visibility = 'hidden'; s.display = 'none';
}
