// replace fonts (cufon)
Cufon.replace('a.mainmenuItemLink');
Cufon.replace('a.mainmenuItemActiveLink');
Cufon.replace('a.submenuItemLink', { hover: { color: '#58585a'} });
Cufon.replace('a.submenuItemActiveLink');
Cufon.replace('li.active a');
Cufon.replace('.hpContent h2');
Cufon.replace('#contentbar h1', {textShadow: '1px 1px rgba(0,0,0,0.25)'});
Cufon.replace('#content .blockLarge h4');

$(document).ready(function() {

	// load random visual
	loadRandomVisual();

	// fix homepage locations hover issue for IE6		
	if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == '6') {
		sfHover();		
	}
});

var myVisuals = new Array();

function loadRandomVisual() {
	var randomIndex = Math.floor(Math.random() * myVisuals.length);
	var imgSrc = myVisuals[randomIndex];

	if (!(jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == '6')) {
		$(function() {
			var img = new Image();
			$(img).load(function() {
				$('#visual').fadeOut(2000, function() {
					$('#visual').attr('style', 'background: url(' + imgSrc + ') no-repeat top left');
					$('#visual').fadeIn(2000);
				});
			}).attr('src', imgSrc);
		});

		setTimeout('loadRandomVisual()', 10000);
	}
}

sfHover = function() {
	if (document.getElementById('locations') != null) {
		var sfEls = document.getElementById('locations').getElementsByTagName('DIV');
		for (var i=0; i<sfEls.length; i++) {
			if (sfEls[i].className.indexOf('dot') > -1) {
				sfEls[i].onmouseover=function() {
					this.className+=' sfhover';
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(' sfhover\\b'), '');
				}
			}
		}
	}
}

function toggleDiv(id, flagit, startup)
{
    if (flagit == "1")
    {
        if (!startup)
        {
            hideAll();
        }
        if (document.layers)
        {
            if (document.layers[id])
            {
                document.layers[id].visibility = "show";
            }
        }
        else if (document.all)
        {
            if (document.all[id])
            {
                document.all[id].style.visibility = "visible";
            }
        }
        else if (document.getElementById)
        {
            if (document.getElementById(id))
            {
                document.getElementById(id).style.visibility = "visible";
            }
        }
    }
    else if (flagit == "0")
    {
        if (document.layers)
        {
            document.layers['' + id + ''].visibility = "hide";
        }
        else if (document.all)
        {
            document.all['' + id + ''].style.visibility = "hidden";
        }
        else if (document.getElementById)
        {
            document.getElementById('' + id + '').style.visibility = "hidden";
        }
    }
}

function hideAll()
{
    var elements = document.getElementsByTagName("div");
    var selectedElement = "";
    for (var i = 0; i < elements.length; i++)
    {
        var elementID = elements[i].getAttribute("id");

        if (elementID != null && elementID.indexOf("submenu") > -1)
        {
            toggleDiv(elementID, 0, false);
        }
    }

    if (sub != "")
    {
        toggleDiv(sub, 1, true);
        sub = "";
    }
}
