var fTimer      = 300;
var fLayer      = null;
var fItem       = null;
var fCount      = 0;
var fDontClose  = 0;
var fCloseTimer = null;

// Open Hidden Layer
function OpenLayer(i)
{
    var layer  = document.getElementById("smnu"+i);
    var item = document.getElementById("mnu"+i);
	
    if(layer)
    {
        StopClosing();
        layer.style.visibility='visible';
        item.style.textDecoration='underline';
        item.style.color='gold';

        if(fLayer && (fCount != i))
        {
            fLayer.style.visibility='hidden';
            fItem.style.textDecoration='';
            fItem.style.color='';
        }

        fLayer = layer;
        fItem = item;
        fCount = i;			
    }
    else if(fLayer)
    {
        fLayer.style.visibility='hidden';
        fItem.style.textDecoration='';
        fItem.style.color='';
        fCount = 0;
        fItem = null;
        fLayer = null;
	}
}

// Turn On Close Timer
function SetClose()
{
    fCloseTimer = window.setTimeout(CloseLayer, fTimer);
}

// Cancel Close Timer
function StopClosing()
{
    if(fCloseTimer)
    {
        window.clearTimeout(fCloseTimer);
        fCloseTimer = null;
    }
}

// Close Showed Layer
function CloseLayer()
{
    if(fLayer && fDontClose != 1)
    {
        fLayer.style.visibility='hidden';
        fItem.style.color='';
        fItem.style.textDecoration='';
        fCount = 0;
        fLayer = null;
        fItem = null;
    }
    else
    {
        fDontClose = 0;
    }

    fLayer = null;
    fItem = null;
}

// Close Layer Then Click-out
document.onclick = CloseLayer; 

// From http://homepage.ntlworld.com/bobosola/

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version <= 6.0) && (document.body.filters))
    {
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText 
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                img.outerHTML = strNewHTML
                i = i-1
            }
       }
   }    
}
window.attachEvent("onload", correctPNG);

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 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;
}

var resize = false;

function newsScale() {
    if(f_clientWidth()<950) {
        img = document.getElementById('imagebox');
        img.style.display = 'none';
        box = document.getElementById('newsbox');
        box.style.marginRight = 0;
    } else {
        box = document.getElementById('newsbox');
        box.style.marginRight = 275;
        img = document.getElementById('imagebox');
        img.style.display = '';
    }
}
